root/vtigercrm/branches/5.2.0/include/js/ListView.js

Revision 13038, 17.4 kB (checked in by musavir, 6 months ago)

RelatedList? Rewrite - MAK
=========================

1. enabled ajax in more information page.

  • Property svn:mime-type set to text/plain
Line 
1 /*********************************************************************************
2
3 ** The contents of this file are subject to the vtiger CRM Public License Version 1.0
4  * ("License"); You may not use this file except in compliance with the License
5  * The Original Code is:  vtiger CRM Open Source
6  * The Initial Developer of the Original Code is vtiger.
7  * Portions created by vtiger are Copyright (C) vtiger.
8  * All Rights Reserved.
9  ********************************************************************************/
10
11 // MassEdit Feature
12 function massedit_togglediv(curTabId,total){
13
14    for(var i=0;i<total;i++){
15         tagName = $('massedit_div'+i);
16         tagName1 = $('tab'+i)
17         tagName.style.display = 'none';
18         tagName1.className = 'dvtUnSelectedCell';
19    }
20
21    tagName = $('massedit_div'+curTabId);
22    tagName.style.display = 'block';
23    tagName1 = $('tab'+curTabId)
24    tagName1.className = 'dvtSelectedCell';
25 }
26
27 function massedit_initOnChangeHandlers() {
28         var form = document.getElementById('massedit_form');
29         // Setup change handlers for input boxes
30         var inputs = form.getElementsByTagName('input');
31         for(var index = 0; index < inputs.length; ++index) {
32                 var massedit_input = inputs[index];
33                 // TODO Onchange on readonly and hidden fields are to be handled later.
34                 massedit_input.onchange = function() {
35                         var checkbox = document.getElementById(this.name + '_mass_edit_check');
36                         if(checkbox) checkbox.checked = true;
37                 }
38         }
39         // Setup change handlers for select boxes
40         var selects = form.getElementsByTagName('select');
41         for(var index = 0; index < selects.length; ++index) {
42                 var massedit_select = selects[index];
43                 massedit_select.onchange = function() {
44                         var checkbox = document.getElementById(this.name + '_mass_edit_check');
45                         if(checkbox) checkbox.checked = true;
46                 }
47         }
48 }
49
50 function mass_edit(obj,divid,module,parenttab) {
51         var select_options = document.getElementById('allselectedboxes').value;
52         var x = select_options.split(';');
53         var count = x.length;
54        
55         if(count > 1) {
56                 idstring=select_options;
57                 mass_edit_formload(idstring,module,parenttab);
58         } else {
59                 alert(alert_arr.SELECT);
60                 return false;
61         }
62         fnvshobj(obj, divid);
63 }
64 function mass_edit_formload(idstring,module,parenttab) {
65         if(typeof(parenttab) == 'undefined') parenttab = '';
66         $("status").style.display="inline";
67         new Ajax.Request(
68                 'index.php',
69                 {queue: {position: 'end', scope: 'command'},
70                 method: 'post',
71                         postBody:"module="+encodeURIComponent(module)+"&action="+encodeURIComponent(module+'Ajax')+"&parenttab="+encodeURIComponent(parenttab)+"&file=MassEdit&mode=ajax&idstring="+idstring,
72                                 onComplete: function(response) {
73                         $("status").style.display="none";
74                     var result = response.responseText;
75                     $("massedit_form_div").innerHTML= result;
76                                         $("massedit_form")["massedit_recordids"].value = idstring;
77                                         $("massedit_form")["massedit_module"].value = module;
78                                        
79                                         var jscripts = $('massedit_javascript');
80                                         if(jscripts) {
81                                                 eval(jscripts.innerHTML);
82                                                 // Updating global variables
83                                                 fieldname = mass_fieldname;
84                                                 for(var i=0;i<fieldname.length;i++){
85                                                         calendar_jscript = $('massedit_calendar_'+fieldname[i]);                       
86                                                         if(calendar_jscript){
87                                                                 eval(calendar_jscript.innerHTML);
88                                                         }
89                                                 }
90                                                 fieldlabel = mass_fieldlabel;
91                                                 fielddatatype = mass_fielddatatype;
92                                                 count = mass_count;
93                                         }
94                                 }
95                 }
96         );
97 }
98 function mass_edit_fieldchange(selectBox) {
99         var oldSelectedIndex = selectBox.oldSelectedIndex;
100         var selectedIndex = selectBox.selectedIndex;
101
102         if($('massedit_field'+oldSelectedIndex)) $('massedit_field'+oldSelectedIndex).style.display='none';
103         if($('massedit_field'+selectedIndex)) $('massedit_field'+selectedIndex).style.display='block';
104
105         selectBox.oldSelectedIndex = selectedIndex;
106 }
107
108 function mass_edit_save(){
109         var masseditform = $("massedit_form");
110         var module = masseditform["massedit_module"].value;
111         var viewid = document.getElementById("viewname").options[document.getElementById("viewname").options.selectedIndex].value;
112         var searchurl = document.getElementById("search_url").value;
113
114         var urlstring =
115                 "module="+encodeURIComponent(module)+"&action="+encodeURIComponent(module+'Ajax')+
116                 "&return_module="+encodeURIComponent(module)+"&return_action=ListView"+
117                 "&mode=ajax&file=MassEditSave&viewname=" + viewid ;//+"&"+ searchurl;
118
119         fninvsh("massedit");
120
121         new Ajax.Request(
122                 "index.php",
123                 {queue:{position:"end", scope:"command"},
124                         method:"post",
125                         postBody:urlstring,
126                         onComplete:function (response) {
127                                 $("status").style.display = "none";
128                                 var result = response.responseText.split("&#&#&#");
129                                 $("ListViewContents").innerHTML = result[2];
130                                 if (result[1] != "") {
131                                         alert(result[1]);
132                                 }
133                                 $("basicsearchcolumns").innerHTML = "";
134                         }
135                 }
136         );
137        
138 }
139 function ajax_mass_edit() {
140         alert();
141         $("status").style.display = "inline";
142
143         var masseditform = $("massedit_form");
144         var module = masseditform["massedit_module"].value;
145
146         var viewid = document.getElementById("viewname").options[document.getElementById("viewname").options.selectedIndex].value;
147         var idstring = masseditform["massedit_recordids"].value;
148         var searchurl = document.getElementById("search_url").value;
149         var tplstart = "&";
150         if (gstart != "") { tplstart = tplstart + gstart; }
151
152         var masseditfield = masseditform['massedit_field'].value;
153         var masseditvalue = masseditform['massedit_value_'+masseditfield].value;
154
155         var urlstring =
156                 "module="+encodeURIComponent(module)+"&action="+encodeURIComponent(module+'Ajax')+
157                 "&return_module="+encodeURIComponent(module)+
158                 "&mode=ajax&file=MassEditSave&viewname=" + viewid +
159                 "&massedit_field=" + encodeURIComponent(masseditfield) +
160                 "&massedit_value=" + encodeURIComponent(masseditvalue) +
161                 "&idlist=" + idstring + searchurl;
162
163         fninvsh("massedit");
164
165         new Ajax.Request(
166                 "index.php",
167                 {queue:{position:"end", scope:"command"},
168                         method:"post",
169                         postBody:urlstring,
170                         onComplete:function (response) {
171                                 $("status").style.display = "none";
172                                 var result = response.responseText.split("&#&#&#");
173                                 $("ListViewContents").innerHTML = result[2];
174                                 if (result[1] != "") {
175                                         alert(result[1]);
176                                 }
177                                 $("basicsearchcolumns").innerHTML = "";
178                         }
179                 }
180         );
181 }
182        
183 // END
184
185 function change(obj,divid)
186 {
187         var select_options  =  document.getElementById('allselectedboxes').value;
188         //Added to remove the semi colen ';' at the end of the string.done to avoid error.
189         var x = select_options.split(";");
190         var count=x.length;
191         var viewid =getviewId();
192         idstring = "";
193
194         if (count > 1)
195         {
196                 idstring=select_options;
197                 document.getElementById('idlist').value=idstring;
198         }
199         else
200         {
201                 alert(alert_arr.SELECT);
202                 return false;
203         }
204         fnvshobj(obj,divid);
205 }
206 function getviewId()
207 {
208         if(document.getElementById("viewname") != null &&
209                 typeof(document.getElementById("viewname")) != 'undefined') {
210                 var oViewname = document.getElementById("viewname");
211                 var viewid = oViewname.options[oViewname.selectedIndex].value;
212         }
213         else
214         {
215                 var viewid ='';         
216         }
217         return viewid; 
218 }
219 var gstart='';
220 function massDelete(module)
221 {
222         var select_options  =  document.getElementById('allselectedboxes').value;
223         var x = select_options.split(";");
224         var searchurl= document.getElementById('search_url').value;
225         var count=x.length
226         var viewid =getviewId();
227         var idstring = "";
228
229         if (count > 1)
230         {
231             //document.getElementById('idlist').value=idstring;
232             document.getElementById('idlist').value=select_options;
233             idstring = select_options;
234         }
235         else
236         {
237             alert(alert_arr.SELECT);
238             return false;
239         }
240         //we have to decrese the count value by 1 because when we split with semicolon we will get one extra count
241         count = count - 1;
242
243         var alert_str = alert_arr.DELETE + count +alert_arr.RECORDS;
244
245         if(module=="Accounts")
246                 alert_str = alert_arr.DELETE_ACCOUNT +count+alert_arr.RECORDS;
247         else if(module=="Vendors")
248                 alert_str = alert_arr.DELETE_VENDOR+count+alert_arr.RECORDS;
249
250         if(confirm(alert_str))
251         {
252                 $("status").style.display="inline";
253                 new Ajax.Request(
254                       'index.php',
255                         {queue: {position: 'end', scope: 'command'},
256                                 method: 'post',
257                                 postBody:"module=Users&action=massdelete&return_module="+module+"&"+gstart+"&viewname="+viewid+"&idlist="+idstring+searchurl,
258                                 onComplete: function(response) {
259                                         $("status").style.display="none";
260                                         result = response.responseText.split('&#&#&#');
261                                         $("ListViewContents").innerHTML= result[2];
262                                         if(result[1] != '')
263                                                 alert(result[1]);
264                                                                         $('basicsearchcolumns').innerHTML = '';
265                                 }
266                          }
267                 );
268         }
269         else
270         {
271                 return false;
272         }
273 }
274
275 function showDefaultCustomView(selectView,module,parenttab)
276 {
277         $("status").style.display="inline";
278         var viewName = encodeURIComponent(selectView.options[selectView.options.selectedIndex].value);
279         new Ajax.Request(
280                 'index.php',
281                 {queue: {position: 'end', scope: 'command'},
282                         method: 'post',
283                         postBody:"module="+module+"&action="+module+"Ajax&file=ListView&ajax=true&start=1&viewname="+viewName+"&parenttab="+parenttab,
284                         onComplete: function(response) {
285                         $("status").style.display="none";
286                         result = response.responseText.split('&#&#&#');
287                         $("ListViewContents").innerHTML= result[2];
288                         if(result[1] != '')
289                                 alert(result[1]);
290                         $('basicsearchcolumns_real').innerHTML = $('basicsearchcolumns').innerHTML
291                         $('basicsearchcolumns').innerHTML = '';
292                         document.basicSearch.search_text.value = '';
293                         }
294                 }
295         );
296 }
297
298
299 function getListViewEntries_js(module,url)
300 {
301         var select_options  =  document.getElementsByName('selected_id');
302         var x = select_options.length;
303         var viewid =getviewId();
304         idstring = "";
305
306         xx = 0;
307         for(i = 0; i < x ; i++)
308         {
309                 if(select_options[i].checked)
310                 {
311                         idstring = select_options[i].value +";"+idstring
312                         xx++
313                 }
314         }
315         var all_selected=document.getElementById('allselectedboxes').value;
316
317         $("status").style.display="inline";
318                 if(typeof $('search_url') != 'undefined' && $('search_url').value!='')
319                 urlstring = $('search_url').value;
320         else
321                 urlstring = '';
322
323         gstart = url;
324         new Ajax.Request(
325                 'index.php',
326                 {queue: {position: 'end', scope: 'command'},
327                         method: 'post',
328                         postBody:"module="+module+"&action="+module+"Ajax&file=ListView&ajax=true&allselobjs="+all_selected+"&selobjs="+idstring+"&"+url+urlstring,
329                         onComplete: function(response) {
330                                 $("status").style.display="none";
331                                 result = response.responseText.split('&#&#&#');
332                                 $("ListViewContents").innerHTML= result[2];
333                                 update_selected_checkbox();
334                                 if(result[1] != '')
335                                         alert(result[1]);
336                                 $('basicsearchcolumns').innerHTML = '';
337                         }
338                 }
339         );
340 }
341 //for multiselect check box in list view:
342
343 function check_object(sel_id,groupParentElementId)
344 {
345         var select_global=new Array();
346         var selected=trim(document.getElementById("allselectedboxes").value);
347         select_global=selected.split(";");
348         var box_value=sel_id.checked;
349         var id= sel_id.value;
350         var duplicate=select_global.indexOf(id);
351         var size=select_global.length-1;
352                 var result="";
353         //alert("size: "+size);
354         //alert("Box_value: "+box_value);
355         //alert("Duplicate: "+duplicate);
356         if(box_value == true)
357         {
358                 if(duplicate == "-1")
359                 {
360                         select_global[size]=id;
361                 }
362
363                 size=select_global.length-1;
364                 var i=0;
365                 for(i=0;i<=size;i++)
366                 {
367                         if(trim(select_global[i])!='')
368                                 result=select_global[i]+";"+result;
369                 }
370                 default_togglestate(sel_id.name,groupParentElementId);
371         }
372         else
373         {
374                 if(duplicate != "-1")
375                         select_global.splice(duplicate,1)
376
377                 size=select_global.length-1;
378                 var i=0;
379                 for(i=size;i>=0;i--)
380                 {
381                         if(trim(select_global[i])!='')
382                                 result=select_global[i]+";"+result;
383                 }
384           //      getObj("selectall").checked=false
385                 default_togglestate(sel_id.name,groupParentElementId);
386         }
387
388         document.getElementById("allselectedboxes").value=result;
389         //alert("Result: "+result);
390 }
391
392 function update_selected_checkbox()
393 {
394         var all=document.getElementById('current_page_boxes').value;
395         var tocheck=document.getElementById('allselectedboxes').value;
396         var allsplit=new Array();
397         allsplit=all.split(";");
398
399         var selsplit=new Array();
400         selsplit=tocheck.split(";");
401
402         var n=selsplit.length;
403         for(var i=0;i<n;i++)
404         {
405                 if(allsplit.indexOf(selsplit[i]) != "-1")
406                         document.getElementById(selsplit[i]).checked='true';
407         }
408 }
409
410 //Function to Set the status as Approve/Deny for Public access by Admin
411 function ChangeCustomViewStatus(viewid,now_status,changed_status,module,parenttab)
412 {
413         $('status').style.display = 'block';
414         new Ajax.Request(
415                 'index.php',
416                 {queue: {position: 'end', scope: 'command'},
417                         method: 'post',
418                     postBody:'module=CustomView&action=CustomViewAjax&file=ChangeStatus&dmodule='+module+'&record='+viewid+'&status='+changed_status,
419                                         onComplete: function(response)
420                                         {
421                                         var responseVal=response.responseText;
422                                                 if(responseVal.indexOf(':#:FAILURE') > -1) {
423                                                         alert('Failed');
424                                                 } else if(responseVal.indexOf(':#:SUCCESS') > -1) {
425                                                         var values = responseVal.split(':#:');
426                                                         var module_name = values[2];
427                                                         var customview_ele = $('viewname');
428                                                         showDefaultCustomView(customview_ele, module_name, parenttab);
429                                                 } else {
430                                                         $('ListViewContents').innerHTML = responseVal;
431                                                 }
432                                                 $('status').style.display = 'none';
433                                         }
434                                 }
435         );
436 }
437
438 function getListViewCount(module,element,parentElement,url){
439         if(module != 'Documents'){
440                 var elementList = document.getElementsByName(module+'_listViewCountRefreshIcon');
441                 for(var i=0;i<elementList.length;++i){
442                         elementList[i].style.display = 'none';
443                 }
444         }else{
445                 element.style.display = 'none';
446         }
447         var elementList = document.getElementsByName(module+'_listViewCountContainerBusy');
448         for(var i=0;i<elementList.length;++i){
449                 elementList[i].style.display = '';
450         }
451         var element = document.getElementsByName('search_url')[0];
452         var searchURL = '';
453         if(typeof element !='undefined'){
454                 searchURL = element.value;
455         }else if(typeof document.getElementsByName('search_text')[0] != 'undefined'){
456                 element = document.getElementsByName('search_text')[0];
457                 var searchField = document.getElementsByName('search_field')[0];
458                 if(element.value.length > 0) {
459                         searchURL = '&query=true&searchtype=BasicSearch&search_field='+
460                                 encodeURIComponent(searchField.value)+'&search_text='+encodeURIComponent(element.value);
461                 }
462         }else if(document.getElementById('globalSearchText') != null &&
463                         typeof document.getElementById('globalSearchText') != 'undefined'){
464                 var searchText = document.getElementById('globalSearchText').value;
465                 searchURL = '&query=true&globalSearch=true&globalSearchText='+encodeURIComponent(searchText);
466         }
467         if(module != 'Documents'){
468                 searchURL += (url);
469         }
470         // Url parameters to carry forward the Alphabetical search in Popups,
471         // which is stored in the global variable gPopupAlphaSearchUrl
472         if(typeof gPopupAlphaSearchUrl != 'undefined' && gPopupAlphaSearchUrl != '')
473                 searchURL += gPopupAlphaSearchUrl;
474
475         new Ajax.Request(
476                         'index.php',
477                         {queue: {position: 'end', scope: 'command'},
478                                 method: 'post',
479                                 postBody:"module="+module+"&action="+module+"Ajax&file=ListViewPagging&ajax=true"+searchURL,
480                                 onComplete: function(response) {
481                                         var elementList = document.getElementsByName(module+'_listViewCountContainerBusy');
482                                         for(var i=0;i<elementList.length;++i){
483                                                 elementList[i].style.display = 'none';
484                                         }
485                                         elementList = document.getElementsByName(module+'_listViewCountRefreshIcon');
486                                         if(module != 'Documents' && typeof parentElement != 'undefined' && elementList.length !=0){
487                                                 for(i=0;i<=elementList.length;){
488                                                         //No need to increment the count, as the element will be eliminated in the next step.
489                                                         elementList[i].parentNode.innerHTML = response.responseText;
490                                                 }
491                                         }else{
492                                                 parentElement.innerHTML = response.responseText;
493                                         }
494                                 }
495                         }
496         );
497 }
498
499 function VT_disableFormSubmit(evt) {
500         var evt = (evt) ? evt : ((event) ? event : null);
501         var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
502         if ((evt.keyCode == 13) && (node.type=='text')) {
503                 node.onchange();
504                 return false;
505         }
506         return true;
507 }
Note: See TracBrowser for help on using the browser.