From: helge Date: Fri, 18 Feb 2005 17:43:35 +0000 (+0000) Subject: added inline editing to contact tableview X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bbeb8e5c6ffa7a803b06f9be284cd4c296231c83;p=scalable-opengroupware.org added inline editing to contact tableview git-svn-id: http://svn.opengroupware.org/SOGo/trunk@587 d1b88da0-ebda-0310-925b-ed51d893ca5b --- diff --git a/SOGo/UI/Contacts/UIxContactEditor.m b/SOGo/UI/Contacts/UIxContactEditor.m index 674141f6..d37eb1ea 100644 --- a/SOGo/UI/Contacts/UIxContactEditor.m +++ b/SOGo/UI/Contacts/UIxContactEditor.m @@ -248,6 +248,7 @@ [self saveValuesIntoRecord:record]; + // TODO: directly hacking the content, hm, not so nice or reasonable? recstr = [record description]; // make plist ex = [[self clientObject] saveContentString:recstr]; if (ex != nil) { diff --git a/SOGo/UI/MailerContacts/ChangeLog b/SOGo/UI/MailerContacts/ChangeLog index 36245ec2..d4eca3b3 100644 --- a/SOGo/UI/MailerContacts/ChangeLog +++ b/SOGo/UI/MailerContacts/ChangeLog @@ -1,3 +1,8 @@ +2005-02-18 Helge Hess + + * mailercontacts.js: added some function to allow inline editing of + fields in a tableview (v0.9.6) + 2005-02-17 Helge Hess * removed DUP Images directory, resource lookup now properly works for diff --git a/SOGo/UI/MailerContacts/Version b/SOGo/UI/MailerContacts/Version index 84f2fb42..dacebf41 100644 --- a/SOGo/UI/MailerContacts/Version +++ b/SOGo/UI/MailerContacts/Version @@ -1,5 +1,5 @@ # version file -SUBMINOR_VERSION:=5 +SUBMINOR_VERSION:=6 # v0.9.5 requires MailerUI v0.9.116 diff --git a/SOGo/UI/MailerContacts/mailercontacts.js b/SOGo/UI/MailerContacts/mailercontacts.js index bb3a540c..536253cf 100644 --- a/SOGo/UI/MailerContacts/mailercontacts.js +++ b/SOGo/UI/MailerContacts/mailercontacts.js @@ -36,3 +36,121 @@ function cl_highlight(sender) { function cl_lowlight(sender) { sender.className = "tableview"; } + +/* edit field */ + +function cl_stripActionInURL(url) { + if (url[url.length - 1] != '/') { + var i; + + i = url.lastIndexOf("/"); + if (i != -1) url = url.substring(0, i); + } + if (url[url.length - 1] != '/') // ensure trailing slash + url = url + "/"; + return url; +} + +function cl_saveFieldValue(sender, keyName) { + var http = createHTTPClient(); + + if (http) { + var tableRow = sender.parentNode.parentNode; + var recordID = tableRow.id; + var url = window.location.href; + var content; + + url = cl_stripActionInURL(url); + url = url + recordID + "/patchOneField"; + // TODO: confuses SOPE?!: url = url + "?jsonly=1" + + // TODO: need to use XML! + content = keyName + "\n" + sender.value; + + http.open("POST", url, false); + http.send(content); + if (http.status != 200) { + // TODO: localize, improve error message + alert("Store Failed: " + http.statusText); + } + else { + return true; + } + } + else { + // TODO: we should disable the functionality now + } + return false; +} + +var currentEditField = null; +var currentEditDiv = null; +var oldFieldValue = null; +var currentKeyName = null; + +function cl_findEditField(sender) { + var f; + + f = sender.parentNode.getElementsByTagName("input"); + return (f.length > 0) ? f[0] : null; +} + +function cl_showEditField(sender, e, keyName) { + var inputField; + + if (currentEditDiv != null) + cl_findEditField(currentEditField); + + e.stopPropagation(); + + currentKeyName = keyName; + currentEditDiv = sender; + currentEditField = cl_findEditField(sender); + oldFieldValue = unescapeHTML(sender.innerHTML); + + inputField = cl_findEditField(sender); + inputField.value = oldFieldValue; + sender.style.display = "none"; + inputField.style.display = "inline"; + + inputField.focus(); + inputField.select(); + + return true; +} + +function cl_finishEditField(sender) { + // this might trigger onblur! + + if (sender != currentEditField && sender != null) + return; + + currentEditField.style.display = "none"; + currentEditDiv.style.display = "inline"; + currentEditField = null; + currentEditDiv = null; + currentKeyName = null; + oldFieldValue = null; +} + +function cl_editFieldKeyPress(sender, e) { + if (e.keyCode == 27) { /* escape, cancel editing */ + cl_finishEditField(null); + return false; + } + if (e.keyCode == 13) { /* save using XMLHttpRequest */ + if (cl_saveFieldValue(sender, currentKeyName)) { + // copy new value to div + currentEditDiv.innerHTML = escapeHTML(sender.value); + cl_finishEditField(null); + } + else { + // alert blurs!: alert("field save failed!"); // TODO: localize + // TODO: do we have beep or something? + } + return false; + } + + // TODO: we could support "tab" for jumping to the next field + return true; +} diff --git a/SOGo/UI/Templates/UIxMailContactList.wox b/SOGo/UI/Templates/UIxMailContactList.wox index f997f2bf..cac769e3 100644 --- a/SOGo/UI/Templates/UIxMailContactList.wox +++ b/SOGo/UI/Templates/UIxMailContactList.wox @@ -21,6 +21,19 @@ var:queryDictionary="queryParameters" --> + + @@ -88,17 +101,29 @@ - + - + + + +