]> err.no Git - scalable-opengroupware.org/blob - SOGo/UI/MailerContacts/mailercontacts.js
work on tableview reloading DHTML
[scalable-opengroupware.org] / SOGo / UI / MailerContacts / mailercontacts.js
1 /*
2   Copyright (C) 2005 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
5
6   OGo is free software; you can redistribute it and/or modify it under
7   the terms of the GNU Lesser General Public License as published by the
8   Free Software Foundation; either version 2, or (at your option) any
9   later version.
10
11   OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12   WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14   License for more details.
15
16   You should have received a copy of the GNU Lesser General Public
17   License along with OGo; see the file COPYING.  If not, write to the
18   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19   02111-1307, USA.
20 */
21 /* JavaScript code for SOGo MailerUI contacts */
22
23 function openContact(sender, addruid) {
24   var w;
25   
26   w = window.open(addruid + "/tb.edit", 'SOGo_addr_' + addruid,
27                   'width=540,height=340,resizable=1,scrollbars=1,toolbar=0,' +
28                   'location=0,directories=0,status=0,menubar=0,copyhistory=0');
29   w.focus();
30   return false;
31 }
32
33 function cl_highlight(sender) {
34   sender.className = "tableview_highlight";
35 }
36 function cl_lowlight(sender) {
37   sender.className = "tableview";
38 }
39
40 /* edit field */
41
42 function cl_saveFieldValue(sender, keyName) {
43   var http = createHTTPClient();
44
45   if (http) {
46     var tableRow = sender.parentNode.parentNode;
47     var recordID = tableRow.id;
48     var url      = window.location.href;
49     var content;
50     
51     url = ml_stripActionInURL(url);
52     url = url + recordID + "/patchOneField";
53     // TODO: confuses SOPE?!: url = url + "?jsonly=1"
54     
55     // TODO: need to use XML!
56     content = keyName + "\n" + sender.value;
57     
58     http.open("POST", url, false);
59     http.send(content);
60     if (http.status != 200) {
61       // TODO: localize, improve error message
62       alert("Store Failed: " + http.statusText);
63     }
64     else {
65       return true;
66     }
67   }
68   else {
69     // TODO: we should disable the functionality now
70   }
71   return false;
72 }
73
74 var currentEditField = null;
75 var currentEditDiv   = null;
76 var oldFieldValue    = null;
77 var currentKeyName   = null;
78
79 function cl_findEditField(sender) {
80   var f;
81
82   f = sender.parentNode.getElementsByTagName("input");
83   return (f.length > 0) ? f[0] : null;
84 }
85
86 function cl_showEditField(sender, e, keyName) {
87   var inputField;
88
89   if (currentEditDiv != null)
90     cl_findEditField(currentEditField);
91   
92   e.stopPropagation();
93   
94   currentKeyName   = keyName;
95   currentEditDiv   = sender;
96   currentEditField = cl_findEditField(sender);
97   oldFieldValue    = unescapeHTML(sender.innerHTML);
98   
99   inputField               = cl_findEditField(sender);
100   inputField.value         = oldFieldValue;
101   sender.style.display     = "none";
102   inputField.style.display = "inline";
103
104   inputField.focus();
105   inputField.select();
106   
107   return true;
108 }
109
110 function cl_finishEditField(sender) {
111   // this might trigger onblur!
112
113   if (sender != currentEditField && sender != null)
114     return;
115   
116   currentEditField.style.display = "none";
117   currentEditDiv.style.display   = "inline";
118   currentEditField = null;
119   currentEditDiv   = null;
120   currentKeyName   = null;
121   oldFieldValue    = null;
122 }
123
124 function cl_editFieldKeyPress(sender, e) {
125   if (e.keyCode == 27) { /* escape, cancel editing */
126     cl_finishEditField(null);
127     return false;
128   }
129   if (e.keyCode == 13) { /* save using XMLHttpRequest */
130     if (cl_saveFieldValue(sender, currentKeyName)) {
131       // copy new value to div
132       currentEditDiv.innerHTML = escapeHTML(sender.value);
133       cl_finishEditField(null);
134     }
135     else {
136       // alert blurs!: alert("field save failed!"); // TODO: localize
137       // TODO: do we have beep or something?
138     }
139     return false;
140   }
141
142   // TODO: we could support "tab" for jumping to the next field
143   return true;
144 }