]> err.no Git - scalable-opengroupware.org/blob - UI/WebServerResources/UIxComponentEditor.js
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1174 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / UI / WebServerResources / UIxComponentEditor.js
1 function onPopupAttendeesWindow(event) {
2    if (event)
3       preventDefault(event);
4    window.open(ApplicationBaseURL + "/editAttendees", null, 
5                "width=803,height=573");
6
7    return false;
8 }
9
10 function onSelectPrivacy(event) {
11    if (event.button == 0 || (isSafari() && event.button == 1)) {
12       var node = getTarget(event);
13       if (node.tagName != 'A')
14         node = $(node).getParentWithTagName("a");
15       node = $(node).childNodesWithTag("span")[0];
16       popupToolbarMenu(node, "privacy-menu");
17       Event.stop(event);
18 //       preventDefault(event);
19    }
20 }
21
22 function onPopupUrlWindow(event) {
23    if (event)
24       preventDefault(event);
25
26    var urlInput = document.getElementById("url");
27    var newUrl = window.prompt(labels["Target:"], urlInput.value);
28    if (newUrl != null) {
29       var documentHref = $("documentHref");
30       var documentLabel = $("documentLabel");
31       if (documentHref.childNodes.length > 0) {
32          documentHref.childNodes[0].nodeValue = newUrl;
33          if (newUrl.length > 0)
34             documentLabel.setStyle({ display: "block" });
35          else
36             documentLabel.setStyle({ display: "none" });
37       }
38       else {
39          documentHref.appendChild(document.createTextNode(newUrl)); 
40          if (newUrl.length > 0)
41             documentLabel.setStyle({ display: "block" });
42       }
43       urlInput.value = newUrl;
44    }
45
46    return false;
47 }
48
49 function onPopupDocumentWindow(event) {
50    var documentUrl = $("url");
51
52    preventDefault(event);
53    window.open(documentUrl.value, "SOGo_Document");
54
55    return false;
56 }
57
58 function onMenuSetClassification(event) {
59    event.cancelBubble = true;
60
61    var classification = this.getAttribute("classification");
62    if (this.parentNode.chosenNode)
63       this.parentNode.chosenNode.removeClassName("_chosen");
64    this.addClassName("_chosen");
65    this.parentNode.chosenNode = this;
66
67 //    log("classification: " + classification);
68    var privacyInput = document.getElementById("privacy");
69    privacyInput.value = classification;
70 }
71
72 function onChangeCalendar(event) {
73    var calendars = $("calendarFoldersList").value.split(",");
74    var form = document.forms["editform"];
75    var urlElems = form.getAttribute("action").split("/");
76    var choice = calendars[this.value];
77    var ownerLogin;
78    if (choice.indexOf(":") > -1)
79       ownerLogin = choice.split(":")[0];
80    else
81       ownerLogin = UserLogin;
82    urlElems[urlElems.length-4] = ownerLogin;
83
84    form.setAttribute("action", urlElems.join("/"));
85 }
86
87 function refreshAttendees() {
88    var attendeesLabel = $("attendeesLabel");
89    var attendeesNames = $("attendeesNames");
90    var attendeesHref = $("attendeesHref");
91
92    for (var i = 0; i < attendeesHref.childNodes.length; i++)
93      attendeesHref.removeChild(attendeesHref.childNodes[i]);
94
95    if (attendeesNames.value.length > 0) {
96       attendeesHref.appendChild(document.createTextNode(attendeesNames.value));
97       attendeesLabel.setStyle({ display: "block" });
98    }
99    else
100       attendeesLabel.setStyle({ display: "none" });
101 }
102
103 function initializeAttendeesHref() {
104    var attendeesHref = $("attendeesHref");
105    var attendeesLabel = $("attendeesLabel");
106    var attendeesNames = $("attendeesNames");
107
108    Event.observe(attendeesHref, "click", onPopupAttendeesWindow, false);
109    if (attendeesNames.value.length > 0) {
110       attendeesHref.setStyle({ textDecoration: "underline", color: "#00f" });
111       attendeesHref.appendChild(document.createTextNode(attendeesNames.value));
112       attendeesLabel.setStyle({ display: "block" });
113    }
114 }
115
116 function initializeDocumentHref() {
117    var documentHref = $("documentHref");
118    var documentLabel = $("documentLabel");
119    var documentUrl = $("url");
120
121    Event.observe(documentHref, "click", onPopupDocumentWindow, false);
122    documentHref.setStyle({ textDecoration: "underline", color: "#00f" });
123    if (documentUrl.value.length > 0) {
124       documentHref.appendChild(document.createTextNode(documentUrl.value));
125       documentLabel.setStyle({ display: "block" });
126    }
127
128    var changeUrlButton = $("changeUrlButton");
129    Event.observe(changeUrlButton, "click", onPopupUrlWindow, false);
130 }
131
132 function initializePrivacyMenu() {
133    var privacy = $("privacy").value.toUpperCase();
134    if (privacy.length > 0) {
135       var privacyMenu = $("privacy-menu").childNodesWithTag("ul")[0];
136       var menuEntries = $(privacyMenu).childNodesWithTag("li");
137       var chosenNode;
138       if (privacy == "CONFIDENTIAL")
139          chosenNode = menuEntries[1];
140       else if (privacy == "PRIVATE")
141          chosenNode = menuEntries[2];
142       else
143          chosenNode = menuEntries[0];
144       privacyMenu.chosenNode = chosenNode;
145       $(chosenNode).addClassName("_chosen");
146    }
147 }
148
149 function onComponentEditorLoad(event) {
150    if (!$("statusPercent"))
151       initializeAttendeesHref();
152    initializeDocumentHref();
153    initializePrivacyMenu();
154    var list = $("calendarList");
155    Event.observe(list, "mousedown",
156                  onChangeCalendar.bindAsEventListener(list),
157                  false);
158    if (document.createEvent) {
159      var onSelectionChangeEvent;
160       if (isSafari())
161         onSelectionChangeEvent = document.createEvent("UIEvents");
162       else
163         onSelectionChangeEvent = document.createEvent("Events");
164       onSelectionChangeEvent.initEvent("mousedown", false, false);
165      list.dispatchEvent(onSelectionChangeEvent);
166    }
167    else {
168      list.fireEvent("onmousedown"); // IE
169    }
170
171    var menuItems = $("itemPrivacyList").childNodesWithTag("li");
172    for (var i = 0; i < menuItems.length; i++)
173       Event.observe(menuItems[i], "mousedown",
174                     onMenuSetClassification.bindAsEventListener(menuItems[i]),
175                     false);
176 }
177
178 addEvent(window, 'load', onComponentEditorLoad);