[ 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 10 Vtiger_BasicSearch_Js("Vtiger_AdvanceSearch_Js",{ 11 12 //cache will store the search data 13 cache : {} 14 15 },{ 16 //container which will store the search elements 17 elementContainer : false, 18 //instance which represents advance filter 19 advanceFilter : false, 20 21 //states whether the validation is registred for filter elements 22 filterValidationRegistered : false, 23 24 //contains the filter form element 25 filterForm : false, 26 27 /** 28 * Function which will give the container 29 */ 30 getContainer : function() { 31 return this.elementContainer; 32 }, 33 34 /** 35 *Function which is used to set the continaer 36 *@params : container - element which represent the container 37 *@return current instance 38 */ 39 setContainer : function(container) { 40 this.elementContainer = container; 41 return this; 42 }, 43 44 getFilterForm : function() { 45 return jQuery('form[name="advanceFilterForm"]',this.getContainer()); 46 }, 47 48 /** 49 * Function used to get the advance search ui 50 * @return : deferred promise 51 */ 52 getAdvanceSearch : function() { 53 var aDeferred = jQuery.Deferred(); 54 var moduleName = app.getModuleName(); 55 var searchModule = this.getSearchModule(); 56 57 //Exists in the cache 58 if(searchModule in Vtiger_AdvanceSearch_Js.cache) { 59 aDeferred.resolve(Vtiger_AdvanceSearch_Js.cache[searchModule]); 60 return aDeferred.promise(); 61 } 62 63 //if you are in settings then module should be vtiger 64 if(app.getParentModuleName().length > 0) { 65 moduleName = 'Vtiger'; 66 } 67 68 var searchableModulesParams = { 69 "module":moduleName, 70 "view" : "BasicAjax", 71 "mode" : "showAdvancedSearch", 72 "source_module": searchModule 73 }; 74 75 var progressInstance = jQuery.progressIndicator(); 76 AppConnector.request(searchableModulesParams).then( 77 function(data){ 78 progressInstance.hide(); 79 //add to cache 80 Vtiger_AdvanceSearch_Js.cache[searchModule] = data; 81 aDeferred.resolve(data); 82 }, 83 function(error,err){ 84 aDeferred.reject(error); 85 } 86 ); 87 return aDeferred.promise(); 88 }, 89 90 91 /** 92 * Function which intializes search 93 */ 94 initiateSearch : function() { 95 var aDeferred = jQuery.Deferred(); 96 var thisInstance = this; 97 var postLoad = function(uiData) { 98 thisInstance.setContainer(jQuery('#advanceSearchContainer')); 99 thisInstance.registerEvents(); 100 thisInstance.advanceFilter = new Vtiger_SearchAdvanceFilter_Js(jQuery('.filterContainer',uiData)); 101 //align it below the search element 102 uiData.closest('.blockMsg').position({ 103 my: "right top", 104 at: "right bottom", 105 of: ".searchElement", 106 using: function(){ 107 jQuery("#globalmodal").css({ 'margin-left': '-65px', 'margin-top':'30px'}); 108 } 109 }); 110 if (jQuery('#searchContainer').height() > 200) { 111 app.showScrollBar( jQuery('#searchContainer'), {'height':'400px','railVisible':'true'}); 112 } 113 aDeferred.resolve(); 114 } 115 116 this.getAdvanceSearch().then( 117 function(data){ 118 var params = {}; 119 params.data = data ; 120 params.cb = postLoad; 121 //TODO : put this css as attribute of object so that its easy for maintanace 122 params.css = {'width':'50%','text-align':'left','background-color':'transparent','border-width':'0px'}; 123 //not showing overlay 124 params.overlayCss = {'opacity':'0.2'}; 125 126 app.showModalWindow(params); 127 }, 128 function(error) { 129 aDeferred.reject(); 130 } 131 ) 132 return aDeferred.promise(); 133 }, 134 135 getNameFields : function() { 136 var form = this.getFilterForm(); 137 return form.find('[name="labelFields"]').data('value'); 138 }, 139 140 selectBasicSearchValue : function() { 141 var value = jQuery('#globalSearchValue').val(); 142 if(value.length > 0 ) { 143 var form = this.getFilterForm(); 144 var labelFieldList = this.getNameFields(); 145 if(typeof labelFieldList == 'undefined' || labelFieldList.length == 0) { 146 return; 147 } 148 var anyConditionContainer = form.find('.anyConditionContainer'); 149 for(var index in labelFieldList){ 150 var labelFieldName = labelFieldList[index]; 151 if(index !=0 ) { 152 //By default one condition exits , only if you have multiple label fields you have add one more condition 153 anyConditionContainer.find('.addCondition').find('button').trigger('click'); 154 } 155 var conditionRow = anyConditionContainer.find('.conditionList').find('.conditionRow:last'); 156 var fieldSelectElemnt = conditionRow.find('select[name="columnname"]'); 157 fieldSelectElemnt.find('option[data-field-name="'+ labelFieldName +'"]').attr('selected','selected'); 158 fieldSelectElemnt.trigger('change').trigger('liszt:updated'); 159 160 var comparatorSelectElemnt = conditionRow.find('select[name="comparator"]'); 161 //select the contains value 162 comparatorSelectElemnt.find('option[value="c"]').attr('selected','selected'); 163 comparatorSelectElemnt.trigger('liszt:updated'); 164 165 var valueElement = conditionRow.find('[name="value"]'); 166 valueElement.val(value); 167 } 168 169 } 170 }, 171 172 /** 173 * Function which invokes search 174 */ 175 search : function() { 176 var conditionValues = this.advanceFilter.getValues(); 177 var module = this.getSearchModule(); 178 179 var params = {}; 180 params.module = module; 181 params.advfilterlist = JSON.stringify(conditionValues); 182 183 return this._search(params); 184 }, 185 186 /** 187 * Function which shows search results in proper manner 188 * @params : data to be shown 189 */ 190 showSearchResults : function(data){ 191 var thisInstance = this; 192 var aDeferred = jQuery.Deferred(); 193 var postLoad = function(data) { 194 var blockMsg = jQuery(data).closest('.blockMsg'); 195 app.showScrollBar(jQuery(data).find('.contents')); 196 aDeferred.resolve(data); 197 } 198 199 var unblockcd = function(){ 200 thisInstance.getContainer().remove(); 201 } 202 203 var html = '<div class="row-fluid">'+ 204 '<span class="span4 searchHolder"></span>'+ 205 '<span class="span8 filterHolder marginLeftZero hide"></span>'+ 206 '</div>'; 207 var jQhtml = jQuery(html); 208 jQuery('.searchHolder',jQhtml).html(data); 209 210 data = jQhtml; 211 212 var params = {}; 213 params.data = data; 214 params.cb = postLoad; 215 params.css = {'width':'20%','text-align':'left','margin-left':'-100px'}; 216 params.overlayCss = {'opacity':'0.2'}; 217 params.unblockcb = unblockcd; 218 app.showModalWindow(params); 219 220 return aDeferred.promise(); 221 }, 222 223 /** 224 * Function which will save the filter 225 */ 226 saveFilter : function(params) { 227 var aDeferred = jQuery.Deferred(); 228 params.source_module = this.getSearchModule(); 229 params.status = 1; 230 params.advfilterlist = JSON.stringify(this.advanceFilter.getValues(false)); 231 232 params.module = 'CustomView'; 233 params.action = 'Save'; 234 235 AppConnector.request(params).then(function(data){ 236 if(!data.success) { 237 var params = { 238 title : app.vtranslate('JS_MESSAGE'), 239 text: data.error.message, 240 animation: 'show', 241 type: 'error' 242 }; 243 Vtiger_Helper_Js.showPnotify(params); 244 } 245 aDeferred.resolve(data); 246 }) 247 return aDeferred.promise(); 248 }, 249 250 /** 251 * Function which will save the filter and show the list view of new custom view 252 */ 253 saveAndViewFilter : function(params){ 254 this.saveFilter(params).then( 255 function(response){ 256 var url = response['result']['listviewurl']; 257 window.location.href=url; 258 }, 259 function(error) { 260 261 } 262 ); 263 }, 264 265 /** 266 * Function which specify whether the search component and filter component both are shown 267 */ 268 isSearchAndFilterComponentsShown : function() { 269 var modalData = jQuery('#globalmodal'); 270 var filterComponent = jQuery('.filterHolder',modalData).find('#advanceSearchContainer'); 271 if(filterComponent.length <= 0 ) { 272 return false; 273 } 274 return true; 275 }, 276 277 /** 278 * Function which will perform search and other operaions 279 */ 280 performSearch : function() { 281 var thisInstance = this; 282 var isSearchResultsAndFilterShown = this.isSearchAndFilterComponentsShown(); 283 this.search().then(function(data){ 284 thisInstance.setContainer(thisInstance.getContainer().detach()); 285 thisInstance.showSearchResults(data).then(function(modalBlock){ 286 var msgContainer = modalBlock.closest('.blockMsg'); 287 msgContainer.position({ 288 my: "left bottom", 289 at: "left bottom", 290 of: "#globalSearchValue", 291 offset: "1 -29" 292 }); 293 thisInstance.registerShowFiler(); 294 //if the filter already shown , show again 295 if(isSearchResultsAndFilterShown) { 296 thisInstance.showFilter(); 297 } 298 }); 299 300 }); 301 }, 302 303 /** 304 * Function which will show the advance filter next to search results 305 */ 306 showFilter : function(){ 307 var modalData = jQuery('#globalmodal'); 308 var searchHolder = jQuery('.searchHolder', modalData); 309 var filterHolder = jQuery('.filterHolder', modalData); 310 filterHolder.removeClass('hide').html(this.getContainer()); 311 //searchHolder.removeClass('span12').css('width' , '35%');; 312 modalData.closest('.blockMsg').css('width' , '70%'); 313 }, 314 315 /** 316 * Function which will perform the validation for the advance filter fields 317 * @return : deferred promise - resolves if validation succeded if not failure 318 */ 319 performValidation : function() { 320 var thisInstance = this; 321 this.formValidationDeferred = jQuery.Deferred(); 322 var controlForm = this.getFilterForm(); 323 324 var validationDone = function(form, status){ 325 if(status) { 326 thisInstance.formValidationDeferred.resolve(); 327 }else{ 328 thisInstance.formValidationDeferred.reject(); 329 } 330 } 331 //To perform validation registration only once 332 if(!this.filterValidationRegistered){ 333 this.filterValidationRegistered = true; 334 controlForm.validationEngine({ 335 'onValidationComplete' : validationDone 336 }); 337 } 338 //This will trigger the validation 339 controlForm.submit(); 340 return this.formValidationDeferred.promise(); 341 }, 342 343 /** 344 * Function which will register the show filer invocation 345 */ 346 registerShowFiler : function() { 347 var thisInstance = this; 348 jQuery('#showFilter').on('click',function(e){ 349 thisInstance.showFilter(); 350 }); 351 }, 352 353 /** 354 * Function which will register events 355 */ 356 registerEvents : function() { 357 var thisInstance = this; 358 var container = this.getContainer(); 359 360 container.on('change','#searchModuleList', function(e){ 361 var selectElement = jQuery(e.currentTarget); 362 var selectedModuleName = selectElement.val(); 363 364 thisInstance.setSearchModule(selectedModuleName); 365 366 thisInstance.initiateSearch().then(function(){ 367 thisInstance.selectBasicSearchValue(); 368 }); 369 }); 370 371 jQuery('#advanceSearchButton').on('click', function(e){ 372 var searchModule = thisInstance.getSearchModule(); 373 //If no module is selected 374 if(searchModule.length <= 0) { 375 app.getChosenElementFromSelect(jQuery('#searchModuleList')) 376 .validationEngine('showPrompt', app.vtranslate('JS_SELECT_MODULE'), 'error','topRight',true) 377 return; 378 } 379 thisInstance.performValidation().then( 380 function(){ 381 thisInstance.performSearch(); 382 }, 383 function(){ 384 385 } 386 ); 387 }); 388 389 jQuery('#advanceIntiateSave').on('click', function(e){ 390 var currentElement = jQuery(e.currentTarget); 391 currentElement.addClass('hide'); 392 var actionsContainer = currentElement.closest('.actions'); 393 jQuery('input[name="viewname"]',actionsContainer).removeClass('zeroOpacity').focus(); 394 jQuery('#advanceSave').removeClass('hide'); 395 }); 396 397 jQuery('#advanceSave').on('click',function(e){ 398 var actionsContainer = jQuery(e.currentTarget).closest('.actions'); 399 var filterNameField = jQuery('input[name="viewname"]',actionsContainer); 400 var value = filterNameField.val(); 401 if(value.length <= 0) { 402 filterNameField.validationEngine('showPrompt', app.vtranslate('JS_REQUIRED_FIELD'), 'error','topRight',true); 403 return; 404 } 405 406 var searchModule = thisInstance.getSearchModule(); 407 //If no module is selected 408 if(searchModule.length <= 0) { 409 app.getChosenElementFromSelect(jQuery('#searchModuleList')) 410 .validationEngine('showPrompt', app.vtranslate('JS_SELECT_MODULE'), 'error','topRight',true) 411 return; 412 } 413 414 thisInstance.performValidation().then(function(){ 415 var params = {}; 416 params.viewname = value; 417 thisInstance.saveAndViewFilter(params); 418 }); 419 }); 420 421 //DO nothing on submit of filter form 422 this.getFilterForm().on('submit',function(e){ 423 e.preventDefault(); 424 }) 425 426 //To set the search module with the currently selected values. 427 this.setSearchModule(jQuery('#searchModuleList').val()); 428 } 429 })
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 |