1 | /** |
---|
2 | * @author diogenes |
---|
3 | */ |
---|
4 | function ccFullSearch() { |
---|
5 | var win; |
---|
6 | var fields = null; |
---|
7 | } |
---|
8 | |
---|
9 | ccFullSearch.prototype.showForm = function() { |
---|
10 | div = document.getElementById('cc_searchDiv'); |
---|
11 | // if(this.fields==null) |
---|
12 | // this.fields = new Array(Element('cc_qa_given_names').value, Element('cc_corporate').value+":", Element('cc_qa_email').value, Element('cc_qa_phone').value); |
---|
13 | if(div) |
---|
14 | this.showWindow(div); |
---|
15 | else { |
---|
16 | |
---|
17 | var el = document.createElement("DIV"); |
---|
18 | el.style.visibility = "hidden"; |
---|
19 | el.style.position = "absolute"; |
---|
20 | el.style.left = "0px"; |
---|
21 | el.style.top = "0px"; |
---|
22 | el.style.width = "0px"; |
---|
23 | wHeight = Element('ccQAWinHeight').value; |
---|
24 | el.style.height = wHeight + 'px'; |
---|
25 | el.className = "div_cc_rectQuickAddContact"; |
---|
26 | el.id = 'cc_searchDiv'; |
---|
27 | document.body.appendChild(el); |
---|
28 | el.innerHTML = ""; |
---|
29 | |
---|
30 | var fieldsTop = 10; |
---|
31 | var fieldsSpace = 30; |
---|
32 | for (i=0; i<this.fields.length; i++) { |
---|
33 | el.innerHTML += '<span id="ccSearchSpan' + i + '" style="position: absolute; top: ' + (fieldsTop+i*fieldsSpace) + 'px; left: 5px; width: 100px; text-align: right; border: 0px solid #999;">' + this.fields[i] + '</span>'; |
---|
34 | el.innerHTML += '<input id="ccSearchInp' + i + '" type="text" maxlength="30" style="position: absolute; top: ' + (fieldsTop + i * fieldsSpace) + 'px; left: 110px; width: 135px;">'; |
---|
35 | } |
---|
36 | el.innerHTML +='<div id="ccSearchFunctions" style="border: 0px solid black; width: 220px; height: 20px">' + |
---|
37 | '<input title="' + Element('cc_panel_search_text').value + '" type="button" onclick="ccFullSearchVar.go();" style="position: absolute; top: ' + (fieldsTop+i*fieldsSpace) + 'px; left: 35px; width: 60px" value="'+Element('cc_panel_search_text').value+'"/>' + |
---|
38 | '<input title="' + Element('cc_msg_clean').value + '" type="button" onclick="ccFullSearchVar.clean();" value="' + Element('cc_msg_clean').value + '" style="position: absolute; top: ' + (fieldsTop+i*fieldsSpace) + 'px; left: 100px; width: 60px" />' + |
---|
39 | '<input title="' + Element('cc_qa_close').value + '" type="button" onclick="ccFullSearchVar.close();" value="' + Element('cc_qa_close').value + '" style="position: absolute; top: ' + (fieldsTop+i*fieldsSpace) + 'px; left: 165px; width: 60px" />' + |
---|
40 | '</div>'; |
---|
41 | el.innerHTML += "<br>"; |
---|
42 | |
---|
43 | this.showWindow(el); |
---|
44 | } |
---|
45 | |
---|
46 | } |
---|
47 | |
---|
48 | ccFullSearch.prototype.showWindow = function (div) |
---|
49 | { |
---|
50 | if(! this.win) { |
---|
51 | win = new dJSWin({ |
---|
52 | id: 'ccSearch_'+div.id, |
---|
53 | content_id: div.id, |
---|
54 | width: '255px', |
---|
55 | height: wHeight+'px', |
---|
56 | title_color: '#3978d6', |
---|
57 | bg_color: '#eee', |
---|
58 | title: Element('cc_cs_title').value, |
---|
59 | title_text_color: 'white', |
---|
60 | button_x_img: Element('cc_phpgw_img_dir').value+'/winclose.gif', |
---|
61 | border: true }); |
---|
62 | |
---|
63 | this.win = win; |
---|
64 | win.draw(); |
---|
65 | } |
---|
66 | if((ccTree.actualCatalog=='bo_people_catalog') || |
---|
67 | (ccTree.actualCatalog=='bo_shared_people_manager')) //Habilita empresa apenas para catálogos que não sejam do ldap. |
---|
68 | Element('ccSearchInp1').disabled = false; |
---|
69 | else |
---|
70 | Element('ccSearchInp1').disabled = true; |
---|
71 | this.win.open(); |
---|
72 | } |
---|
73 | |
---|
74 | ccFullSearch.prototype.go = function () { |
---|
75 | |
---|
76 | var _this = this; |
---|
77 | var data = new Array(); |
---|
78 | var type = Element('cc_type_contact').value; |
---|
79 | |
---|
80 | data['fields'] = new Array(); |
---|
81 | |
---|
82 | data['search_for'] = Element('ccSearchInp0').value + " " |
---|
83 | + Element('ccSearchInp1').value + " " |
---|
84 | + Element('ccSearchInp2').value + " " |
---|
85 | + Element('ccSearchInp3').value + " "; |
---|
86 | |
---|
87 | var invalidChars = /[\%\?]/; |
---|
88 | if(invalidChars.test(data['search_for']) || invalidChars.test(data['search_for_area'])){ |
---|
89 | showMessage(Element('cc_msg_err_invalid_serch').value); |
---|
90 | return; |
---|
91 | } |
---|
92 | |
---|
93 | var search_for = data['search_for'].split(' '); |
---|
94 | var greaterThanMin = false; |
---|
95 | var use_length = v_min; |
---|
96 | |
---|
97 | for (i = 0; i < search_for.length; i++) |
---|
98 | { |
---|
99 | if (search_for[i].length >= use_length) |
---|
100 | { |
---|
101 | greaterThanMin = true; |
---|
102 | } |
---|
103 | } |
---|
104 | |
---|
105 | if (!greaterThanMin){ |
---|
106 | alert("Favor fazer a consulta com pelo menos " + v_min + " caracteres!"); |
---|
107 | return; |
---|
108 | } |
---|
109 | |
---|
110 | if (Element('ccSearchInp0').value == "") |
---|
111 | data['search_for'] = ""; |
---|
112 | |
---|
113 | if (type=='groups') { |
---|
114 | data['fields']['id'] = 'group.id_group'; |
---|
115 | data['fields']['search'] = 'group.title'; |
---|
116 | } |
---|
117 | else { |
---|
118 | data['fields']['id'] = 'contact.id_contact'; |
---|
119 | data['fields']['search'] = 'contact.names_ordered'; |
---|
120 | } |
---|
121 | //data['search_for'] = Element('ccSearchInp0').value; |
---|
122 | data['full_search'] = new Array(); |
---|
123 | |
---|
124 | data['full_search']['corporate'] = Element('ccSearchInp1').disabled?'':Element('ccSearchInp1').value; |
---|
125 | data['full_search']['mail'] = Element('ccSearchInp2').value ; |
---|
126 | data['full_search']['phone'] = Element('ccSearchInp3').value ; |
---|
127 | var handler = function(responseText) { |
---|
128 | ccSearch.mount_handler(responseText); |
---|
129 | _this.close(); |
---|
130 | } |
---|
131 | Connector.newRequest('fullSearch',CC_url+'search&data='+serialize(data), 'GET',handler); |
---|
132 | } |
---|
133 | |
---|
134 | ccFullSearch.prototype.close = function() { |
---|
135 | this.win.close(); |
---|
136 | } |
---|
137 | |
---|
138 | ccFullSearch.prototype.clean = function() { |
---|
139 | for (i=0; i<this.fields.length; i++) { |
---|
140 | Element('ccSearchInp'+i).value = ''; |
---|
141 | } |
---|
142 | } |
---|
143 | |
---|
144 | var ccFullSearchVar = new ccFullSearch(); |
---|