[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/layouts/vlayout/modules/Settings/Vtiger/resources/ -> ConfigEditor.js (source)

   1  /*+***********************************************************************************
   2   * The contents of this file are subject to the vtiger CRM Public License Version 1.0
   3   * ("License"); You may not use this file except in compliance with the License
   4   * The Original Code is:  vtiger CRM Open Source
   5   * The Initial Developer of the Original Code is vtiger.
   6   * Portions created by vtiger are Copyright (C) vtiger.
   7   * All Rights Reserved.
   8   *************************************************************************************/
   9  
  10  jQuery.Class("Settings_Vtiger_ConfigEditor_Js",{},{
  11      
  12      /*
  13       * Function to save the Configuration Editor content
  14       */
  15      saveConfigEditor : function(form) {
  16          var aDeferred = jQuery.Deferred();
  17          
  18          var data = form.serializeFormData();
  19          var updatedFields = {};
  20          jQuery.each(data, function(key, value) {
  21              updatedFields[key] = value;
  22          })
  23          
  24          var params = {
  25              'module' : app.getModuleName(),
  26              'parent' : app.getParentModuleName(),
  27              'action' : 'ConfigEditorSaveAjax',
  28              'updatedFields' : JSON.stringify(updatedFields)
  29          }
  30          AppConnector.request(params).then(
  31              function(data) {
  32                  aDeferred.resolve(data);
  33              },
  34              function(error,err){
  35                  aDeferred.reject();
  36              }
  37          );
  38          return aDeferred.promise();
  39      },
  40      
  41      /*
  42       * Function to load the contents from the url through pjax
  43       */
  44      loadContents : function(url) {
  45          var aDeferred = jQuery.Deferred();
  46          AppConnector.requestPjax(url).then(
  47              function(data){
  48                  aDeferred.resolve(data);
  49              },
  50              function(error, err){
  51                  aDeferred.reject();
  52              }
  53          );
  54          return aDeferred.promise();
  55      },
  56      
  57      /*
  58       * function to register the events in editView
  59       */
  60      registerEditViewEvents : function() {
  61          var thisInstance = this;
  62          var form = jQuery('#ConfigEditorForm');
  63          var detailUrl = form.data('detailUrl');
  64          
  65          //register all select2 Elements
  66          app.showSelect2ElementView(form.find('select.select2'), {dropdownCss : {'z-index' : 0}});
  67          
  68          //register validation engine
  69          var params = app.validationEngineOptions;
  70          params.onValidationComplete = function(form, valid){
  71              if(valid) {
  72                  var progressIndicatorElement = jQuery.progressIndicator({
  73                      'position' : 'html',
  74                      'blockInfo' : {
  75                          'enabled' : true
  76                      }
  77                  });
  78                  thisInstance.saveConfigEditor(form).then(
  79                      function(data) {
  80                          var params = {};
  81                          if(data['success']) {
  82                              params['text'] = app.vtranslate('JS_CONFIGURATION_DETAILS_SAVED');
  83                              thisInstance.loadContents(detailUrl).then(
  84                                  function(data) {
  85                                      progressIndicatorElement.progressIndicator({'mode':'hide'});
  86                                      jQuery('.contentsDiv').html(data);
  87                                      thisInstance.registerDetailViewEvents();
  88                                  }
  89                              );
  90                          } else {
  91                              progressIndicatorElement.progressIndicator({'mode':'hide'});
  92                              params['text'] = data['error']['message'];
  93                              params['type'] = 'error';
  94                          }
  95                          Settings_Vtiger_Index_Js.showMessage(params);
  96                      },function(error, err) {
  97                          progressIndicatorElement.progressIndicator({'mode':'hide'});
  98                      }
  99                  );
 100                  return valid;
 101              }
 102          }
 103          form.validationEngine(params);
 104          
 105          form.submit(function(e) {
 106              e.preventDefault();
 107          })
 108          
 109          //Register click event for cancel link
 110          var cancelLink = form.find('.cancelLink');
 111          cancelLink.click(function() {
 112              var progressIndicatorElement = jQuery.progressIndicator({
 113                  'position' : 'html',
 114                  'blockInfo' : {
 115                      'enabled' : true
 116                  }
 117              });
 118              thisInstance.loadContents(detailUrl).then(
 119                  function(data) {
 120                      progressIndicatorElement.progressIndicator({'mode':'hide'})
 121                      jQuery('.contentsDiv').html(data);
 122                      thisInstance.registerDetailViewEvents();
 123                  }
 124              );
 125          })
 126      },
 127      
 128      /*
 129       * function to register the events in DetailView
 130       */
 131      registerDetailViewEvents : function() {
 132          var thisInstance = this;
 133          var container = jQuery('#ConfigEditorDetails');
 134          var editButton = container.find('.editButton');
 135          
 136          //Register click event for edit button
 137          editButton.click(function() {
 138              var url = editButton.data('url');
 139              var progressIndicatorElement = jQuery.progressIndicator({
 140                  'position' : 'html',
 141                  'blockInfo' : {
 142                      'enabled' : true
 143                  }
 144              });
 145              thisInstance.loadContents(url).then(
 146                  function(data) {
 147                      progressIndicatorElement.progressIndicator({'mode':'hide'});
 148                      jQuery('.contentsDiv').html(data);
 149                      thisInstance.registerEditViewEvents();
 150                  }, function(error, err) {
 151                      progressIndicatorElement.progressIndicator({'mode':'hide'});
 152                  }
 153              );
 154          });
 155      },
 156      
 157      registerEvents: function() {
 158          if(jQuery('#ConfigEditorDetails').length > 0) {
 159              this.registerDetailViewEvents();
 160          } else {
 161              this.registerEditViewEvents();
 162          }
 163      }
 164  
 165  });
 166  
 167  jQuery(document).ready(function(e){
 168      var tacInstance = new Settings_Vtiger_ConfigEditor_Js();
 169      tacInstance.registerEvents();
 170  })
 171  
 172  Vtiger_WholeNumberGreaterThanZero_Validator_Js("Vtiger_NumberRange5_Validator_Js",{
 173      
 174      /**
 175       *Function which invokes field validation
 176       *@param accepts field element as parameter
 177       * @return error if validation fails true on success
 178       */
 179      invokeValidation: function(field, rules, i, options){
 180          var rangeInstance = new Vtiger_NumberRange5_Validator_Js();
 181          rangeInstance.setElement(field);
 182          var response = rangeInstance.validate();
 183          if(response != true){
 184              return rangeInstance.getError();
 185          }
 186      }
 187      
 188  },{
 189      /**
 190       * Function to validate the percentage field data
 191       * @return true if validation is successfull
 192       * @return false if validation error occurs
 193       */
 194      validate: function(){
 195          var response = this._super();
 196          if(response != true){
 197              return response;
 198          }else{
 199              var fieldValue = this.getFieldValue();
 200              if (fieldValue < 1 || fieldValue > 5) {
 201                  var errorInfo = app.vtranslate('JS_PLEASE_ENTER_NUMBER_IN_RANGE_1TO5');
 202                  this.setError(errorInfo);
 203                  return false;
 204              }
 205              return true;
 206          }
 207      }
 208  });
 209  
 210  Vtiger_WholeNumberGreaterThanZero_Validator_Js("Vtiger_NumberRange100_Validator_Js",{
 211  
 212      /**
 213       *Function which invokes field validation
 214       *@param accepts field element as parameter
 215       * @return error if validation fails true on success
 216       */
 217      invokeValidation: function(field, rules, i, options){
 218          var rangeInstance = new Vtiger_NumberRange100_Validator_Js();
 219          rangeInstance.setElement(field);
 220          var response = rangeInstance.validate();
 221          if(response != true){
 222              return rangeInstance.getError();
 223          }
 224      }
 225      
 226  },{
 227      /**
 228       * Function to validate the percentage field data
 229       * @return true if validation is successfull
 230       * @return false if validation error occurs
 231       */
 232      validate: function(){
 233          var response = this._super();
 234          if(response != true){
 235              return response;
 236          }else{
 237              var fieldValue = this.getFieldValue();
 238              if (fieldValue < 1 || fieldValue > 100) {
 239                  var errorInfo = app.vtranslate('JS_PLEASE_ENTER_NUMBER_IN_RANGE_1TO100');
 240                  this.setError(errorInfo);
 241                  return false;
 242              }
 243              return true;
 244          }
 245      }
 246  
 247  })


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1