[ Index ] |
PHP Cross Reference of vtigercrm-6.1.0 |
[Summary view] [Print] [Text view]
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_Sharing_Access_Js', {}, { 10 11 contentTable : false, 12 contentsContainer : false, 13 14 init : function() { 15 this.setContentTable('.sharingAccessDetails').setContentContainer('#sharingAccessContainer'); 16 17 }, 18 19 setContentTable : function(element) { 20 if(element instanceof jQuery){ 21 this.contentTable = element; 22 return this; 23 } 24 this.contentTable = jQuery(element); 25 return this; 26 }, 27 28 setContentContainer : function(element) { 29 if(element instanceof jQuery){ 30 this.contentsContainer = element; 31 return this; 32 } 33 this.contentsContainer = jQuery(element); 34 return this; 35 }, 36 37 getContentTable : function() { 38 return this.contentTable; 39 }, 40 41 getContentContainer : function() { 42 return this.contentsContainer; 43 }, 44 45 getCustomRuleContainerClassName : function(parentModuleName) { 46 return parentModuleName+'CustomRuleList'; 47 }, 48 49 showCustomRulesNextToElement : function(parentElement, rulesListElement) { 50 var moduleName = parentElement.data('moduleName') 51 var trElementForRuleList = jQuery('<tr class="'+this.getCustomRuleContainerClassName(moduleName)+'"><td class="customRuleContainer row-fluid" colspan="6"></td></tr>'); 52 jQuery('td',trElementForRuleList).append(rulesListElement); 53 jQuery('.ruleListContainer', trElementForRuleList).css('display', 'none'); 54 parentElement.after(trElementForRuleList).addClass('collapseRow'); 55 jQuery('.ruleListContainer', trElementForRuleList).slideDown('slow'); 56 }, 57 58 /* 59 * function to get custom rules data based on the module 60 * @params: forModule. 61 */ 62 getCustomRules : function(forModule) { 63 var aDeferred = jQuery.Deferred(); 64 var params = {} 65 params['for_module'] = forModule; 66 params['module'] = app.getModuleName(); 67 params['parent'] = app.getParentModuleName(); 68 params['view'] = 'IndexAjax'; 69 params['mode'] = 'showRules'; 70 AppConnector.request(params).then( 71 function(data) { 72 aDeferred.resolve(data); 73 }, 74 function(error) { 75 //TODO : Handle error 76 aDeferred.reject(error); 77 } 78 ); 79 return aDeferred.promise(); 80 }, 81 82 save : function(data) { 83 var aDeferred = jQuery.Deferred(); 84 85 var progressIndicatorElement = jQuery.progressIndicator({ 86 'position' : 'html', 87 'blockInfo' : { 88 'enabled' : true 89 } 90 }); 91 if(typeof data == 'undefined') { 92 data = {}; 93 } 94 95 AppConnector.request(data).then( 96 function(data){ 97 progressIndicatorElement.progressIndicator({'mode' : 'hide'}); 98 aDeferred.resolve(data); 99 }, 100 function(error, errorThrown){ 101 progressIndicatorElement.progressIndicator({'mode' : 'hide'}); 102 aDeferred.reject(error); 103 } 104 ) 105 106 return aDeferred.promise(); 107 }, 108 109 110 111 /* 112 * function to Save the Custom Rule 113 */ 114 saveCustomRule : function(form, e) { 115 var thisInstance = this; 116 var data = form.serializeFormData(); 117 118 if(typeof data == 'undefined' ) { 119 data = {}; 120 } 121 122 var progressIndicatorElement = jQuery.progressIndicator({ 123 'position' : 'html', 124 'blockInfo' : { 125 'enabled' : true 126 } 127 }); 128 data.module = app.getModuleName(); 129 data.parent = app.getParentModuleName(); 130 data.action = 'IndexAjax'; 131 data.mode = 'saveRule'; 132 133 AppConnector.request(data).then( 134 function(data) { 135 progressIndicatorElement.progressIndicator({'mode':'hide'}); 136 app.hideModalWindow(); 137 thisInstance.displaySaveCustomRuleResponse(data); 138 var moduleName = jQuery('[name="for_module"]', form).val(); 139 thisInstance.loadCustomRulesList(moduleName); 140 } 141 ); 142 }, 143 144 /* 145 * function to load the CustomRules List for the module after save the custom rule 146 */ 147 loadCustomRulesList : function(moduleName) { 148 var thisInstance = this; 149 var contentTable = this.getContentTable(); 150 151 thisInstance.getCustomRules(moduleName).then( 152 function(data){ 153 var customRuleListContainer = jQuery('.'+thisInstance.getCustomRuleContainerClassName(moduleName),contentTable); 154 customRuleListContainer.find('td.customRuleContainer').html(data); 155 }, 156 function(error){ 157 //TODO: Handle Error 158 } 159 ); 160 }, 161 162 /* 163 * Function to display the SaveCustomRule response message 164 */ 165 displaySaveCustomRuleResponse : function(data) { 166 var thisInstance = this; 167 var success = data['success']; 168 var params = {}; 169 if(success) { 170 params = { 171 text: app.vtranslate('JS_CUSTOM_RULE_SAVED_SUCCESSFULLY'), 172 type: 'success' 173 } 174 } else { 175 params = { 176 text: app.vtranslate('JS_CUSTOM_RULE_SAVING_FAILED'), 177 type: 'error' 178 } 179 } 180 thisInstance.showNotify(params); 181 }, 182 183 //This will show the notification message of SaveCustomRule using pnotify 184 showNotify : function(customParams) { 185 var params = { 186 text: customParams.text, 187 type: customParams.type, 188 width: '30%', 189 delay: '3000' 190 }; 191 Vtiger_Helper_Js.showPnotify(params); 192 }, 193 194 editCustomRule : function(url) { 195 var thisInstance = this; 196 var progressIndicatorElement = jQuery.progressIndicator({ 197 'position' : 'html', 198 'blockInfo' : { 199 'enabled' : true 200 } 201 }); 202 203 app.showModalWindow(null, url, function(modalContainer){ 204 var form = jQuery('#editCustomRule'); 205 206 form.on('submit', function(e) { 207 //To stop the submit of form 208 e.preventDefault(); 209 var formElement = jQuery(e.currentTarget); 210 thisInstance.saveCustomRule(formElement, e); 211 }) 212 }); 213 }, 214 215 /* 216 * function to delete Custom Rule from the list 217 * @params: deleteElement. 218 */ 219 deleteCustomRule : function(deleteElement) { 220 var deleteUrl = deleteElement.data('url'); 221 var currentRow = deleteElement.closest('tr.customRuleEntries'); 222 var message = app.vtranslate('LBL_DELETE_CONFIRMATION'); 223 Vtiger_Helper_Js.showConfirmationBox({'message' : message}).then(function(data) { 224 AppConnector.request(deleteUrl).then( 225 function(data){ 226 if(data.success == true){ 227 currentRow.fadeOut('slow'); 228 var customRuleTable = currentRow.closest('table .customRuleTable'); 229 //after delete the custom rule, update the sequence number of existing rules 230 var nextRows = currentRow.nextAll('tr.customRuleEntries'); 231 if(nextRows.length > 0){ 232 jQuery.each(nextRows,function(i,element) { 233 var currentSequenceElement = jQuery(element).find('.sequenceNumber'); 234 var updatedNumber = parseInt(currentSequenceElement.text())-1; 235 currentSequenceElement.text(updatedNumber); 236 }); 237 } 238 currentRow.remove(); 239 var customRuleEntries = customRuleTable.find('.customRuleEntries'); 240 //if there are no custom rule entries, we have to hide headers also and show the empty message div 241 if(customRuleEntries.length < 1) { 242 customRuleTable.find('.customRuleHeaders').fadeOut('slow').remove(); 243 customRuleTable.parent().find('.recordDetails').removeClass('hide'); 244 customRuleTable.addClass('hide'); 245 } 246 }else{ 247 Vtiger_Helper_Js.showPnotify(data.error.message); 248 } 249 }); 250 }, 251 function(error, err){ 252 } 253 ); 254 }, 255 256 /* 257 * function to register click event for radio buttons 258 */ 259 registerSharingAccessEdit : function() { 260 var contentContainer = this.getContentContainer(); 261 contentContainer.one('click','input:radio', function(e){ 262 contentContainer.find('button:submit').removeClass('hide'); 263 }); 264 }, 265 266 /* 267 * Function to register change event for dependent modules privileges 268 */ 269 registerDependentModulesPrivilegesChange : function() { 270 var thisInstance = this; 271 var container = thisInstance.getContentContainer(); 272 var contentTable = this.getContentTable(); 273 var modulesList = JSON.parse(container.find('.dependentModules').val()); 274 275 jQuery.each(modulesList, function(moduleName, dependentList) { 276 var dependentPrivilege = contentTable.find('[data-module-name="'+moduleName+'"]').find('[data-action-state="Private"]'); 277 dependentPrivilege.change(function(e) { 278 var currentTarget = jQuery(e.currentTarget); 279 if(currentTarget.is(':checked')) { 280 var message = app.vtranslate('JS_DEPENDENT_PRIVILEGES_SHOULD_CHANGE'); 281 bootbox.alert(message); 282 jQuery.each(dependentList, function(index, module) { 283 contentTable.find('[data-module-name="'+module+'"]').find('[data-action-state="Private"]').attr('checked', 'checked'); 284 }) 285 } 286 }) 287 }) 288 }, 289 290 registerEvents : function() { 291 var thisInstance = this; 292 var contentTable = this.getContentTable(); 293 var contentContainer = this.getContentContainer(); 294 thisInstance.registerSharingAccessEdit(); 295 thisInstance.registerDependentModulesPrivilegesChange(); 296 297 contentTable.on('click', 'td.triggerCustomSharingAccess', function(e){ 298 var element = jQuery(e.currentTarget); 299 var trElement = element.closest('tr'); 300 var moduleName = trElement.data('moduleName'); 301 var customRuleListContainer = jQuery('.'+thisInstance.getCustomRuleContainerClassName(moduleName),contentTable); 302 303 if(customRuleListContainer.length > 0) { 304 if(app.isHidden(customRuleListContainer)) { 305 customRuleListContainer.show(); 306 jQuery('.ruleListContainer', customRuleListContainer).slideDown('slow'); 307 trElement.addClass('collapseRow'); 308 element.find('button.arrowDown').addClass('hide'); 309 element.find('button.arrowUp').removeClass('hide').addClass('show'); 310 }else{ 311 jQuery('.ruleListContainer', customRuleListContainer).slideUp('slow', function(e) { 312 customRuleListContainer.css('display', 'none'); 313 }); 314 element.find('button.arrowUp').addClass('hide'); 315 element.find('button.arrowDown').removeClass('hide').addClass('show'); 316 trElement.removeClass('collapseRow'); 317 } 318 return; 319 } 320 321 var progressIndicatorElement = jQuery.progressIndicator({ 322 'position' : 'html', 323 'blockInfo' : { 324 'enabled' : true 325 } 326 }); 327 328 thisInstance.getCustomRules(moduleName).then( 329 function(data){ 330 progressIndicatorElement.progressIndicator({'mode':'hide'}); 331 thisInstance.showCustomRulesNextToElement(trElement, data); 332 element.find('button.arrowDown').addClass('hide'); 333 element.find('button.arrowUp').removeClass('hide').addClass('show'); 334 }, 335 function(error){ 336 //TODO: Handle Error 337 } 338 ); 339 }); 340 341 contentTable.on('click', 'button.addCustomRule' , function(e) { 342 var button = jQuery(e.currentTarget); 343 thisInstance.editCustomRule(button.data('url')); 344 }) 345 346 contentTable.on('click', '.edit', function(e){ 347 var editElement = jQuery(e.currentTarget); 348 var editUrl = editElement.data('url'); 349 thisInstance.editCustomRule(editUrl); 350 }); 351 352 contentTable.on('click', '.delete', function(e){ 353 var deleteElement = jQuery(e.currentTarget); 354 thisInstance.deleteCustomRule(deleteElement); 355 }); 356 357 contentContainer.on('submit', '#EditSharingAccess', function(e){ 358 e.preventDefault(); 359 var form = jQuery(e.currentTarget); 360 var data = form.serializeFormData(); 361 thisInstance.save(data).then( 362 function(data) { 363 contentContainer.find('button:submit').addClass('hide'); 364 thisInstance.registerSharingAccessEdit(); 365 var params = { 366 text: app.vtranslate('JS_NEW_SHARING_RULES_APPLIED_SUCCESSFULLY'), 367 type: 'success' 368 }; 369 thisInstance.showNotify(params); 370 }, 371 function(error,err){ 372 } 373 ); 374 }); 375 } 376 }); 377 378 379 jQuery(document).ready(function(){ 380 var settingSharingAcessInstance = new Settings_Sharing_Access_Js(); 381 settingSharingAcessInstance.registerEvents(); 382 })
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:08:37 2014 | Cross-referenced by PHPXref 0.7.1 |