[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/layouts/vlayout/modules/Settings/Profiles/resources/ -> Profiles.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  var Settings_Profiles_Js = {
  11      
  12      initEditView: function() {
  13  
  14  		function toggleEditViewTableRow(e) {
  15              var target = jQuery(e.currentTarget);
  16              var container = jQuery('[data-togglecontent="'+ target.data('togglehandler') + '"]');
  17              var closestTrElement = container.closest('tr');
  18              
  19              if (target.find('i').hasClass('icon-chevron-down')) {
  20                  closestTrElement.removeClass('hide');
  21                  container.slideDown('slow');
  22                  target.find('.icon-chevron-down').removeClass('icon-chevron-down').addClass('icon-chevron-up');
  23              } else {
  24                  container.slideUp('slow',function(){
  25                      closestTrElement.addClass('hide');
  26                  });
  27                  target.find('.icon-chevron-up').removeClass('icon-chevron-up').addClass('icon-chevron-down');
  28              }
  29          }
  30          
  31  		function handleChangeOfPermissionRange(e, ui) {
  32              var target = jQuery(ui.handle);
  33              if (!target.hasClass('mini-slider-control')) {
  34                  target = target.closest('.mini-slider-control');
  35              }
  36              var input  = jQuery('[data-range-input="'+target.data('range')+'"]');
  37              input.val(ui.value);
  38              target.attr('data-value', ui.value);
  39          }
  40          
  41  		function handleModuleSelectionState(e) {
  42              var target = jQuery(e.currentTarget);
  43              var tabid  = target.data('value');
  44              
  45              var parent = target.closest('tr');
  46              if (target.attr('checked')) {
  47                  jQuery('[data-action-state]', parent).attr('checked', 'checked');
  48                  jQuery('[data-handlerfor]', parent).removeAttr('disabled');
  49              } else {
  50                  jQuery('[data-action-state]', parent).attr('checked', false);
  51                  
  52                  // Pull-up fields / tools details in disabled state.
  53                  jQuery('[data-handlerfor]', parent).attr('disabled', 'disabled');
  54                  jQuery('[data-togglecontent="'+tabid+'-fields"]').hide();
  55                  jQuery('[data-togglecontent="'+tabid+'-tools"]').hide();
  56              }
  57          }
  58          
  59  		function handleActionSelectionState(e) {
  60              var target = jQuery(e.currentTarget);
  61              var parent = target.closest('tr');
  62              var checked = target.attr('checked')? true : false;
  63              
  64              if (target.data('action-state') == 'EditView' || target.data('action-state') == 'Delete') {
  65                  if (checked) {
  66                      jQuery('[data-action-state="DetailView"]', parent).attr('checked', 'checked');
  67                      jQuery('[data-module-state]', parent).attr('checked', 'checked');
  68                      jQuery('[data-handlerfor]', parent).removeAttr('disabled');
  69                  }
  70              }
  71              if (target.data('action-state') == 'DetailView') {
  72                  if (!checked) {
  73                      jQuery('[data-action-state]', parent).removeAttr('checked');
  74                      jQuery('[data-module-state]', parent).removeAttr('checked').trigger('change');
  75                  } else {
  76                      jQuery('[data-module-state]', parent).attr('checked', 'checked');
  77                      jQuery('[data-handlerfor]', parent).removeAttr('disabled');
  78                  }
  79              }
  80          }
  81          
  82  		function selectAllModulesViewAndToolPriviliges(e) {
  83              var target = jQuery(e.currentTarget);
  84              var checked = target.attr('checked')? true : false;
  85              if(checked) {
  86                  jQuery('#mainAction4CheckBox').attr('checked','checked');
  87                  jQuery('#mainModulesCheckBox').attr('checked','checked');
  88                  jQuery('.modulesCheckBox').attr('checked','checked');
  89                  jQuery('.action4CheckBox').attr('checked','checked');
  90                  jQuery('[data-handlerfor]').removeAttr('disabled');
  91              }
  92          }
  93          
  94          jQuery('[data-module-state]').change(handleModuleSelectionState);
  95          jQuery('[data-action-state]').change(handleActionSelectionState);
  96          jQuery('#mainAction1CheckBox,#mainAction2CheckBox').change(selectAllModulesViewAndToolPriviliges);
  97          
  98          jQuery('[data-togglehandler]').click(toggleEditViewTableRow);
  99          jQuery('[data-range]').each(function(index, item) {
 100              item = jQuery(item);
 101              var value = item.data('value');
 102              item.slider({
 103                  min: 0,
 104                  max: 2,
 105                  value: value,
 106                  disabled: item.data('locked'),
 107                  slide: handleChangeOfPermissionRange
 108              });
 109          });    
 110          
 111          //fix for IE jQuery UI slider
 112          jQuery('[data-range]').find('a').css('filter','');
 113  
 114      },
 115      
 116      registerSelectAllModulesEvent : function() {
 117          var moduleCheckBoxes = jQuery('.modulesCheckBox');
 118          var viewAction = jQuery('#mainAction4CheckBox');
 119          var createAction = jQuery('#mainAction1CheckBox');
 120          var deleteACtion = jQuery('#mainAction2CheckBox');
 121          var mainModulesCheckBox = jQuery('#mainModulesCheckBox');
 122          mainModulesCheckBox.on('change',function(e) {
 123              var mainCheckBox = jQuery(e.currentTarget);
 124              if(mainCheckBox.is(':checked')){
 125                  moduleCheckBoxes.attr('checked',true);
 126                  viewAction.attr('checked',true);
 127                  createAction.show().attr('checked',true);
 128                  deleteACtion.show().attr('checked',true);
 129                  moduleCheckBoxes.trigger('change');
 130              } else {
 131                  moduleCheckBoxes.attr('checked',false);
 132                  moduleCheckBoxes.trigger('change');
 133                  viewAction.attr('checked',false);
 134                  createAction.attr('checked', false);
 135                  deleteACtion.attr('checked', false);
 136              }
 137          });
 138          
 139          moduleCheckBoxes.on('change',function(){
 140              Settings_Profiles_Js.checkSelectAll(moduleCheckBoxes,mainModulesCheckBox);
 141              Settings_Profiles_Js.checkSelectAll(jQuery('.action4CheckBox'),viewAction);
 142              Settings_Profiles_Js.checkSelectAll(jQuery('.action1CheckBox'),createAction);
 143              Settings_Profiles_Js.checkSelectAll(jQuery('.action2CheckBox'),deleteACtion);
 144          });
 145      },
 146      
 147      registerSelectAllViewActionsEvent : function() {
 148          var viewActionCheckBoxes = jQuery('.action4CheckBox');
 149          var mainViewActionCheckBox = jQuery('#mainAction4CheckBox');
 150          var modulesMainCheckBox = jQuery('#mainModulesCheckBox');
 151          
 152          mainViewActionCheckBox.on('change',function(e){
 153              var mainCheckBox = jQuery(e.currentTarget);
 154              if(mainCheckBox.is(':checked')){
 155                  modulesMainCheckBox.attr('checked',true);
 156                  modulesMainCheckBox.trigger('change');
 157              } else {
 158                  modulesMainCheckBox.attr('checked',false);
 159                  modulesMainCheckBox.trigger('change');
 160              }
 161          });
 162          
 163          viewActionCheckBoxes.on('change',function() {
 164              Settings_Profiles_Js.checkSelectAll(viewActionCheckBoxes,mainViewActionCheckBox);
 165          });
 166          
 167      },
 168      
 169      registerSelectAllCreateActionsEvent : function() {
 170          var createActionCheckBoxes = jQuery('.action1CheckBox');
 171          var mainCreateActionCheckBox =  jQuery('#mainAction1CheckBox');
 172          mainCreateActionCheckBox.on('change',function(e){
 173              var mainCheckBox = jQuery(e.currentTarget);
 174              if(mainCheckBox.is(':checked')){
 175                  createActionCheckBoxes.attr('checked',true);
 176              } else {
 177                  createActionCheckBoxes.attr('checked',false);
 178              }
 179          });
 180          createActionCheckBoxes.on('change',function() {
 181              Settings_Profiles_Js.checkSelectAll(createActionCheckBoxes,mainCreateActionCheckBox);
 182          });
 183          
 184      },
 185      
 186      registerSelectAllDeleteActionsEvent : function() {
 187          var deleteActionCheckBoxes = jQuery('.action2CheckBox');
 188          var mainDeleteActionCheckBox =  jQuery('#mainAction2CheckBox');
 189          mainDeleteActionCheckBox.on('change',function(e){
 190              var mainCheckBox = jQuery(e.currentTarget);
 191              if(mainCheckBox.is(':checked')){
 192                  deleteActionCheckBoxes.attr('checked',true);
 193              } else {
 194                  deleteActionCheckBoxes.attr('checked',false);
 195              }
 196          });
 197          deleteActionCheckBoxes.on('change',function() {
 198              Settings_Profiles_Js.checkSelectAll(deleteActionCheckBoxes,mainDeleteActionCheckBox);
 199          });
 200      },
 201  
 202      checkSelectAll : function(checkBoxElement,mainCheckBoxElement){
 203          var state = true;
 204          if(typeof checkBoxElement == 'undefined' || typeof mainCheckBoxElement == 'undefined'){
 205              return false;
 206          }
 207          checkBoxElement.each(function(index,element){
 208              if(jQuery(element).is(':checked')){
 209                  state = true;
 210              }else{
 211                  state = false;
 212                  return false;
 213              }
 214          });
 215          if(state == true){
 216              mainCheckBoxElement.attr('checked',true);
 217          } else {
 218              mainCheckBoxElement.attr('checked', false);
 219          }
 220      },
 221      
 222      performSelectAllActionsOnLoad : function() {
 223          if(jQuery('[data-module-unchecked]').length > 0){
 224              jQuery('#mainModulesCheckBox').attr('checked',false);
 225          }
 226          
 227          if(jQuery('[data-action4-unchecked]').length <= 0){
 228              jQuery('#mainAction4CheckBox').attr('checked',true);
 229          }
 230          if(jQuery('[data-action1-unchecked]').length <= 0) {
 231              jQuery('#mainAction1CheckBox').attr('checked',true);
 232          }
 233          if(jQuery('[data-action2-unchecked]').length > 0) {
 234              jQuery('#mainAction2CheckBox').attr('checked',false);
 235          }
 236      }, 
 237      
 238      registerSubmitEvent : function() {
 239          var thisInstance = this;
 240          var form = jQuery('[name="EditProfile"]');
 241          form.on('submit',function(e) {
 242              if(form.data('submit') == 'true' && form.data('performCheck') == 'true') {
 243                  return true;
 244              } else {
 245                  if(form.data('jqv').InvalidFields.length <= 0) {
 246                      var formData = form.serializeFormData();
 247                      thisInstance.checkDuplicateName({
 248                          'profileName' : formData.profilename,
 249                          'profileId' : formData.record
 250                      }).then(
 251                          function(data){
 252                              form.data('submit', 'true');
 253                              form.data('performCheck', 'true');
 254                              form.submit();
 255                          },
 256                          function(data, err){
 257                              var params = {};
 258                              params['text'] = data['message'];
 259                              params['type'] = 'error';
 260                              Settings_Vtiger_Index_Js.showMessage(params);
 261                              return false;
 262                          }
 263                      );
 264                  } else {
 265                      //If validation fails, form should submit again
 266                      form.removeData('submit');
 267                      // to avoid hiding of error message under the fixed nav bar
 268                      app.formAlignmentAfterValidation(form);
 269                  }
 270                  e.preventDefault();
 271              }
 272          })
 273      },
 274      
 275      /*
 276       * Function to check Duplication of Profile Name
 277       * returns boolean true or false
 278       */
 279  
 280      checkDuplicateName : function(details) {
 281          var profileName = details.profileName;
 282          var recordId = details.profileId;
 283          var aDeferred = jQuery.Deferred();
 284          
 285          var params = {
 286          'module' : app.getModuleName(),
 287          'parent' : app.getParentModuleName(),
 288          'action' : 'EditAjax',
 289          'mode' : 'checkDuplicate',
 290          'profilename' : profileName,
 291          'record' : recordId
 292          }
 293          
 294          AppConnector.request(params).then(
 295              function(data) {
 296                  var response = data['result'];
 297                  var result = response['success'];
 298                  if(result == true) {
 299                      aDeferred.reject(response);
 300                  } else {
 301                      aDeferred.resolve(response);
 302                  }
 303              },
 304              function(error,err){
 305                  aDeferred.reject();
 306              }
 307          );
 308          return aDeferred.promise();
 309      },
 310      
 311      registerGlobalPermissionActionsEvent : function() {
 312          var editAllAction = jQuery('[name="editall"]').filter(':checkbox');
 313          var viewAllAction = jQuery('[name="viewall"]').filter(':checkbox');
 314          
 315          if(editAllAction.is(':checked')) {
 316              viewAllAction.attr('readonly', 'readonly');
 317          }
 318          
 319          viewAllAction.on('change', function(e) {
 320              var currentTarget = jQuery(e.currentTarget);
 321              if(currentTarget.attr('readonly') == 'readonly') {
 322                  var status = jQuery(e.currentTarget).is(':checked');
 323                  if(!status){
 324                      jQuery(e.currentTarget).attr('checked','checked')
 325                  }else{
 326                      jQuery(e.currentTarget).removeAttr('checked');
 327                  }
 328                  e.preventDefault();
 329              }
 330          })
 331          
 332          editAllAction.on('change', function(e) {
 333              var currentTarget = jQuery(e.currentTarget);
 334              if(currentTarget.is(':checked')) {
 335                  viewAllAction.attr('checked', 'checked');
 336                  viewAllAction.attr('readonly', 'readonly');
 337              } else {
 338                  viewAllAction.removeAttr('readonly');
 339              }
 340          })
 341      },
 342      
 343      registerEvents : function() {
 344          Settings_Profiles_Js.initEditView();
 345          Settings_Profiles_Js.registerSelectAllModulesEvent();
 346          Settings_Profiles_Js.registerSelectAllViewActionsEvent();
 347          Settings_Profiles_Js.registerSelectAllCreateActionsEvent();
 348          Settings_Profiles_Js.registerSelectAllDeleteActionsEvent();
 349          Settings_Profiles_Js.performSelectAllActionsOnLoad();
 350          Settings_Profiles_Js.registerSubmitEvent();
 351          Settings_Profiles_Js.registerGlobalPermissionActionsEvent();
 352      }
 353      
 354  }
 355  jQuery(document).ready(function(){
 356      Settings_Profiles_Js.registerEvents();
 357  })


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