]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/modules/MergeRecords/Merge.js
Release 6.5.0
[Github/sugarcrm.git] / jssource / src_files / modules / MergeRecords / Merge.js
1 /*********************************************************************************
2  * SugarCRM Community Edition is a customer relationship management program developed by
3  * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
4  * 
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU Affero General Public License version 3 as published by the
7  * Free Software Foundation with the addition of the following permission added
8  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
9  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
10  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
11  * 
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
15  * details.
16  * 
17  * You should have received a copy of the GNU Affero General Public License along with
18  * this program; if not, see http://www.gnu.org/licenses or write to the Free
19  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20  * 02110-1301 USA.
21  * 
22  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
23  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
24  * 
25  * The interactive user interfaces in modified source and object code versions
26  * of this program must display Appropriate Legal Notices, as required under
27  * Section 5 of the GNU Affero General Public License version 3.
28  * 
29  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
30  * these Appropriate Legal Notices must retain the display of the "Powered by
31  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
32  * technical reasons, the Appropriate Legal Notices must display the words
33  * "Powered by SugarCRM".
34  ********************************************************************************/
35
36
37
38
39 var lbl_remove = SUGAR.language.get('app_strings', 'LBL_REMOVE');
40
41 function remove_filter(spanfieldid) {
42         var selspan = document.getElementById(spanfieldid);
43         //hide the span 
44         selspan.setAttribute("style","visibility:hidden");
45         selspan.innerHTML='';//' '
46
47         //and id to avail list. 
48         var ops=object_refs['field_avail_list'].options;
49         var newoption = new Option(selspan.getAttribute("Value"),selspan.getAttribute("ValueId"),false,true);
50         ops.add(newoption);
51 }
52 function ajax_fetch_sync(url,post_data)
53 {
54         global_xmlhttp = getXMLHTTPinstance();
55
56         var method = 'GET';
57         if ( typeof(post_data) != 'undefined' )
58         {
59                 method = 'POST';
60         }
61
62         try
63         {
64                 global_xmlhttp.open(method, url,false);
65         }
66         catch(error)
67         {
68                 alert('message:'+error.message+":url:"+url);
69         }
70         
71         if ( method == 'POST')
72         {
73                 global_xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
74         }
75
76         global_xmlhttp.send(post_data);
77         var ajax_response = {"responseText":global_xmlhttp.responseText,"responseXML":global_xmlhttp.responseXML};
78
79         return ajax_response;
80 }
81
82 //----------------------------------------------------
83 //----------------------------------------------------
84 //----------------------------------------------------
85 function get_fields_to_dedup(parent_mod)
86 {
87         var rel_map_div_obj = document.getElementById('rel_map');       
88
89         if(parent_mod != '')
90         {
91                 var request_id = 1;
92                 var     url = site_url + '/index.php?to_pdf=1&sugar_body_only=1&inline=1&parent_module=' + parent_mod + '&module=MigrationMappings&action=GetRelationshipsToMap';
93                 var ajax_return_obj = ajax_fetch_sync(url);
94
95                 try     { eval("var responseObj =" + ajax_return_obj['responseText']); }
96                 catch(e) { alert(ajax_return_obj['responseText']); }
97
98                 build_avail_rels_array(responseObj);
99                 
100                 rel_map_div_obj.innerHTML = responseObj['html_content'];
101         }
102         else
103         {
104                 rel_map_div_obj.innerHTML = '';
105         }
106         
107         return true;
108 }
109
110 function get_dedup_fields()
111 {
112         var parent_div = document.getElementById('filter_def');
113         var node;
114         var spannode;
115         var value;
116         var valueid;
117         var style;
118         document.DedupSetup.dedup_fields.value='';
119         for (node in parent_div.childNodes) {
120            spannode=parent_div.childNodes[node];
121            if (spannode.tagName=='SPAN') {
122                         value= spannode.getAttribute('value');
123                         valueid=spannode.getAttribute('valueid');                                       
124                         style=spannode.getAttribute('style');                                   
125                         if (typeof(style) == 'undefined' || style==null || style=='' || style.lastIndexOf('hidden') == -1 ) {
126                                 if (document.DedupSetup.dedup_fields.value != '') {
127                                         document.DedupSetup.dedup_fields.value=document.DedupSetup.dedup_fields.value + '#';
128                                 }
129                                 document.DedupSetup.dedup_fields.value = document.DedupSetup.dedup_fields.value + valueid;
130                         }
131            }
132         }
133         
134         //var selected_fields_obj = document.getElementById('field_include_list[]');
135
136         //for(i=0; i < selected_fields_obj.length; i++)
137         //{
138         //      document.DedupSetup.dedup_fields.value = document.DedupSetup.dedup_fields.value + selected_fields_obj.options[i].value;
139         //      if(i != (selected_fields_obj.length - 1)) { document.DedupSetup.dedup_fields.value += '#'; }
140         //}
141
142 //      document.DedupSetup.submit();   
143 }
144
145 //-------------------------------------------------------------------
146 //-------------------------------------------------------------------
147 //-------------------------------------------------------------------
148 //-------------------------------------------------------------------
149 //-------------------------------------------------------------------
150 //-------------------------------------------------------------------
151 var object_refs = new Object();
152 object_refs['field_include_list'] = document.DedupSetup['field_include_list']; 
153 object_refs['field_avail_list'] = document.DedupSetup['field_avail_list'];
154
155 function setselected(included_name,avail_name) 
156 {
157         var included_columns_ref = object_refs[included_name];
158         var avail_columns_ref = object_refs[avail_name];
159
160         var included_td = document.getElementById(included_name+'_td');
161         var avail_td = document.getElementById(avail_name+'_td');
162
163         var selected_avail = new Array();
164         var notselected_avail = new Array();
165         var notselected_include = new Array();
166
167         for (i=0; i < avail_columns_ref.options.length; i++)
168         {
169                 if (avail_columns_ref.options[i].selected == true) 
170                 {
171                         selected_avail[selected_avail.length] = {text:avail_columns_ref.options[i].text, value:avail_columns_ref.options[i].value};
172                 }
173                 else
174                 {
175                         notselected_avail[notselected_avail.length] = {text:avail_columns_ref.options[i].text, value:avail_columns_ref.options[i].value};
176                 }
177                 
178         }
179
180         var right_select_html_info = new Object();
181         var right_options = new Array();
182         var right_select = new Object();
183
184         right_select['name'] = avail_name+ '[]';
185         right_select['id'] = avail_name;
186         right_select['multiple'] = 'true';
187         right_select['size'] = '10';
188
189         for (i=0;i < notselected_avail.length;i++)
190         {
191                 right_options[right_options.length] = notselected_avail[i];     
192         }
193
194         right_select_html_info['options'] = right_options;
195         right_select_html_info['select'] = right_select;
196
197         var right_html = buildSelectHTML(right_select_html_info);
198
199         avail_td.innerHTML = right_html;
200         object_refs[avail_name] = avail_td.getElementsByTagName('select')[0];
201
202         //////////////////////////////
203         for(p=0; p < selected_avail.length; p++)
204         {
205                 addFieldRow(selected_avail[p].value, selected_avail[p].text)
206         }
207         ///////////////////////////
208
209 }
210
211
212 function up(name) {
213         var td = document.getElementById(name+'_td');
214         var obj = td.getElementsByTagName('select')[0];
215         obj = (typeof obj == "string") ? document.getElementById(obj) : obj;
216         if (obj.tagName.toLowerCase() != "select" && obj.length < 2)
217                 return false;
218         var sel = new Array();
219
220         for (i=0; i<obj.length; i++) {
221                 if (obj[i].selected == true) {
222                         sel[sel.length] = i;
223                 }
224         }
225         for (i in sel) {
226                 if (sel[i] != 0 && !obj[sel[i]-1].selected) {
227                         var tmp = new Array(obj[sel[i]-1].text, obj[sel[i]-1].value);
228                         obj[sel[i]-1].text = obj[sel[i]].text;
229                         obj[sel[i]-1].value = obj[sel[i]].value;
230                         obj[sel[i]].text = tmp[0];
231                         obj[sel[i]].value = tmp[1];
232                         obj[sel[i]-1].selected = true;
233                         obj[sel[i]].selected = false;
234                 }
235         }
236 }
237
238
239 function down(name) {
240         var td = document.getElementById(name+'_td');
241         var obj = td.getElementsByTagName('select')[0];
242         if (obj.tagName.toLowerCase() != "select" && obj.length < 2)
243                 return false;
244         var sel = new Array();
245         for (i=obj.length-1; i>-1; i--) {
246                 if (obj[i].selected == true) {
247                         sel[sel.length] = i;
248                 }
249         }
250         for (i in sel) {
251                 if (sel[i] != obj.length-1 && !obj[sel[i]+1].selected) {
252                         var tmp = new Array(obj[sel[i]+1].text, obj[sel[i]+1].value);
253                         obj[sel[i]+1].text = obj[sel[i]].text;
254                         obj[sel[i]+1].value = obj[sel[i]].value;
255                         obj[sel[i]].text = tmp[0];
256                         obj[sel[i]].value = tmp[1];
257                         obj[sel[i]+1].selected = true;
258                         obj[sel[i]].selected = false;
259                 }
260         }
261 }
262
263 function buildSelectHTML(info)
264 {
265         var text;
266         text = "<div align='left'><select";
267
268         if ( typeof (info['select']['size']) != 'undefined')
269         {
270                 text +=" size=\""+ info['select']['size'] +"\"";
271         }
272
273         if ( typeof (info['select']['name']) != 'undefined')
274         {
275                 text +=" name=\""+ info['select']['name'] +"\"";
276         }
277
278         if ( typeof (info['select']['style']) != 'undefined')
279         {
280                 text +=" style=\""+ info['select']['style'] +"\"";
281         }
282
283         if ( typeof (info['select']['onchange']) != 'undefined')
284         {
285                 text +=" onChange=\""+ info['select']['onchange'] +"\"";
286         }
287
288         if ( typeof (info['select']['multiple']) != 'undefined')
289         {
290                 text +=" multiple";
291         }
292         text +=">";
293
294         for(i=0; i<info['options'].length;i++)
295         {
296                 option = info['options'][i];
297                 text += "<option value=\""+option['value']+"\" ";
298                 if ( typeof (option['selected']) != 'undefined' && option['selected']== true)
299                 {
300                         text += "SELECTED";
301                 }
302                 text += ">"+option['text']+"</option>";
303         }
304         text += "</select></div>";
305         return text;
306 }
307
308 //////////////////////////////////////////////
309 var fieldCount = 0;
310 function addFieldRow(colName, colLabel) {
311         var tableId = 'search_type';
312         var rowIdName = 'field';
313
314         var fieldArrayCount;
315         var optionVal;
316         var optionDispVal;
317         var optionsIndex = 0;
318
319         fieldCount = fieldCount + 1;
320         document.DedupSetup.num_fields.value = fieldCount;
321
322         var selElement = document.createElement("select");
323         var selectName = colName + "SearchType";
324         selElement.setAttribute("name", selectName);
325
326         var i=0;
327         for (theoption in operator_options) {
328                 selElement.options[i] = new Option(operator_options[theoption],theoption,  false, false);
329                 i++;
330         }
331
332         var aElement = document.createElement("a");
333         aElement.setAttribute("href","javascript:remove_filter('filter_" + colName + "')");
334         aElement.setAttribute("class","listViewTdToolsS1");
335         
336         var imgElement = document.createElement("img");
337         imgElement.setAttribute("src", delete_inline_image);
338         imgElement.setAttribute("align","absmiddle");
339         imgElement.setAttribute("alt",lbl_remove);
340         imgElement.setAttribute("border","0");
341         imgElement.setAttribute("height","12");
342         imgElement.setAttribute("width","12");
343         
344         aElement.appendChild(imgElement);
345         aElement.appendChild(document.createTextNode(" "));
346         
347         var div = document.getElementById('filter_def');
348         var span1 =  document.getElementById('filter_'+colName);
349         if (span1 == null || span1=='' || typeof(span1)=='undefined') {
350                 span1=document.createElement("span");
351         } else {
352                 span1.setAttribute("style","visibility:visible");
353         }
354         
355         span1.setAttribute("id",'filter_'+colName);
356         span1.setAttribute("Value",colLabel);   
357         span1.setAttribute("ValueId",colName);
358         
359         //table as a child of span element.
360         //table with only row only.
361         var table = document.createElement("table");
362         //usage or insertRow is required by IE, ironically this call
363         //produces bad UI when using IE on mac.
364         var row = table.insertRow(table.rows.length );
365         table.setAttribute("width","100%");
366         table.setAttribute("border","0");
367         table.setAttribute("cellpadding","0");
368
369         var td1= document.createElement("td");
370         td1.setAttribute("width","2%");
371         
372         td1.appendChild(aElement);      
373         row.appendChild(td1)
374
375         var td2= document.createElement("td");
376         td2.setAttribute("width","20%");
377         td2.appendChild(document.createTextNode(colLabel + ':  '));     
378         row.appendChild(td2)
379         
380         var td3= document.createElement("td");
381         td3.setAttribute("width","10%");
382         td3.appendChild(selElement);    
383         row.appendChild(td3);
384
385         var coldata;
386         eval("coldata=bean_data."+ colName+ ";");
387         
388         var edit=document.createElement("input");
389         edit.setAttribute("type","text");
390         edit.setAttribute("name",colName + 'SearchField');
391         edit.setAttribute("id",colName + 'SearchField');
392         edit.setAttribute("value",coldata);
393         
394
395         var td5= document.createElement("td");
396         td5.setAttribute("width","68%");
397         td5.appendChild(edit);  
398         row.appendChild(td5);
399
400         
401         //table.appendChild(row);
402         span1.appendChild(table);
403         div.appendChild(span1); 
404 }