source: sandbox/expresso2.2/contactcenter/js/ccAux.js @ 1662

Revision 1662, 5.8 KB checked in by amuller, 14 years ago (diff)

Ticket #490 - Criação dos códigos de unificação ajax

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1  /***************************************************************************\
2  * eGroupWare - Contacts Center                                              *
3  * http://www.egroupware.org                                                 *
4  * Written by:                                                               *
5  *  - Raphael Derosso Pereira <raphaelpereira@users.sourceforge.net>         *
6  *  - Jonas Goes <jqhcb@users.sourceforge.net>                               *
7  *  sponsored by Thyamad - http://www.thyamad.com                            *
8  * ------------------------------------------------------------------------- *
9  *  This program is free software; you can redistribute it and/or modify it  *
10  *  under the terms of the GNU General Public License as published by the    *
11  *  Free Software Foundation; either version 2 of the License, or (at your   *
12  *  option) any later version.                                               *
13  \***************************************************************************/
14
15/***********************************************\
16*               INITIALIZATION                  *
17\***********************************************/
18if (document.all)
19{
20        navigator.userAgent.toLowerCase().indexOf('msie 5') != -1 ? is_ie5 = true : is_ie5 = false;
21        is_ie = true;
22        is_moz1_6 = false;
23        is_mozilla = false;
24        is_ns4 = false;
25}
26else if (document.getElementById)
27{
28        navigator.userAgent.toLowerCase().match('mozilla.*rv[:]1\.6.*gecko') ? is_moz1_6 = true : is_moz1_6 = false;
29        is_ie = false;
30        is_ie5 = false;
31        is_mozilla = true;
32        is_ns4 = false;
33}
34else if (document.layers)
35{
36        is_ie = false;
37        is_ie5 = false
38        is_moz1_6 = false;
39        is_mozilla = false;
40        is_ns4 = true;
41}
42
43/***********************************************\
44 *                DATA FUNCTIONS               *
45\***********************************************/
46function randomString() {
47        var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
48        var string_length = 4;
49        var randomstring = '';
50        for (var i=0; i<string_length; i++) {
51                var rnum = Math.floor(Math.random() * chars.length);
52                randomstring += chars.substring(rnum,rnum+1);
53        }
54        return randomstring;
55}
56
57function serialize(data)
58{
59        return expresso.connector.serialize(data);
60}
61
62function unserialize(str)
63{
64        return expresso.connector.unserialize(str);
65}
66
67
68
69/***********************************************\
70*               AUXILIAR FUNCTIONS              *
71\***********************************************/
72
73function resizeIcon(id, action)
74{
75        var element = Element(id);
76       
77        if (action == 0)
78        {
79                CC_old_icon_w = element.style.width;
80                CC_old_icon_h = element.style.height;
81
82                element.style.zIndex = parseInt(element.style.zIndex) + 1;
83                element.style.width = '36px';
84                element.style.height = '36px';
85                element.style.top = (parseInt(element.style.top) - parseInt(element.style.height)/2) + 'px';
86                element.style.left = (parseInt(element.style.left) - parseInt(element.style.width)/2) + 'px';
87        }
88        else if (action == 1)
89        {
90                element.style.zIndex = parseInt(element.style.zIndex) - 1;
91                element.style.top = (parseInt(element.style.top) + parseInt(element.style.height)/2) + 'px';
92                element.style.left = (parseInt(element.style.left) + parseInt(element.style.width)/2) + 'px';
93                element.style.width = CC_old_icon_w;
94                element.style.height = CC_old_icon_h;
95        }
96}
97
98function Element (element)
99{
100        /* IE OBJECTS */
101        if (document.all)
102        {
103                return document.all[element];
104        }
105        /* MOZILLA OBJECTS */
106        else if (document.getElementById)
107        {
108                return document.getElementById(element);
109        }
110        /* NS4 OBJECTS */
111        else if (document.layers)
112        {
113                return document.layers[element];
114        }
115}
116
117function removeHTMLCode(id)
118{
119        Element(id).parentNode.removeChild(Element(id));
120}
121
122function addHTMLCode(parent_id,child_id,child_code,surround_block_tag)
123{
124        var obj = document.createElement(surround_block_tag);
125        Element(parent_id).appendChild(obj);
126        obj.id = child_id;
127        obj.innerHTML = child_code;
128        return obj;
129}
130
131function addSlashes(code)
132{
133        for (var i = 0; i < code.length; i++)
134        {
135                switch(code.charAt(i))
136                {
137                        case "'":
138                        case '"':
139                        case "\\":
140                                code = code.substr(0, i) + "\\" + code.charAt(i) + code.substr(i+1);
141                                i++;
142                                break;
143                }
144        }
145
146        return code;
147}
148
149function htmlSpecialChars(str)
150{
151        // TODO: Not implemented!!!
152        var pos = 0;
153       
154        for (var i = 0; i < str.length; i++)
155        {
156               
157        }
158}
159
160function replaceComAnd(str, replacer)
161{
162        return escape( str );
163        var oldPos = 0;
164        var pos = 0;
165       
166        while ((pos = str.indexOf('&', pos)) != -1)
167        {
168                str = str.substring(oldPos, pos) + replacer + str.substring(pos+1);
169        }
170
171        return str;
172}
173
174function ccTimeout(control, code, maxCalls, actualCall, singleTimeout)
175{
176        if (eval(control))
177        {
178                eval(code);
179                return true;
180        }
181
182        if (!actualCall)
183        {
184                actualCall = 1;
185        }
186
187        if (!maxCalls)
188        {
189                maxCalls = 100;
190        }
191
192        if (actualCall == maxCalls)
193        {
194                showMessage(Element('cc_msg_err_timeout').value);
195                return false;
196        }
197
198        if (!singleTimeout)
199        {
200                singleTimeout = 100;
201        }
202
203        setTimeout('ccTimeout(\''+control+'\',\''+addSlashes(code)+'\','+maxCalls+','+(actualCall+1)+','+singleTimeout+')', singleTimeout);
204}
205
206function showMessage(msg, type)
207{
208        // TODO: Replace alert with 'loading' style div with Ok button
209
210        switch(type)
211        {
212                case 'confirm':
213                        return confirm(msg);
214
215                default:
216                        alert(msg);
217                        return;
218        }
219}
220
221function formatPhone(obj){
222        if (!Element("cc_conn_type_1").checked) {
223                obj.value = obj.value.replace(/[^\-\d\+\(\)\sx]/g, "");
224        } 
225}
226
227
228/***********************************************\
229*                   CONSTANTS                   *
230\***********************************************/
231
232var CC_url = Element('cc_server_root').value+'/index.php?menuaction=contactcenter.ui_data.data_manager&method=';
233
234/***********************************************\
235*               GLOBALS VARIABLES               *
236\***********************************************/
237
238var CC_loading_div = null;
239var CC_loading_td  = null;
240var CC_loading     = false;
241var CC_loading_set = false;
Note: See TracBrowser for help on using the repository browser.