[ 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 Reports_Edit_Js("Reports_Edit1_Js",{},{ 10 11 relatedModulesMapping : false, 12 step1Container : false, 13 secondaryModulesContainer : false, 14 15 init : function() { 16 this.initialize(); 17 }, 18 /** 19 * Function to get the container which holds all the reports step1 elements 20 * @return jQuery object 21 */ 22 getContainer : function() { 23 return this.step1Container; 24 }, 25 26 /** 27 * Function to set the reports step1 container 28 * @params : element - which represents the reports step1 container 29 * @return : current instance 30 */ 31 setContainer : function(element) { 32 this.step1Container = element; 33 return this; 34 }, 35 /* 36 * Function to get the secondary module container 37 */ 38 getSecondaryModuleContainer : function(){ 39 if(this.secondaryModulesContainer == false){ 40 this.secondaryModulesContainer = jQuery('#secondary_module'); 41 } 42 return this.secondaryModulesContainer; 43 }, 44 45 /** 46 * Function to intialize the reports step1 47 */ 48 initialize : function(container) { 49 if(typeof container == 'undefined') { 50 container = jQuery('#report_step1'); 51 } 52 if(container.is('#report_step1')) { 53 this.setContainer(container); 54 }else{ 55 this.setContainer(jQuery('#report_step1')); 56 } 57 this.intializeOperationMappingDetails(); 58 }, 59 /** 60 * Function which will save the related modules mapping 61 */ 62 intializeOperationMappingDetails : function() { 63 this.relatedModulesMapping = jQuery('#relatedModules').data('value'); 64 }, 65 66 /** 67 * Function which will return set of condition for the given field type 68 * @return array of conditions 69 */ 70 getRelatedModulesFromPrimaryModule : function(primaryModule){ 71 return this.relatedModulesMapping[primaryModule]; 72 }, 73 74 loadRelatedModules : function(primaryModule){ 75 var relatedModulesMapping = this.getRelatedModulesFromPrimaryModule(primaryModule); 76 var options = ''; 77 for(var key in relatedModulesMapping) { 78 //IE Browser consider the prototype properties also, it should consider has own properties only. 79 if(relatedModulesMapping.hasOwnProperty(key)) { 80 options += '<option value="'+key+'">'+relatedModulesMapping[key]+'</option>'; 81 } 82 } 83 var secondaryModulesContainer = this.getSecondaryModuleContainer(); 84 secondaryModulesContainer.html(options).trigger("change"); 85 86 }, 87 registerPrimaryModuleChangeEvent : function(){ 88 var thisInstance = this; 89 jQuery('#primary_module').on('change',function(e){ 90 var primaryModule = jQuery(e.currentTarget).val(); 91 thisInstance.loadRelatedModules(primaryModule); 92 }); 93 }, 94 95 /* 96 * Function to check Duplication of report Name 97 * returns boolean true or false 98 */ 99 checkDuplicateName : function(details) { 100 var aDeferred = jQuery.Deferred(); 101 var moduleName = app.getModuleName(); 102 var params = { 103 'module' : moduleName, 104 'action' : "CheckDuplicate", 105 'reportname' : details.reportName, 106 'record' : details.reportId, 107 'isDuplicate' : details.isDuplicate 108 } 109 110 AppConnector.request(params).then( 111 function(data) { 112 var response = data['result']; 113 var result = response['success']; 114 if(result == true) { 115 aDeferred.reject(response); 116 } else { 117 aDeferred.resolve(response); 118 } 119 }, 120 function(error,err){ 121 aDeferred.reject(); 122 } 123 ); 124 return aDeferred.promise(); 125 }, 126 127 128 submit : function(){ 129 var thisInstance = this; 130 var aDeferred = jQuery.Deferred(); 131 var form = this.getContainer(); 132 var formData = form.serializeFormData(); 133 134 var params = {}; 135 var reportName = jQuery.trim(formData.reportname); 136 var reportId = formData.record; 137 138 var progressIndicatorElement = jQuery.progressIndicator({ 139 'position' : 'html', 140 'blockInfo' : { 141 'enabled' : true 142 } 143 }); 144 145 thisInstance.checkDuplicateName({ 146 'reportName' : reportName, 147 'reportId' : reportId, 148 'isDuplicate' : formData.isDuplicate 149 }).then( 150 function(data){ 151 AppConnector.request(formData).then( 152 function(data) { 153 form.hide(); 154 progressIndicatorElement.progressIndicator({ 155 'mode' : 'hide' 156 }) 157 aDeferred.resolve(data); 158 }, 159 function(error,err){ 160 161 } 162 ); 163 }, 164 function(data, err){ 165 progressIndicatorElement.progressIndicator({ 166 'mode' : 'hide' 167 }); 168 params = { 169 title: app.vtranslate('JS_DUPLICATE_RECORD'), 170 text: data['message'] 171 }; 172 Vtiger_Helper_Js.showPnotify(params); 173 aDeferred.reject(); 174 } 175 ); 176 return aDeferred.promise(); 177 }, 178 179 /** 180 * Function which will register the select2 elements for secondary modules selection 181 */ 182 registerSelect2ElementForSecondaryModulesSelection : function() { 183 var secondaryModulesContainer = this.getSecondaryModuleContainer(); 184 app.changeSelectElementView(secondaryModulesContainer, 'select2', {maximumSelectionSize: 2}); 185 }, 186 187 /** 188 * Function to register event for scheduled reports UI 189 */ 190 registerEventForScheduledReprots : function() { 191 var thisInstance = this; 192 jQuery('input[name="enable_schedule"]').on('click', function(e) { 193 var element = jQuery(e.currentTarget); 194 var scheduleBoxContainer = jQuery('#scheduleBox'); 195 if(element.is(':checked')) { 196 element.val(element.is(':checked')); 197 scheduleBoxContainer.removeClass('hide'); 198 } else { 199 element.val(element.is(':checked')); 200 scheduleBoxContainer.addClass('hide'); 201 } 202 }); 203 app.registerEventForTimeFields('#schtime', true); 204 app.registerEventForDatePickerFields('#scheduleByDate', true); 205 206 jQuery('#annualDates').chosen(); 207 jQuery('#schdayoftheweek').chosen(); 208 jQuery('#schdayofthemonth').chosen(); 209 jQuery('#recipients').chosen(); 210 211 var currentYear = new Date().getFullYear(); 212 jQuery('#annualDatePicker').datepick({autoSize: true, multiSelect:100,monthsToShow: [1,2], 213 minDate: '01/01/'+currentYear, maxDate: '12/31/'+currentYear, 214 yearRange: currentYear+':'+currentYear, 215 onShow : function() { 216 //Hack to remove the year 217 thisInstance.removeYearInAnnualReport(); 218 }, 219 onSelect : function(dates) { 220 var datesInfo = []; 221 var values = []; 222 var html=''; 223 // reset the annual dates 224 var annualDatesEle = jQuery('#annualDates'); 225 thisInstance.updateAnnualDates(annualDatesEle); 226 for(index in dates) { 227 var date = dates[index]; 228 datesInfo.push({ 229 id:thisInstance.DateToYMD(date), 230 text:thisInstance.DateToYMD(date) 231 }); 232 values.push(thisInstance.DateToYMD(date)); 233 html += '<option selected value='+thisInstance.DateToYMD(date)+'>'+thisInstance.DateToYMD(date)+'</option>'; 234 } 235 annualDatesEle.append(html); 236 annualDatesEle.trigger("liszt:updated"); 237 } 238 }); 239 var annualDatesEle = jQuery('#annualDates'); 240 thisInstance.updateAnnualDates(annualDatesEle); 241 annualDatesEle.trigger("liszt:updated"); 242 }, 243 244 removeYearInAnnualReport : function() { 245 setTimeout(function() { 246 var year = jQuery('.datepick-month.first').find('.datepick-month-year').get(1); 247 jQuery(year).hide(); 248 var monthHeaders = jQuery('.datepick-month-header'); 249 jQuery.each(monthHeaders, function( key, ele ) { 250 var header = jQuery(ele); 251 var str = header.html().replace(/[\d]+/, ''); 252 header.html(str); 253 }); 254 },100); 255 }, 256 257 updateAnnualDates : function(annualDatesEle) { 258 annualDatesEle.html(''); 259 var annualDatesJSON = jQuery('#hiddenAnnualDates').val(); 260 if(annualDatesJSON) { 261 var hiddenDates = ''; 262 var annualDates = JSON.parse(annualDatesJSON); 263 for(i in annualDates) { 264 hiddenDates += '<option selected value='+annualDates[i]+'>'+annualDates[i]+'</option>'; 265 } 266 annualDatesEle.html(hiddenDates); 267 } 268 }, 269 270 DateToYMD : function (date) { 271 var year, month, day; 272 year = String(date.getFullYear()); 273 month = String(date.getMonth() + 1); 274 if (month.length == 1) { 275 month = "0" + month; 276 } 277 day = String(date.getDate()); 278 if (day.length == 1) { 279 day = "0" + day; 280 } 281 return year + "-" + month + "-" + day; 282 }, 283 284 registerEventForChangeInScheduledType : function() { 285 var thisInstance = this; 286 jQuery('#schtypeid').on('change', function(e){ 287 var element = jQuery(e.currentTarget); 288 var value = element.val(); 289 290 thisInstance.showScheduledTime(); 291 thisInstance.hideScheduledWeekList(); 292 thisInstance.hideScheduledMonthByDateList(); 293 thisInstance.hideScheduledAnually(); 294 thisInstance.hideScheduledSpecificDate(); 295 296 if(value == '2') { //weekly 297 thisInstance.showScheduledWeekList(); 298 } else if(value == '3') { //monthly by day 299 thisInstance.showScheduledMonthByDateList(); 300 } else if(value == '4') { //Anually 301 thisInstance.showScheduledAnually(); 302 } else if(value == '5') { //specific date 303 thisInstance.showScheduledSpecificDate(); 304 } 305 }); 306 }, 307 308 //Remove annual dates element 309 registerEventForRemoveAnnualDates : function() { 310 var thisInstance = this; 311 jQuery("#annualDates").chosen().change(function(e){ 312 jQuery('#hiddenAnnualDates').val(JSON.stringify(jQuery(e.target).val())); 313 var element = jQuery(e.currentTarget); 314 thisInstance.updateAnnualDates(element); 315 element.trigger("liszt:updated"); 316 }); 317 }, 318 319 hideScheduledTime : function() { 320 jQuery('#scheduledTime').addClass('hide'); 321 }, 322 323 showScheduledTime : function() { 324 jQuery('#scheduledTime').removeClass('hide'); 325 }, 326 327 hideScheduledWeekList : function() { 328 jQuery('#scheduledWeekDay').addClass('hide'); 329 }, 330 331 showScheduledWeekList : function() { 332 jQuery('#scheduledWeekDay').removeClass('hide'); 333 }, 334 335 hideScheduledMonthByDateList : function() { 336 jQuery('#scheduleMonthByDates').addClass('hide'); 337 }, 338 339 showScheduledMonthByDateList : function() { 340 jQuery('#scheduleMonthByDates').removeClass('hide'); 341 }, 342 343 hideScheduledSpecificDate : function() { 344 jQuery('#scheduleByDate').addClass('hide'); 345 }, 346 347 showScheduledSpecificDate : function() { 348 jQuery('#scheduleByDate').removeClass('hide'); 349 }, 350 351 hideScheduledAnually : function() { 352 jQuery('#scheduleAnually').addClass('hide'); 353 }, 354 355 showScheduledAnually : function() { 356 jQuery('#scheduleAnually').removeClass('hide'); 357 }, 358 359 registerEvents : function(){ 360 this.registerPrimaryModuleChangeEvent(); 361 this.registerSelect2ElementForSecondaryModulesSelection(); 362 var container = this.getContainer(); 363 364 var opts = app.validationEngineOptions; 365 // to prevent the page reload after the validation has completed 366 opts['onValidationComplete'] = function(form,valid) { 367 //returns the valid status 368 return valid; 369 }; 370 opts['promptPosition'] = "bottomRight"; 371 container.validationEngine(opts); 372 //schedule reports 373 this.registerEventForScheduledReprots(); 374 this.registerEventForChangeInScheduledType(); 375 this.registerEventForRemoveAnnualDates(); 376 } 377 });
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 |