[ 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 var Settings_Roles_Js = { 10 11 newPriviliges : false, 12 13 initDeleteView: function() { 14 jQuery('#roleDeleteForm').validationEngine(app.validationEngineOptions); 15 16 jQuery('[data-action="popup"]').on('click',function(e) { 17 e.preventDefault(); 18 var target = $(e.currentTarget); 19 var field = target.data('field'); 20 21 // TODO simiplify by pushing the retrieveSelectedRecords to library 22 var popupInstance = Vtiger_Popup_Js.getInstance(); 23 popupInstance.show(target.data('url')); 24 popupInstance.retrieveSelectedRecords(function(data) { 25 try { 26 data = JSON.parse(data); 27 } catch (e) {} 28 29 if (typeof data == 'object') { 30 jQuery('[name="'+field+'_display"]').val(data.label); 31 data = data.value; 32 } 33 jQuery('[name="'+field+'"]').val(data); 34 }); 35 }); 36 37 jQuery('#clearRole').on('click',function(e){ 38 jQuery('[name="transfer_record_display"]').val(''); 39 }); 40 }, 41 42 initPopupView: function() { 43 jQuery('.roleEle').click(function(e){ 44 var target = $(e.currentTarget); 45 // jquery_windowmsg plugin expects second parameter to be string. 46 jQuery.triggerParentEvent('postSelection', JSON.stringify({value: target.closest('li').data('roleid'), label: target.text()})); 47 self.close(); 48 }); 49 }, 50 51 initEditView: function() { 52 53 function applyMoveChanges(roleid, parent_roleid) { 54 var params = { 55 module: 'Roles', 56 action: 'MoveAjax', 57 parent: 'Settings', 58 record: roleid, 59 parent_roleid: parent_roleid 60 } 61 62 AppConnector.request(params).then(function(res) { 63 if (!res.success) { 64 alert(app.vtranslate('JS_FAILED_TO_SAVE')); 65 window.location.reload(); 66 } 67 }); 68 } 69 70 jQuery('[rel="tooltip"]').tooltip(); 71 72 function modalActionHandler(event) { 73 var target = $(event.currentTarget); 74 app.showModalWindow(null, target.data('url'),function(data){ 75 Settings_Roles_Js.initDeleteView(); 76 }); 77 } 78 79 jQuery('[data-action="modal"]').click(modalActionHandler); 80 81 jQuery('.toolbar').hide(); 82 83 jQuery('.toolbar-handle').bind('mouseover', function(e){ 84 var target = $(e.currentTarget); 85 jQuery('.toolbar', target).css({display: 'inline'}); 86 }); 87 jQuery('.toolbar-handle').bind('mouseout', function(e){ 88 var target = $(e.currentTarget); 89 jQuery('.toolbar', target).hide(); 90 }); 91 92 jQuery('.draggable').draggable({ 93 containment: '.treeView', 94 start : function(event, ui) { 95 var container = jQuery(ui.helper); 96 var referenceid = container.data('refid'); 97 var sourceGroup = jQuery('[data-grouprefid="'+referenceid+'"]'); 98 var sourceRoleId = sourceGroup.data('roleid'); 99 if(sourceRoleId == 'H5' || sourceRoleId == 'H2') { 100 var params = {}; 101 params.title = app.vtranslate('JS_PERMISSION_DENIED'); 102 params.text = app.vtranslate('JS_NO_PERMISSIONS_TO_MOVE'); 103 params.type = 'error'; 104 Settings_Vtiger_Index_Js.showMessage(params); 105 } 106 }, 107 helper: function(event) { 108 var target = $(event.currentTarget); 109 var targetGroup = target.closest('li'); 110 var timestamp = +(new Date()); 111 112 var container = $('<div/>'); 113 container.data('refid', timestamp); 114 container.html(targetGroup.clone()); 115 116 // For later reference we shall assign the id before we return 117 targetGroup.attr('data-grouprefid', timestamp); 118 119 return container; 120 } 121 }); 122 jQuery('.droppable').droppable({ 123 hoverClass: 'btn-primary', 124 tolerance: 'pointer', 125 drop: function(event, ui) { 126 var container = $(ui.helper); 127 var referenceid = container.data('refid'); 128 var sourceGroup = $('[data-grouprefid="'+referenceid+'"]'); 129 130 var thisWrapper = $(this).closest('div'); 131 132 var targetRole = thisWrapper.closest('li').data('role'); 133 var targetRoleId= thisWrapper.closest('li').data('roleid'); 134 var sourceRole = sourceGroup.data('role'); 135 var sourceRoleId = sourceGroup.data('roleid'); 136 137 // Attempt to push parent-into-its own child hierarchy? 138 if (targetRole.indexOf(sourceRole) == 0) { 139 // Sorry 140 return; 141 } 142 //Attempt to move the roles CEO and Sales Person 143 if (sourceRoleId == 'H5' || sourceRoleId == 'H2') { 144 return; 145 } 146 sourceGroup.appendTo(thisWrapper.next('ul')); 147 148 applyMoveChanges(sourceRoleId, targetRoleId); 149 } 150 }); 151 }, 152 153 registerShowNewProfilePrivilegesEvent : function() { 154 jQuery('[name="profile_directly_related_to_role"]').on('change',function(e){ 155 var target = jQuery(e.currentTarget); 156 var hanlder = target.data('handler'); 157 if(hanlder == 'new'){ 158 Settings_Roles_Js.getProfilePriviliges();return false; 159 } 160 var container = jQuery('[data-content="'+ hanlder + '"]'); 161 jQuery('[data-content]').not(container).fadeOut('slow',function(){ 162 container.fadeIn('slow'); 163 }); 164 }) 165 }, 166 167 onLoadProfilePrivilegesAjax : function() { 168 jQuery('[name="profile_directly_related_to_role"]:checked').trigger('change'); 169 }, 170 171 getProfilePriviliges : function() { 172 var content = jQuery('[data-content="new"]'); 173 var profileId = jQuery('[name="profile_directly_related_to_role_id"]').val(); 174 var params = { 175 module : 'Profiles', 176 parent: 'Settings', 177 view : 'EditAjax', 178 record : profileId 179 } 180 if(Settings_Roles_Js.newPriviliges == true) { 181 jQuery('[data-content="existing"]').fadeOut('slow',function(){ 182 content.fadeIn('slow'); 183 }); 184 return false; 185 } 186 var progressIndicatorElement = jQuery.progressIndicator({ 187 'position' : 'html', 188 'blockInfo' : { 189 'enabled' : true 190 } 191 }); 192 AppConnector.request(params).then(function(data) { 193 content.find('.fieldValue').html(data); 194 app.changeSelectElementView(jQuery('#directProfilePriviligesSelect'), 'select2'); 195 Settings_Roles_Js.registerExistingProfilesChangeEvent(); 196 progressIndicatorElement.progressIndicator({ 197 'mode' : 'hide' 198 }); 199 Settings_Roles_Js.newPriviliges = true; 200 jQuery('[data-content="existing"]').fadeOut('slow',function(){ 201 content.fadeIn('slow',function(){ 202 }); 203 }); 204 }) 205 }, 206 207 registerExistingProfilesChangeEvent : function() { 208 jQuery('#directProfilePriviligesSelect').on('change',function(e) { 209 var profileId = jQuery(e.currentTarget).val(); 210 var params = { 211 module : 'Profiles', 212 parent: 'Settings', 213 view : 'EditAjax', 214 record : profileId 215 } 216 var progressIndicatorElement = jQuery.progressIndicator({ 217 'position' : 'html', 218 'blockInfo' : { 219 'enabled' : true 220 } 221 }); 222 223 AppConnector.request(params).then(function(data) { 224 jQuery('[data-content="new"]').find('.fieldValue').html(data); 225 progressIndicatorElement.progressIndicator({ 226 'mode' : 'hide' 227 }); 228 app.changeSelectElementView(jQuery('#directProfilePriviligesSelect'), 'select2'); 229 Settings_Roles_Js.registerExistingProfilesChangeEvent(); 230 }); 231 }); 232 }, 233 234 registerSubmitEvent : function() { 235 var thisInstance = this; 236 var form = jQuery('#EditView'); 237 form.on('submit',function(e) { 238 if(form.data('submit') == 'true' && form.data('performCheck') == 'true') { 239 return true; 240 } else { 241 if(jQuery('[data-handler="existing"]').is(':checked')){ 242 var selectElement = jQuery('#profilesList'); 243 var select2Element = app.getSelect2ElementFromSelect(selectElement); 244 var result = Vtiger_MultiSelect_Validator_Js.invokeValidation(selectElement); 245 if(result != true){ 246 select2Element.validationEngine('showPrompt', result , 'error','bottomLeft',true); 247 e.preventDefault(); 248 return; 249 } else { 250 select2Element.validationEngine('hide'); 251 } 252 } 253 254 if(form.data('jqv').InvalidFields.length <= 0) { 255 var formData = form.serializeFormData(); 256 thisInstance.checkDuplicateName({ 257 'rolename' : formData.rolename, 258 'record' : formData.record 259 }).then( 260 function(data){ 261 form.data('submit', 'true'); 262 form.data('performCheck', 'true'); 263 form.submit(); 264 jQuery.progressIndicator({ 265 'blockInfo' : { 266 'enabled' : true 267 } 268 }); 269 }, 270 function(data, err){ 271 var params = {}; 272 params['text'] = data['message']; 273 params['type'] = 'error'; 274 Settings_Vtiger_Index_Js.showMessage(params); 275 return false; 276 } 277 ); 278 } else { 279 //If validation fails, form should submit again 280 form.removeData('submit'); 281 // to avoid hiding of error message under the fixed nav bar 282 app.formAlignmentAfterValidation(form); 283 } 284 e.preventDefault(); 285 } 286 }); 287 }, 288 289 /* 290 * Function to check Duplication of Role Names 291 * returns boolean true or false 292 */ 293 294 checkDuplicateName : function(details) { 295 var aDeferred = jQuery.Deferred(); 296 297 var params = { 298 'module' : app.getModuleName(), 299 'parent' : app.getParentModuleName(), 300 'action' : 'EditAjax', 301 'mode' : 'checkDuplicate', 302 'rolename' : details.rolename, 303 'record' : details.record 304 } 305 306 AppConnector.request(params).then( 307 function(data) { 308 var response = data['result']; 309 var result = response['success']; 310 if(result == true) { 311 aDeferred.reject(response); 312 } else { 313 aDeferred.resolve(response); 314 } 315 }, 316 function(error,err){ 317 aDeferred.reject(); 318 } 319 ); 320 return aDeferred.promise(); 321 }, 322 323 registerEvents : function() { 324 Settings_Roles_Js.initEditView(); 325 Settings_Roles_Js.registerShowNewProfilePrivilegesEvent(); 326 Settings_Roles_Js.onLoadProfilePrivilegesAjax(); 327 Settings_Roles_Js.registerSubmitEvent(); 328 } 329 } 330 jQuery(document).ready(function(){ 331 Settings_Roles_Js.registerEvents(); 332 })
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 |