[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/layouts/vlayout/modules/Users/resources/ -> Edit.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  Vtiger_Edit_Js("Users_Edit_Js",{},{
  11      
  12      duplicateCheckCache : {},
  13      
  14      //Hold the conditions for a hour format
  15      hourFormatConditionMapping : false,
  16      
  17      
  18      registerWidthChangeEvent : function() {
  19          var widthType = app.cacheGet('widthType', 'narrowWidthType');
  20          jQuery('#currentWidthType').html(jQuery('li[data-class="'+widthType+'"]').html());
  21          jQuery('#widthType').on('click', 'li', function(e){
  22              var value = jQuery(e.currentTarget).data('class');
  23              app.cacheSet('widthType', value);
  24              jQuery('#currentWidthType').html(jQuery(e.currentTarget).html());
  25              window.location.reload();
  26          });
  27      },
  28      
  29      registerHourFormatChangeEvent : function() {
  30          
  31      },
  32      
  33      changeStartHourValuesEvent : function(form){
  34          var thisInstance = this;
  35          form.on('change','select[name="hour_format"]',function(e){
  36              var hourFormatVal = jQuery(e.currentTarget).val();
  37              var startHourElement = jQuery('select[name="start_hour"]',form);
  38              var conditionSelected = startHourElement.val();
  39              var list = thisInstance.hourFormatConditionMapping['hour_format'][hourFormatVal]['start_hour'];
  40              var options = '';
  41              for(var key in list) {
  42                  //IE Browser consider the prototype properties also, it should consider has own properties only.
  43                  if(list.hasOwnProperty(key)) {
  44                      var conditionValue = list[key];
  45                      options += '<option value="'+key+'"';
  46                      if(key == conditionSelected){
  47                          options += ' selected="selected" ';
  48                      }
  49                      options += '>'+conditionValue+'</option>';
  50                  }
  51              }
  52              startHourElement.html(options).trigger("liszt:updated");
  53          });
  54          
  55          
  56      },
  57      
  58      triggerHourFormatChangeEvent : function(form) {
  59          this.hourFormatConditionMapping = jQuery('input[name="timeFormatOptions"]',form).data('value');
  60          this.changeStartHourValuesEvent(form);
  61          jQuery('select[name="hour_format"]',form).trigger('change');
  62      },
  63      
  64      /**
  65       * Function to register recordpresave event
  66       */
  67      registerRecordPreSaveEvent : function(form){
  68          var thisInstance = this;
  69          form.on(Vtiger_Edit_Js.recordPreSave, function(e, data) {
  70              var userName = jQuery('input[name="user_name"]').val();
  71              var newPassword = jQuery('input[name="user_password"]').val();
  72              var confirmPassword = jQuery('input[name="confirm_password"]').val();
  73              var record = jQuery('input[name="record"]').val();
  74              if(record == ''){
  75                  if(newPassword != confirmPassword){
  76                      Vtiger_Helper_Js.showPnotify(app.vtranslate('JS_REENTER_PASSWORDS'));
  77                      e.preventDefault();
  78                  }
  79  
  80                  if(!(userName in thisInstance.duplicateCheckCache)) {
  81                      thisInstance.checkDuplicateUser(userName).then(
  82                          function(data){
  83                              if(data.result) {
  84                                  thisInstance.duplicateCheckCache[userName] = data.result;
  85                                  Vtiger_Helper_Js.showPnotify(app.vtranslate('JS_USER_EXISTS'));
  86                              }
  87                          }, 
  88                          function (data, error){
  89                              thisInstance.duplicateCheckCache[userName] = data.result;
  90                              form.submit();
  91                          }
  92                      );
  93                  } else {
  94                      if(thisInstance.duplicateCheckCache[userName] == true){
  95                          Vtiger_Helper_Js.showPnotify(app.vtranslate('JS_USER_EXISTS'));
  96                      } else {
  97                          delete thisInstance.duplicateCheckCache[userName];
  98                          return true;
  99                      }
 100                  }
 101                  e.preventDefault();
 102              }
 103          })
 104      },
 105      
 106      checkDuplicateUser: function(userName){
 107          var aDeferred = jQuery.Deferred();
 108          var params = {
 109                  'module': app.getModuleName(),
 110                  'action' : "SaveAjax",
 111                  'mode' : 'userExists',
 112                  'user_name' : userName
 113              }
 114              AppConnector.request(params).then(
 115                  function(data) {
 116                      if(data.result){
 117                          aDeferred.resolve(data);
 118                      }else{
 119                          aDeferred.reject(data);
 120                      }
 121                  }
 122              );
 123          return aDeferred.promise();
 124      },
 125      
 126      registerEvents : function() {
 127          this._super();
 128          var form = this.getForm();
 129          this.registerWidthChangeEvent();
 130          this.triggerHourFormatChangeEvent(form);
 131          this.registerRecordPreSaveEvent(form);
 132      }
 133  });


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