/**
  * Method getAjaxEventFunctionRender
  * @access protected
  * @return string
  * @since 1.0.35
  */
 protected function getAjaxEventFunctionRender()
 {
     $html = "";
     $loading_obj = null;
     if (get_class($this) == "UploadFile") {
         $loading_obj = $this->getProgressBarObject();
         if ($this->isSizeLimitJsCheckActivated() && $this->getFileSizeLimit() != -1) {
             $size_alert = new DialogBox(__(ERROR), __(UPLOAD_FILESIZE_LIMIT_ERROR_MSG, $this->getFileSizeLimitStr()));
             $size_alert->activateCloseButton()->setWidth(500);
             $size_alert->setDialogBoxLevel(rand(90000, 99999));
             $html .= "var displaySizeErrorDialogBox" . get_class($this) . "_" . $this->getEventObjectName() . " = function(filename) {\n";
             $html .= $size_alert->render();
             $html .= "};\n";
         } else {
             $html .= "var displaySizeErrorDialogBox" . get_class($this) . "_" . $this->getEventObjectName() . " = null;\n";
         }
         if ($this->isMimeTypeJsCheckActivated() && sizeof($this->getAuthorizedMimeTypes()) > 0) {
             $mime_alert = new DialogBox(__(ERROR), __(UPLOAD_MIME_TYPES_ERROR_MSG, implode(", ", $this->getAuthorizedMimeTypes())));
             $mime_alert->activateCloseButton()->setWidth(500);
             $mime_alert->setDialogBoxLevel(rand(90000, 99999));
             $html .= "var displayMimeErrorDialogBox" . get_class($this) . "_" . $this->getEventObjectName() . " = function(filename, mime_type) {\n";
             $html .= $mime_alert->render();
             $html .= "};\n";
         } else {
             $html .= "var displayMimeErrorDialogBox" . get_class($this) . "_" . $this->getEventObjectName() . " = null;\n";
         }
     }
     if (gettype($this->ajax_wait_message) != "object") {
         $loading_img = new Picture("wsp/img/loading.gif", 32, 32);
         $loading_img->setId("wspAjaxEventLoadingPic" . get_class($this) . "_" . $this->getEventObjectName());
         $loading_modalbox = new DialogBox(__(LOADING), new Object($this->ajax_wait_message, "<br/>", $loading_img, $loading_obj));
         $loading_modalbox->setDialogBoxLevel(rand(90000, 99999))->modal();
     }
     $error_alert = new DialogBox(__(ERROR), __(SUBMIT_ERROR));
     $error_alert->activateCloseButton()->setWidth(500);
     $error_alert->setDialogBoxLevel(rand(90000, 99999));
     $error_unknow_alert = new DialogBox(__(ERROR), __(SUBMIT_UNKNOW_ERROR));
     $error_unknow_alert->activateCloseButton()->setWidth(400);
     $error_unknow_alert->setDialogBoxLevel(rand(90000, 99999));
     $html .= "\tvar isRequestedAjaxEvent" . get_class($this) . "_" . $this->getEventObjectName() . " = false;\n";
     $html .= "\tvar lastAjaxRequest" . get_class($this) . "_" . $this->getEventObjectName() . " = Array();\n";
     $html .= "\tvar nbAjaxRequest" . get_class($this) . "_" . $this->getEventObjectName() . " = 0;\n";
     if ($this->is_ajax_event) {
         $html .= "\tvar encryptedObjectValueArray" . get_class($this) . "_" . $this->getEventObjectName() . " = Array();\n";
     }
     $html .= "\tcallAjax" . get_class($this) . "_" . $this->getEventObjectName() . "_event = function(callback_value, abort_last_request) {\n";
     $html .= "\t\tif (isRequestedAjaxEvent" . get_class($this) . "_" . $this->getEventObjectName() . " && !abort_last_request) { return; }\n";
     $html .= "\t\tisRequestedAjaxEvent" . get_class($this) . "_" . $this->getEventObjectName() . " = true;\n";
     $html .= "\t\tnbAjaxRequest" . get_class($this) . "_" . $this->getEventObjectName() . "++;\n";
     if (!$this->disable_ajax_wait_message) {
         if (gettype($this->ajax_wait_message) == "object") {
             $html .= "\t\t\$('#" . $this->ajax_wait_message->getId() . "').css('display', 'block');\n";
         } else {
             $html .= "\t\t" . $loading_modalbox->render() . "\n";
         }
         $html .= "\t\tsetTimeout(\"requestAjaxEvent" . get_class($this) . "_" . $this->getEventObjectName() . "(\\\"\" + callback_value + \"\\\", \" + abort_last_request + \");\", " . (gettype($this->ajax_wait_message) == "object" ? "1" : "1000") . ");\n";
     } else {
         $html .= "\t\tsetTimeout(\"requestAjaxEvent" . get_class($this) . "_" . $this->getEventObjectName() . "(\\\"\" + callback_value + \"\\\", \" + abort_last_request + \");\", (abort_last_request?(lastAjaxRequest" . get_class($this) . "_" . $this->getEventObjectName() . ".length==0?1:200):1));\n";
     }
     $html .= "\t};\n";
     $html .= "\trequestAjaxEvent" . get_class($this) . "_" . $this->getEventObjectName() . " = function(callback_value, abort_last_request) {\n";
     $html .= "\t\tnbAjaxRequest" . get_class($this) . "_" . $this->getEventObjectName() . "--;\n";
     $html .= "\t\tif (abort_last_request) { for (var i=0; i < lastAjaxRequest" . get_class($this) . "_" . $this->getEventObjectName() . ".length; i++) { if (lastAjaxRequest" . get_class($this) . "_" . $this->getEventObjectName() . "[i]!=null) { lastAjaxRequest" . get_class($this) . "_" . $this->getEventObjectName() . "[i].abort(); lastAjaxRequest" . get_class($this) . "_" . $this->getEventObjectName() . "[i]=null; } } if (nbAjaxRequest" . get_class($this) . "_" . $this->getEventObjectName() . " > 0) { return; } }\n";
     // encrypt formular if encrypt is active
     if ($this->form_object != null) {
         $html .= "\t\t" . $this->encryptObjectData($this->form_object, "isRequestedAjaxEvent" . get_class($this) . "_" . $this->getEventObjectName() . " = false;" . ($loading_modalbox == null ? "" : $loading_modalbox->close()->render()));
     }
     if (get_class($this) == "UploadFile") {
         $html .= "var upload_status = \$('#" . $this->getId() . "').upload('";
     } else {
         $html .= "\t\tlastAjaxRequest" . get_class($this) . "_" . $this->getEventObjectName() . "[lastAjaxRequest" . get_class($this) . "_" . $this->getEventObjectName() . ".length] = \$.ajax({ type: '";
         if ($this->form_object != null) {
             $html .= $this->form_object->getMethod();
         } else {
             $html .= "POST";
         }
         $html .= "', url: '";
     }
     $html .= BASE_URL . LANGUAGE_URL . "/ajax/";
     if ($this->form_object == null) {
         $html .= $this->getPage()->getPage() . ".html";
         if (PARAMS_URL != "") {
             $pos = find(PARAMS_URL, "?", 0, $pos);
             if ($pos > 0) {
                 $pos2 = strlen(PARAMS_URL);
                 $html .= "?" . substr(PARAMS_URL, $pos, $pos2 - $pos);
             }
         }
     } else {
         if ($this->form_object->getAction() == "") {
             $html .= $this->form_object->getPageObject()->getPage() . ".html";
             if (PARAMS_URL != "") {
                 $pos = find(PARAMS_URL, "?", 0, $pos);
                 if ($pos > 0) {
                     $pos2 = strlen(PARAMS_URL);
                     $html .= "?" . substr(PARAMS_URL, $pos, $pos2 - $pos);
                 }
             }
         } else {
             $html .= $this->form_object->getAction();
         }
     }
     $html .= "',\n";
     if (get_class($this) == "UploadFile") {
         $html .= "\t\t\t\$('#Callback_" . $this->getEventObjectName() . "').serialize(),\n";
     } else {
         if ($this->form_object != null) {
             $html .= "\t\t\tdata: ";
             if ($this->form_object->isEncrypted()) {
                 $html .= "encrypt_data";
             } else {
                 $html .= "\$('#" . $this->form_object->getId() . "').serialize() + '&Callback_" . $this->getEventObjectName() . "=' + callback_value";
             }
             $html .= ",\n";
         } else {
             $html .= "\t\t\tdata: 'Callback_" . $this->getEventObjectName() . "=' + callback_value,\n";
         }
         $html .= "\t\t\tdataType: 'json',\n";
         $html .= "\t\t\tsuccess: ";
     }
     $html .= "function(ajax_event_response) {\n";
     $html .= "\t\t\t\tisRequestedAjaxEvent" . get_class($this) . "_" . $this->getEventObjectName() . " = false;\n";
     $html .= "\t\t\t\tif (ajax_event_response != \"\") {\n";
     $html .= "\t\t\t\t\tvar dialogbox_is_change = false;\n";
     if (isLocalDebug()) {
         $html .= "\t\t\t\t\tvar alert_local_eval_error = true;\n";
     }
     $html .= "\t\t\t\t\tfor (var ajax_event_ind=0; ajax_event_ind < ajax_event_response.length; ajax_event_ind++) {\n";
     if (!$this->disable_ajax_wait_message) {
         $html .= "\t\t\t\t\t\tif (ajax_event_response[ajax_event_ind] != null && ajax_event_response[ajax_event_ind].indexOf('wspDialogBox" . $modalbox_indice . "' + ' = ') != -1) {\n";
         $html .= "\t\t\t\t\t\t\tdialogbox_is_change = true;\n";
         $html .= "\t\t\t\t\t\t}\n";
     }
     if (get_class($this) == "UploadFile") {
         $html .= "\t\t\t\t\t\tajax_event_response[ajax_event_ind] = myReplaceAll(myReplaceAll(ajax_event_response[ajax_event_ind], '{#wsp_lt}', '<'), '{#wsp_gt}', '>');\n";
     }
     $html .= "\t\t\t\t\t\ttry {\n";
     $html .= "\t\t\t\t\t\t\teval(ajax_event_response[ajax_event_ind]);\n";
     $html .= "\t\t\t\t\t\t} catch (e) {\n";
     $html .= "\t\t\t\t\t\t\tconsole.log('Js error: ' + e.message + '\\nCode: ' + ajax_event_response[ajax_event_ind]);\n";
     // display ajax render error message when it's local or debug execution (useful to debug)
     if (isLocalDebug()) {
         $html .= "\t\t\t\t\t\t\tif (alert_local_eval_error) {\n";
         $html .= "\t\t\t\t\t\t\t\talert('An error appeared during Ajax event, please check the console of your browser to see the error(s).');";
         $html .= "\t\t\t\t\t\t\t\talert_local_eval_error = false;\n";
         $html .= "\t\t\t\t\t\t\t}\n";
     }
     $html .= "\t\t\t\t\t\t}\n";
     $html .= "\t\t\t\t\t}\n";
     if (!$this->disable_ajax_wait_message) {
         if (gettype($this->ajax_wait_message) == "object") {
             $html .= "\t\t\t\t\t\$('#" . $this->ajax_wait_message->getId() . "').css('display', 'none');\n";
         } else {
             $html .= "\t\t\t\t\tif (!dialogbox_is_change) {\n";
             $html .= "\t\t\t\t\t\t" . $loading_modalbox->close()->render();
             $html .= "\t\t\t\t\t}\n";
         }
     }
     $html .= "\t\t\t\t} else {\n";
     if (gettype($this->ajax_wait_message) == "object") {
         $html .= "\t\t\t\t\t\$('#" . $this->ajax_wait_message->getId() . "').css('display', 'none');\n";
     } else {
         $html .= "\t\t\t\t\t" . $loading_modalbox->close()->render();
     }
     $html .= "\t\t\t\t\t" . $error_unknow_alert->render() . "\n";
     $html .= "\t\t\t\t}\n";
     $html .= "\t\t\t\t\$('#Callback_" . $this->getEventObjectName() . "').val('');\n";
     if ($this->is_ajax_event) {
         $html .= "\t\t\t\trestoreEncryptedObject" . get_class($this) . "_" . $this->getEventObjectName() . "();\n";
     }
     $html .= "\t\t\t},\n";
     if (get_class($this) == "UploadFile") {
         $html .= "\t\t\t'json', \$('#wsp_object_wspAjaxEventLoadingObj" . get_class($this) . "_" . $this->getEventObjectName() . "'), \$('#wspAjaxEventLoadingPic" . get_class($this) . "_" . $this->getEventObjectName() . "'), displaySizeErrorDialogBox" . get_class($this) . "_" . $this->getEventObjectName() . ", '" . $this->getFileSizeLimit() . "', displayMimeErrorDialogBox" . get_class($this) . "_" . $this->getEventObjectName() . ", '" . implode(", ", $this->getAuthorizedMimeTypes()) . "');\n";
         $html .= "\t\t\tisRequestedAjaxEvent" . get_class($this) . "_" . $this->getEventObjectName() . " = false;\n";
         $html .= "\t\t\tif (upload_status === false) {\n";
         if (gettype($this->ajax_wait_message) == "object") {
             $html .= "\t\t\t\t\t\$('#" . $this->ajax_wait_message->getId() . "').css('display', 'none');\n";
         } else {
             $html .= "\t\t\t\t\t" . $loading_modalbox->close()->render() . "\n";
         }
         $html .= "\t\t\t}\n";
     } else {
         $html .= "\t\t\terror: function(transport) {\n";
         $html .= "\t\t\t\tisRequestedAjaxEvent" . get_class($this) . "_" . $this->getEventObjectName() . " = false;\n";
         $html .= "\t\t\t\tif (!abort_last_request || (abort_last_request && trim(transport.statusText) != 'abort')) {\n";
         if (gettype($this->ajax_wait_message) == "object") {
             $html .= "\t\t\t\t\t\$('#" . $this->ajax_wait_message->getId() . "').css('display', 'none');\n";
         } else {
             $html .= "\t\t\t\t\t" . $loading_modalbox->close()->render() . "\n";
         }
         $html .= "\t\t\t\t\tif (trim(transport.responseText) == '') {\n";
         $html .= "\t\t\t\t\t\t" . $error_unknow_alert->render();
         $html .= "\t\t\t\t\t} else {\n";
         $html .= "\t\t\t\t\t\t" . $error_alert->render();
         $html .= "\t\t\t\t\t}\n";
         $html .= "\t\t\t\t}\n";
         $html .= "\t\t\t\t\$('#Callback_" . $this->getEventObjectName() . "').val('');\n";
         if ($this->is_ajax_event) {
             $html .= "\t\t\t\trestoreEncryptedObject" . get_class($this) . "_" . $this->getEventObjectName() . "();\n";
         }
         $html .= "\t\t\t}\n";
     }
     if (get_class($this) != "UploadFile") {
         $html .= "\t\t});\n";
     }
     $html .= "\t};\n";
     if ($this->is_ajax_event) {
         $html .= "\trestoreEncryptedObject" . get_class($this) . "_" . $this->getEventObjectName() . " = function() {\n";
         $html .= "\t\tfor (var i=0; i < encryptedObjectValueArray" . get_class($this) . "_" . $this->getEventObjectName() . ".length; i++) {\n";
         $html .= "\t\t\t\$('#' + encryptedObjectValueArray" . get_class($this) . "_" . $this->getEventObjectName() . "[i][0]).val(encryptedObjectValueArray" . get_class($this) . "_" . $this->getEventObjectName() . "[i][1]);\n";
         $html .= "\t\t}\n";
         $html .= "\t};\n";
     }
     return $html;
 }
Exemplo n.º 2
0
 /**
  * Method getArrayDialogBoxLevels
  * @access static
  * @return array
  * @since 1.0.35
  */
 public static function getArrayDialogBoxLevels()
 {
     if (isset($_GET['dialogbox_level'])) {
         $page_is_init_var = $GLOBALS['__PAGE_IS_INIT__'];
         $GLOBALS['__PAGE_IS_INIT__'] = false;
         // create object for intern DialogBox management
         $i = 1;
         while ($i <= $_GET['dialogbox_level']) {
             if (self::$array_dialog_indices[$i] == null) {
                 $dialog = new DialogBox('', '');
                 $dialog->setDialogBoxLevel($i);
             }
             $i++;
         }
         $GLOBALS['__PAGE_IS_INIT__'] = $page_is_init_var;
     }
     return self::$array_dialog_indices;
 }