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