[ 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 Settings_Workflows_Edit_Js("Settings_Workflows_Edit3_Js",{},{ 10 11 step3Container : false, 12 13 advanceFilterInstance : false, 14 15 ckEditorInstance : false, 16 17 fieldValueMap : false, 18 19 init : function() { 20 this.initialize(); 21 }, 22 /** 23 * Function to get the container which holds all the reports step1 elements 24 * @return jQuery object 25 */ 26 getContainer : function() { 27 return this.step3Container; 28 }, 29 30 /** 31 * Function to set the reports step1 container 32 * @params : element - which represents the reports step1 container 33 * @return : current instance 34 */ 35 setContainer : function(element) { 36 this.step3Container = element; 37 return this; 38 }, 39 40 /** 41 * Function to intialize the reports step1 42 */ 43 initialize : function(container) { 44 if(typeof container == 'undefined') { 45 container = jQuery('#workflow_step3'); 46 } 47 if(container.is('#workflow_step3')) { 48 this.setContainer(container); 49 }else{ 50 this.setContainer(jQuery('#workflow_step3')); 51 } 52 }, 53 54 registerEditTaskEvent : function() { 55 var thisInstance = this; 56 var container = this.getContainer(); 57 container.on('click','[data-url]',function(e) { 58 var currentElement = jQuery(e.currentTarget); 59 var params = currentElement.data('url'); 60 var progressIndicatorElement = jQuery.progressIndicator({ 61 'position' : 'html', 62 'blockInfo' : { 63 'enabled' : true 64 } 65 }); 66 AppConnector.request(params).then(function(data) { 67 var callBackFunction = function(data) { 68 app.showScrollBar(jQuery('#addTaskContainer').find('#scrollContainer'),{ 69 height : '450px' 70 }); 71 thisInstance.registerVTCreateTodoTaskEvents(); 72 var taskType = jQuery('#taskType').val(); 73 var functionName = 'register'+taskType+'Events'; 74 if(typeof thisInstance[functionName] != 'undefined' ) { 75 thisInstance[functionName].apply(thisInstance); 76 } 77 thisInstance.registerSaveTaskSubmitEvent(taskType); 78 jQuery('#saveTask').validationEngine(app.validationEngineOptions); 79 thisInstance.registerFillTaskFieldsEvent(); 80 thisInstance.registerCheckSelectDateEvent(); 81 } 82 app.showModalWindow(data,function(){ 83 if(typeof callBackFunction == 'function') { 84 callBackFunction(data) 85 } 86 },{'min-width' : '900px'}); 87 }); 88 }); 89 }, 90 registerCheckSelectDateEvent : function() { 91 jQuery('[name="check_select_date"]').on('change',function(e){ 92 if(jQuery(e.currentTarget).is(':checked')){ 93 jQuery('#checkSelectDateContainer').removeClass('hide').addClass('show'); 94 } else { 95 jQuery('#checkSelectDateContainer').removeClass('show').addClass('hide'); 96 } 97 }); 98 }, 99 100 registerSaveTaskSubmitEvent : function(taskType) { 101 var thisInstance = this; 102 jQuery('#saveTask').on('submit',function(e) { 103 var form = jQuery(e.currentTarget); 104 var validationResult = form.validationEngine('validate'); 105 if(validationResult == true) { 106 var customValidationFunctionName = taskType+'CustomValidation'; 107 if(typeof thisInstance[customValidationFunctionName] != 'undefined') { 108 var result = thisInstance[customValidationFunctionName].apply(thisInstance); 109 if(result != true) { 110 var params = { 111 title : app.vtranslate('JS_MESSAGE'), 112 text: result, 113 animation: 'show', 114 type: 'error' 115 } 116 Vtiger_Helper_Js.showPnotify(params); 117 e.preventDefault(); 118 return; 119 } 120 } 121 var preSaveActionFunctionName = 'preSave'+taskType; 122 if(typeof thisInstance[preSaveActionFunctionName] != 'undefined' ) { 123 thisInstance[preSaveActionFunctionName].apply(thisInstance,[taskType]); 124 } 125 var params = form.serializeFormData(); 126 127 AppConnector.request(params).then(function(data){ 128 if(data.result){ 129 thisInstance.getTaskList(); 130 app.hideModalWindow(); 131 } 132 }); 133 } 134 e.preventDefault(); 135 }) 136 }, 137 138 VTUpdateFieldsTaskCustomValidation : function() { 139 return this.checkDuplicateFieldsSelected(); 140 }, 141 142 VTCreateEntityTaskCustomValidation : function() { 143 return this.checkDuplicateFieldsSelected(); 144 }, 145 146 checkDuplicateFieldsSelected : function() { 147 var selectedFieldNames = jQuery('#save_fieldvaluemapping').find('.conditionRow').find('[name="fieldname"]'); 148 var result = true; 149 var failureMessage = app.vtranslate('JS_SAME_FIELDS_SELECTED_MORE_THAN_ONCE'); 150 jQuery.each(selectedFieldNames, function(i, ele) { 151 var fieldName = jQuery(ele).attr("value"); 152 var fields = jQuery("[name="+fieldName+"]").not(':hidden'); 153 if(fields.length > 1) { 154 result = failureMessage; 155 return false; 156 } 157 }); 158 return result; 159 }, 160 161 preSaveVTUpdateFieldsTask : function(tasktype) { 162 var values = this.getValues(tasktype); 163 jQuery('[name="field_value_mapping"]').val(JSON.stringify(values)); 164 }, 165 166 preSaveVTCreateEntityTask : function(tasktype) { 167 var values = this.getValues(tasktype); 168 jQuery('[name="field_value_mapping"]').val(JSON.stringify(values)); 169 }, 170 171 preSaveVTEmailTask : function(tasktype) { 172 var textAreaElement = jQuery('#content'); 173 //To keep the plain text value to the textarea which need to be 174 //sent to server 175 textAreaElement.val(CKEDITOR.instances['content'].getData()); 176 }, 177 178 /** 179 * Function to check if the field selected is empty field 180 * @params : select element which represents the field 181 * @return : boolean true/false 182 */ 183 isEmptyFieldSelected : function(fieldSelect) { 184 var selectedOption = fieldSelect.find('option:selected'); 185 //assumption that empty field will be having value none 186 if(selectedOption.val() == 'none'){ 187 return true; 188 } 189 return false; 190 }, 191 192 getVTCreateEntityTaskFieldList : function() { 193 return new Array('fieldname', 'value', 'valuetype','modulename'); 194 }, 195 196 getVTUpdateFieldsTaskFieldList : function() { 197 return new Array('fieldname', 'value', 'valuetype'); 198 }, 199 200 getValues : function(tasktype) { 201 var thisInstance = this; 202 var conditionsContainer = jQuery('#save_fieldvaluemapping'); 203 var fieldListFunctionName = 'get'+tasktype+'FieldList'; 204 if(typeof thisInstance[fieldListFunctionName] != 'undefined' ){ 205 var fieldList = thisInstance[fieldListFunctionName].apply() 206 } 207 208 var values = []; 209 var conditions = jQuery('.conditionRow', conditionsContainer); 210 conditions.each(function(i, conditionDomElement){ 211 var rowElement = jQuery(conditionDomElement); 212 var fieldSelectElement = jQuery('[name="fieldname"]', rowElement); 213 var valueSelectElement = jQuery('[data-value="value"]',rowElement); 214 //To not send empty fields to server 215 if(thisInstance.isEmptyFieldSelected(fieldSelectElement)) { 216 return true; 217 } 218 var fieldDataInfo = fieldSelectElement.find('option:selected').data('fieldinfo'); 219 var fieldType = fieldDataInfo.type; 220 var rowValues = {}; 221 if(fieldType == 'owner'){ 222 for(var key in fieldList) { 223 var field = fieldList[key]; 224 if(field == 'value' && valueSelectElement.is('select')){ 225 rowValues[field] = valueSelectElement.find('option:selected').val(); 226 } else { 227 rowValues[field] = jQuery('[name="'+field+'"]', rowElement).val(); 228 } 229 } 230 } else if (fieldType == 'picklist' || fieldType == 'multipicklist') { 231 for(var key in fieldList) { 232 var field = fieldList[key]; 233 if(field == 'value' && valueSelectElement.is('input')) { 234 var commaSeperatedValues = valueSelectElement.val(); 235 var pickListValues = valueSelectElement.data('picklistvalues'); 236 var valuesArr = commaSeperatedValues.split(','); 237 var newvaluesArr = []; 238 for(i=0;i<valuesArr.length;i++){ 239 if(typeof pickListValues[valuesArr[i]] != 'undefined'){ 240 newvaluesArr.push(pickListValues[valuesArr[i]]); 241 } else { 242 newvaluesArr.push(valuesArr[i]); 243 } 244 } 245 var reconstructedCommaSeperatedValues = newvaluesArr.join(','); 246 rowValues[field] = reconstructedCommaSeperatedValues; 247 } else if(field == 'value' && valueSelectElement.is('select') && fieldType == 'picklist'){ 248 rowValues[field] = valueSelectElement.val(); 249 } else if(field == 'value' && valueSelectElement.is('select') && fieldType == 'multipicklist'){ 250 var value = valueSelectElement.val(); 251 if(value == null){ 252 rowValues[field] = value; 253 } else { 254 rowValues[field] = value.join(','); 255 } 256 } else { 257 rowValues[field] = jQuery('[name="'+field+'"]', rowElement).val(); 258 } 259 } 260 261 } else { 262 for(var key in fieldList) { 263 var field = fieldList[key]; 264 if(field == 'value'){ 265 rowValues[field] = valueSelectElement.val(); 266 } else { 267 rowValues[field] = jQuery('[name="'+field+'"]', rowElement).val(); 268 } 269 } 270 } 271 if(jQuery('[name="valuetype"]', rowElement).val() == 'false' || (jQuery('[name="valuetype"]', rowElement).length == 0)) { 272 rowValues['valuetype'] = 'rawtext'; 273 } 274 275 values.push(rowValues); 276 }); 277 return values; 278 }, 279 280 getTaskList : function() { 281 var container = this.getContainer(); 282 var params = { 283 module : app.getModuleName(), 284 parent : app.getParentModuleName(), 285 view : 'TasksList', 286 record : jQuery('[name="record"]',container).val() 287 } 288 var progressIndicatorElement = jQuery.progressIndicator({ 289 'position' : 'html', 290 'blockInfo' : { 291 'enabled' : true 292 } 293 }); 294 AppConnector.request(params).then(function(data){ 295 jQuery('#taskListContainer').html(data); 296 progressIndicatorElement.progressIndicator({mode : 'hide'}); 297 }); 298 }, 299 300 /** 301 * Function to get ckEditorInstance 302 */ 303 getckEditorInstance : function(){ 304 if(this.ckEditorInstance == false){ 305 this.ckEditorInstance = new Vtiger_CkEditor_Js(); 306 } 307 return this.ckEditorInstance; 308 }, 309 310 registerTaskStatusChangeEvent : function() { 311 var container = this.getContainer(); 312 container.on('change','.taskStatus',function(e) { 313 var currentStatusElement = jQuery(e.currentTarget); 314 var url = currentStatusElement.data('statusurl'); 315 if(currentStatusElement.is(':checked')){ 316 url = url+'&status=true'; 317 } else { 318 url = url+'&status=false'; 319 } 320 var progressIndicatorElement = jQuery.progressIndicator({ 321 'position' : 'html', 322 'blockInfo' : { 323 'enabled' : true 324 } 325 }); 326 AppConnector.request(url).then(function(data) { 327 if(data.result == "ok") { 328 var params = { 329 title : app.vtranslate('JS_MESSAGE'), 330 text: app.vtranslate('JS_STATUS_CHANGED_SUCCESSFULLY'), 331 animation: 'show', 332 type: 'success' 333 }; 334 Vtiger_Helper_Js.showPnotify(params); 335 } 336 progressIndicatorElement.progressIndicator({mode : 'hide'}); 337 }); 338 e.stopImmediatePropagation(); 339 }); 340 }, 341 342 registerTaskDeleteEvent : function() { 343 var thisInstance = this; 344 var container = this.getContainer(); 345 container.on('click','.deleteTask',function(e) { 346 var message = app.vtranslate('LBL_DELETE_CONFIRMATION'); 347 Vtiger_Helper_Js.showConfirmationBox({ 348 'message' : message 349 }).then( 350 function() { 351 var currentElement = jQuery(e.currentTarget); 352 var deleteUrl = currentElement.data('deleteurl'); 353 AppConnector.request(deleteUrl).then(function(data){ 354 if(data.result == 'ok'){ 355 thisInstance.getTaskList(); 356 var params = { 357 title : app.vtranslate('JS_MESSAGE'), 358 text: app.vtranslate('JS_TASK_DELETED_SUCCESSFULLY'), 359 animation: 'show', 360 type: 'success' 361 }; 362 Vtiger_Helper_Js.showPnotify(params); 363 } 364 }); 365 }); 366 }); 367 }, 368 369 registerFillTaskFromEmailFieldEvent: function() { 370 jQuery('#saveTask').on('change','#fromEmailOption',function(e) { 371 var currentElement = jQuery(e.currentTarget); 372 var inputElement = currentElement.closest('.row-fluid').find('.fields'); 373 inputElement.val(currentElement.val()); 374 }) 375 }, 376 377 registerFillTaskFieldsEvent: function() { 378 jQuery('#saveTask').on('change','.task-fields',function(e) { 379 var currentElement = jQuery(e.currentTarget); 380 var inputElement = currentElement.closest('.row-fluid').find('.fields'); 381 var oldValue = inputElement.val(); 382 var newValue = oldValue+currentElement.val(); 383 inputElement.val(newValue); 384 }) 385 }, 386 387 registerFillMailContentEvent : function() { 388 jQuery('#task-fieldnames,#task_timefields,#task-templates').change(function(e){ 389 var textarea = CKEDITOR.instances.content; 390 var value = jQuery(e.currentTarget).val(); 391 if(textarea != undefined) { 392 textarea.insertHtml(value); 393 } else if(jQuery('textarea[name="content"]')) { 394 var textArea = jQuery('textarea[name="content"]'); 395 textArea.insertAtCaret(value); 396 } 397 }); 398 }, 399 400 registerVTEmailTaskEvents : function() { 401 var textAreaElement = jQuery('#content'); 402 var ckEditorInstance = this.getckEditorInstance(); 403 ckEditorInstance.loadCkEditor(textAreaElement); 404 this.registerFillMailContentEvent(); 405 this.registerFillTaskFromEmailFieldEvent(); 406 this.registerCcAndBccEvents(); 407 }, 408 409 registerVTCreateTodoTaskEvents : function() { 410 app.registerEventForTimeFields(jQuery('#saveTask')); 411 }, 412 413 registerVTUpdateFieldsTaskEvents : function() { 414 var thisInstance = this; 415 this.registerAddFieldEvent(); 416 this.registerDeleteConditionEvent(); 417 this.registerFieldChange(); 418 this.fieldValueMap = false; 419 if(jQuery('#fieldValueMapping').val() != ''){ 420 this.fieldValueReMapping(); 421 } 422 var fields = jQuery('#save_fieldvaluemapping').find('select[name="fieldname"]'); 423 jQuery.each(fields,function(i,field){ 424 thisInstance.loadFieldSpecificUi(jQuery(field)); 425 }); 426 this.getPopUp(jQuery('#saveTask')); 427 }, 428 429 registerAddFieldEvent : function() { 430 jQuery('#addFieldBtn').on('click',function(e) { 431 var newAddFieldContainer = jQuery('.basicAddFieldContainer').clone(true,true).removeClass('basicAddFieldContainer hide').addClass('conditionRow'); 432 jQuery('select',newAddFieldContainer).addClass('select2'); 433 jQuery('#save_fieldvaluemapping').append(newAddFieldContainer); 434 //change in to chosen elements 435 app.changeSelectElementView(newAddFieldContainer); 436 app.showSelect2ElementView(newAddFieldContainer.find('.select2')); 437 }); 438 }, 439 440 registerDeleteConditionEvent : function() { 441 jQuery('#saveTask').on('click','.deleteCondition',function(e) { 442 jQuery(e.currentTarget).closest('.conditionRow').remove(); 443 }) 444 }, 445 446 /** 447 * Function which will register field change event 448 */ 449 registerFieldChange : function() { 450 var thisInstance = this; 451 jQuery('#saveTask').on('change','select[name="fieldname"]',function(e){ 452 var selectedElement = jQuery(e.currentTarget); 453 if(selectedElement.val() != 'none'){ 454 var conditionRow = selectedElement.closest('.conditionRow'); 455 var moduleNameElement = conditionRow.find('[name="modulename"]'); 456 if(moduleNameElement.length > 0){ 457 var selectedOptionFieldInfo = selectedElement.find('option:selected').data('fieldinfo'); 458 var type = selectedOptionFieldInfo.type; 459 if(type == 'picklist' || type == 'multipicklist'){ 460 var moduleName = jQuery('#createEntityModule').val(); 461 moduleNameElement.find('option[value="'+moduleName+'"]').attr('selected', true); 462 moduleNameElement.trigger('change'); 463 moduleNameElement.select2("disable"); 464 } 465 } 466 thisInstance.loadFieldSpecificUi(selectedElement); 467 } 468 }); 469 }, 470 471 getModuleName : function() { 472 return app.getModuleName(); 473 }, 474 475 getFieldValueMapping : function() { 476 var fieldValueMap = this.fieldValueMap; 477 if(fieldValueMap != false){ 478 return fieldValueMap; 479 } else { 480 return ''; 481 } 482 }, 483 484 fieldValueReMapping : function() { 485 var object = JSON.parse(jQuery('#fieldValueMapping').val()); 486 var fieldValueReMap = {}; 487 488 jQuery.each(object,function (i,array) { 489 fieldValueReMap[array.fieldname] = {}; 490 var values = {} 491 jQuery.each(array, function (key , value) { 492 values[key] = value; 493 }); 494 fieldValueReMap[array.fieldname] = values 495 }); 496 this.fieldValueMap = fieldValueReMap; 497 }, 498 499 loadFieldSpecificUi : function(fieldSelect) { 500 var selectedOption = fieldSelect.find('option:selected'); 501 var row = fieldSelect.closest('div.conditionRow'); 502 var fieldUiHolder = row.find('.fieldUiHolder'); 503 var fieldInfo = selectedOption.data('fieldinfo'); 504 var fieldValueMapping = this.getFieldValueMapping(); 505 if(fieldValueMapping != '' && typeof fieldValueMapping[fieldInfo.name] != 'undefined'){ 506 fieldInfo.value = fieldValueMapping[fieldInfo.name]['value']; 507 fieldInfo.workflow_valuetype = fieldValueMapping[fieldInfo.name]['valuetype']; 508 } else { 509 fieldInfo.workflow_valuetype = 'rawtext'; 510 } 511 512 var moduleName = this.getModuleName(); 513 514 var fieldModel = Vtiger_Field_Js.getInstance(fieldInfo,moduleName); 515 this.fieldModelInstance = fieldModel; 516 var fieldSpecificUi = this.getFieldSpecificUi(fieldSelect); 517 518 //remove validation since we dont need validations for all eleements 519 // Both filter and find is used since we dont know whether the element is enclosed in some conainer like currency 520 var fieldName = fieldModel.getName(); 521 if(fieldModel.getType() == 'multipicklist'){ 522 fieldName = fieldName+"[]"; 523 } 524 fieldSpecificUi.filter('[name="'+ fieldName +'"]').attr('data-value', 'value').addClass('row-fluid'); 525 fieldSpecificUi.find('[name="'+ fieldName +'"]').attr('data-value','value').addClass('row-fluid'); 526 fieldSpecificUi.filter('[name="valuetype"]').removeAttr('data-validation-engine'); 527 fieldSpecificUi.find('[name="valuetype"]').removeAttr('data-validation-engine'); 528 529 //If the workflowValueType is rawtext then only validation should happen 530 var workflowValueType = fieldSpecificUi.filter('[name="valuetype"]').val(); 531 if(workflowValueType != 'rawtext' && typeof workflowValueType != 'undefined') { 532 fieldSpecificUi.filter('[name="'+ fieldName +'"]').removeAttr('data-validation-engine'); 533 fieldSpecificUi.find('[name="'+ fieldName +'"]').removeAttr('data-validation-engine'); 534 } 535 536 fieldUiHolder.html(fieldSpecificUi); 537 538 if(fieldSpecificUi.is('input.select2')){ 539 var tagElements = fieldSpecificUi.data('tags'); 540 var params = {tags : tagElements,tokenSeparators: [","]} 541 app.showSelect2ElementView(fieldSpecificUi,params) 542 } else if(fieldSpecificUi.is('select')){ 543 if(fieldSpecificUi.hasClass('chzn-select')) { 544 app.changeSelectElementView(fieldSpecificUi) 545 }else{ 546 app.showSelect2ElementView(fieldSpecificUi); 547 } 548 } else if (fieldSpecificUi.is('input.dateField')){ 549 var calendarType = fieldSpecificUi.data('calendarType'); 550 if(calendarType == 'range'){ 551 var customParams = { 552 calendars: 3, 553 mode: 'range', 554 className : 'rangeCalendar', 555 onChange: function(formated) { 556 fieldSpecificUi.val(formated.join(',')); 557 } 558 } 559 app.registerEventForDatePickerFields(fieldSpecificUi,false,customParams); 560 }else{ 561 app.registerEventForDatePickerFields(fieldSpecificUi); 562 } 563 } 564 return this; 565 }, 566 567 /** 568 * Functiont to get the field specific ui for the selected field 569 * @prarms : fieldSelectElement - select element which will represents field list 570 * @return : jquery object which represents the ui for the field 571 */ 572 getFieldSpecificUi : function(fieldSelectElement) { 573 var fieldModel = this.fieldModelInstance; 574 return jQuery(fieldModel.getUiTypeSpecificHtml()) 575 }, 576 577 578 registerVTCreateEventTaskEvents : function() { 579 app.registerEventForTimeFields(jQuery('#saveTask')); 580 this.registerRecurrenceFieldCheckBox(); 581 this.repeatMonthOptionsChangeHandling(); 582 this.registerRecurringTypeChangeEvent(); 583 this.registerRepeatMonthActions(); 584 }, 585 586 registerVTCreateEntityTaskEvents : function() { 587 this.registerChangeCreateEntityEvent(); 588 this.registerVTUpdateFieldsTaskEvents(); 589 }, 590 591 registerChangeCreateEntityEvent : function() { 592 var thisInstance = this; 593 jQuery('#createEntityModule').on('change',function(e) { 594 var params = { 595 module : app.getModuleName(), 596 parent : app.getParentModuleName(), 597 view : 'CreateEntity', 598 relatedModule : jQuery(e.currentTarget).val(), 599 for_workflow : jQuery('[name="for_workflow"]').val() 600 } 601 AppConnector.request(params).then(function(data) { 602 var createEntityContainer = jQuery('#addCreateEntityContainer'); 603 createEntityContainer.html(data); 604 app.changeSelectElementView(createEntityContainer); 605 app.showSelect2ElementView(createEntityContainer.find('.select2')); 606 thisInstance.registerAddFieldEvent(); 607 thisInstance.fieldValueMap = false; 608 if(jQuery('#fieldValueMapping').val() != ''){ 609 this.fieldValueReMapping(); 610 } 611 var fields = jQuery('#save_fieldvaluemapping').find('select[name="fieldname"]'); 612 jQuery.each(fields,function(i,field){ 613 thisInstance.loadFieldSpecificUi(jQuery(field)); 614 }); 615 }); 616 }); 617 }, 618 619 /** 620 * Function which will register change event on recurrence field checkbox 621 */ 622 registerRecurrenceFieldCheckBox : function() { 623 var thisInstance = this; 624 jQuery('#saveTask').find('input[name="recurringcheck"]').on('change', function(e) { 625 var element = jQuery(e.currentTarget); 626 var repeatUI = jQuery('#repeatUI'); 627 if(element.is(':checked')) { 628 repeatUI.show(); 629 } else { 630 repeatUI.hide(); 631 } 632 }); 633 }, 634 635 /** 636 * Function which will register the change event for recurring type 637 */ 638 registerRecurringTypeChangeEvent : function() { 639 var thisInstance = this; 640 jQuery('#recurringType').on('change', function(e) { 641 var currentTarget = jQuery(e.currentTarget); 642 var recurringType = currentTarget.val(); 643 thisInstance.changeRecurringTypesUIStyles(recurringType); 644 645 }); 646 }, 647 648 /** 649 * Function which will register the change event for repeatMonth radio buttons 650 */ 651 registerRepeatMonthActions : function() { 652 var thisInstance = this; 653 jQuery('#saveTask').find('input[name="repeatMonth"]').on('change', function(e) { 654 //If repeatDay radio button is checked then only select2 elements will be enable 655 thisInstance.repeatMonthOptionsChangeHandling(); 656 }); 657 }, 658 659 660 /** 661 * Function which will change the UI styles based on recurring type 662 * @params - recurringType - which recurringtype is selected 663 */ 664 changeRecurringTypesUIStyles : function(recurringType) { 665 var thisInstance = this; 666 if(recurringType == 'Daily' || recurringType == 'Yearly') { 667 jQuery('#repeatWeekUI').removeClass('show').addClass('hide'); 668 jQuery('#repeatMonthUI').removeClass('show').addClass('hide'); 669 } else if(recurringType == 'Weekly') { 670 jQuery('#repeatWeekUI').removeClass('hide').addClass('show'); 671 jQuery('#repeatMonthUI').removeClass('show').addClass('hide'); 672 } else if(recurringType == 'Monthly') { 673 jQuery('#repeatWeekUI').removeClass('show').addClass('hide'); 674 jQuery('#repeatMonthUI').removeClass('hide').addClass('show'); 675 } 676 }, 677 678 /** 679 * This function will handle the change event for RepeatMonthOptions 680 */ 681 repeatMonthOptionsChangeHandling : function() { 682 //If repeatDay radio button is checked then only select2 elements will be enable 683 if(jQuery('#repeatDay').is(':checked')) { 684 jQuery('#repeatMonthDate').attr('disabled', true); 685 jQuery('#repeatMonthDayType').select2("enable"); 686 jQuery('#repeatMonthDay').select2("enable"); 687 } else { 688 jQuery('#repeatMonthDate').removeAttr('disabled'); 689 jQuery('#repeatMonthDayType').select2("disable"); 690 jQuery('#repeatMonthDay').select2("disable"); 691 } 692 }, 693 694 checkHiddenStatusofCcandBcc : function(){ 695 var ccLink = jQuery('#ccLink'); 696 var bccLink = jQuery('#bccLink'); 697 if(ccLink.is(':hidden') && bccLink.is(':hidden')){ 698 ccLink.closest('div.row-fluid').addClass('hide'); 699 } 700 }, 701 702 /* 703 * Function to register the events for bcc and cc links 704 */ 705 registerCcAndBccEvents : function(){ 706 var thisInstance = this; 707 jQuery('#ccLink').on('click',function(e){ 708 var ccContainer = jQuery('#ccContainer'); 709 ccContainer.show(); 710 var taskFieldElement = ccContainer.find('select.task-fields'); 711 taskFieldElement.addClass('chzn-select'); 712 app.changeSelectElementView(taskFieldElement); 713 jQuery(e.currentTarget).hide(); 714 thisInstance.checkHiddenStatusofCcandBcc(); 715 }); 716 jQuery('#bccLink').on('click',function(e){ 717 var bccContainer = jQuery('#bccContainer'); 718 bccContainer.show(); 719 var taskFieldElement = bccContainer.find('select.task-fields'); 720 taskFieldElement.addClass('chzn-select'); 721 app.changeSelectElementView(taskFieldElement); 722 jQuery(e.currentTarget).hide(); 723 thisInstance.checkHiddenStatusofCcandBcc(); 724 }); 725 }, 726 727 registerEvents : function(){ 728 var container = this.getContainer(); 729 app.changeSelectElementView(container); 730 this.registerEditTaskEvent(); 731 this.registerTaskStatusChangeEvent(); 732 this.registerTaskDeleteEvent(); 733 } 734 }); 735 736 //http://stackoverflow.com/questions/946534/insert-text-into-textarea-with-jquery 737 jQuery.fn.extend({ 738 insertAtCaret: function(myValue) { 739 return this.each(function(i) { 740 if (document.selection) { 741 //For browsers like Internet Explorer 742 this.focus(); 743 var sel = document.selection.createRange(); 744 sel.text = myValue; 745 this.focus(); 746 } else if (this.selectionStart || this.selectionStart == '0') { 747 //For browsers like Firefox and Webkit based 748 var startPos = this.selectionStart; 749 var endPos = this.selectionEnd; 750 var scrollTop = this.scrollTop; 751 this.value = this.value.substring(0, startPos)+myValue+this.value.substring(endPos,this.value.length); 752 this.focus(); 753 this.selectionStart = startPos + myValue.length; 754 this.selectionEnd = startPos + myValue.length; 755 this.scrollTop = scrollTop; 756 } else { 757 this.value += myValue; 758 this.focus(); 759 } 760 }); 761 } 762 });
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 |