[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/layouts/vlayout/modules/Settings/CustomerPortal/resources/ -> CustomerPortal.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  jQuery.Class('Settings_Customer_Portal_Js', {}, {
  10      
  11      //This will store the CustomerPortal Form
  12      customerPortalForm : false,
  13      
  14      //store the class name for customer portal module row
  15      rowClass : 'portalModuleRow',
  16      
  17      /**
  18       * Function to get the customerPortal form
  19       */
  20      getForm : function() {
  21          if(this.customerPortalForm == false) {
  22              this.customerPortalForm = jQuery('#customerPortalForm');
  23          }
  24          return this.customerPortalForm;
  25      },
  26      
  27      /**
  28       * Function to regiser the event to make the portal modules list sortable
  29       */
  30      makeModulesListSortable : function() {
  31          var thisInstance = this;
  32          var modulesTable = jQuery('#portalModulesTable');
  33          modulesTable.sortable({
  34              'containment' : modulesTable,
  35              'items' : 'tr.'+this.rowClass,
  36              'revert' : true,
  37              'tolerance':'pointer',
  38              'dealy' : '3000',
  39              'helper' : function(e,ui){
  40                  //while dragging helper elements td element will take width as contents width
  41                  //so we are explicity saying that it has to be same width so that element will not
  42                  //look like distrubed
  43                  ui.children().each(function(index,element){
  44                      element = jQuery(element);
  45                      element.width(element.width());
  46                  })
  47                  return ui;
  48              },
  49              'update' : function(e, ui) {
  50                  thisInstance.showSaveButton();
  51              }
  52          });
  53      },
  54      
  55      /**
  56       * Function which will enable the save button in customer portal form
  57       */
  58      showSaveButton : function() {
  59          var form = this.getForm();
  60          var saveButton = form.find('[name="savePortalInfo"]');
  61          if(saveButton.attr('disabled') ==  'disabled') {
  62              saveButton.removeAttr('disabled');
  63          }
  64      },
  65      
  66      /**
  67       * Function which will disable the save button in customer portal form
  68       */
  69      disableSaveButton : function(form) {
  70          var saveButton = form.find('[name="savePortalInfo"]');
  71          saveButton.attr('disabled', 'disabled');
  72      },
  73      
  74      /**
  75       * Function which will update sequence numbers of portal modules list by order
  76       */
  77      updatePortalModulesListByOrder : function() {
  78          var form = this.getForm();
  79          jQuery('tr.'+this.rowClass ,form).each(function(index,domElement){
  80              var portalModuleRow = jQuery(domElement);
  81              var tabId = portalModuleRow.data('id');
  82              var sequenceEle = portalModuleRow.find('[name="portalModulesInfo['+tabId+'][sequence]"]');
  83              var expectedRowSequence = (index+1);
  84              var actualRowSequence = sequenceEle.val();
  85              if(expectedRowSequence != actualRowSequence) {
  86                  return sequenceEle.val(expectedRowSequence);
  87              }
  88          });
  89      },
  90      
  91      /*
  92       * function to save the customer portal settings
  93       * @params: form - customer portal form.
  94       */
  95      saveCustomerPortal : function(form) {
  96          var aDeferred = jQuery.Deferred();
  97          
  98          var progressIndicatorElement = jQuery.progressIndicator({
  99              'position' : 'html',
 100              'blockInfo' : {
 101                  'enabled' : true
 102              }
 103          });
 104          
 105          var data = form.serializeFormData();
 106          data['module'] = app.getModuleName();
 107          data['parent'] = app.getParentModuleName();
 108          data['action'] = 'Save';
 109          
 110          AppConnector.request(data).then(
 111              function(data) {
 112                  progressIndicatorElement.progressIndicator({'mode' : 'hide'});
 113                  aDeferred.resolve(data);
 114              },
 115              function(error) {
 116                  progressIndicatorElement.progressIndicator({'mode' : 'hide'});
 117                  //TODO : Handle error
 118                  aDeferred.reject(error);
 119              }
 120          );
 121          return aDeferred.promise();
 122      },
 123      
 124      registerEvents : function(e){
 125          var thisInstance = this;
 126          var form = thisInstance.getForm();
 127          
 128          //register all select2 Elements
 129          app.showSelect2ElementView(form.find('select.select2'), {maximumSelectionSize: 7, dropdownCss : {'z-index' : 0}});
 130          
 131          //To make customer portal modules list sortable
 132          thisInstance.makeModulesListSortable();
 133          
 134          //If any change happened, then enable the save button
 135          form.find('select.select2').on('change', function() {
 136              thisInstance.showSaveButton();
 137          });
 138          form.find('input:checkbox, input:radio').on('change', function() {
 139              thisInstance.showSaveButton();
 140          })
 141          
 142          form.submit(function(e) {
 143              e.preventDefault();
 144              thisInstance.disableSaveButton(form);
 145              
 146              //update the sequence of customer portal modules
 147              thisInstance.updatePortalModulesListByOrder();
 148              
 149              //save the customer portal settings
 150              thisInstance.saveCustomerPortal(form).then(
 151                  function(data) {
 152                      var result = data['result'];
 153                      if(result['success']) {
 154                          var params = {
 155                              text: app.vtranslate('JS_PORTAL_INFO_SAVED')
 156                          }
 157                          Settings_Vtiger_Index_Js.showMessage(params);
 158                      }
 159                  },
 160                  function(error){
 161                      //TODO: Handle Error
 162                  }
 163              );
 164          });
 165          
 166      }
 167  });
 168  
 169  jQuery(document).ready(function(){
 170      var instance = new Settings_Customer_Portal_Js();
 171      instance.registerEvents();
 172  })


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