]> err.no Git - scalable-opengroupware.org/blob - UI/WebServerResources/UIxComponentEditor.js
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1265 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
85    for (var i = 0; i < attendeesHref.childNodes.length; i++)
86      attendeesHref.removeChild(attendeesHref.childNodes[i]);
87
88    if (attendeesNames.value.length > 0) {
89       attendeesHref.appendChild(document.createTextNode(attendeesNames.value));
90       attendeesLabel.setStyle({ display: "block" });
91    }
92    else
93       attendeesLabel.setStyle({ display: "none" });
94 }
95
96 function initializeAttendeesHref() {
97    var attendeesHref = $("attendeesHref");
98    var attendeesLabel = $("attendeesLabel");
99    var attendeesNames = $("attendeesNames");
100
101    Event.observe(attendeesHref, "click", onPopupAttendeesWindow, false);
102    if (attendeesNames.value.length > 0) {
103       attendeesHref.setStyle({ textDecoration: "underline", color: "#00f" });
104       attendeesHref.appendChild(document.createTextNode(attendeesNames.value));
105       attendeesLabel.setStyle({ display: "block" });
106    }
107 }
108
109 function initializeDocumentHref() {
110    var documentHref = $("documentHref");
111    var documentLabel = $("documentLabel");
112    var documentUrl = $("url");
113
114    Event.observe(documentHref, "click", onPopupDocumentWindow, false);
115    documentHref.setStyle({ textDecoration: "underline", color: "#00f" });
116    if (documentUrl.value.length > 0) {
117       documentHref.appendChild(document.createTextNode(documentUrl.value));
118       documentLabel.setStyle({ display: "block" });
119    }
120
121    var changeUrlButton = $("changeUrlButton");
122    Event.observe(changeUrlButton, "click", onPopupUrlWindow, false);
123 }
124
125 function initializePrivacyMenu() {
126    var privacy = $("privacy").value.toUpperCase();
127    if (privacy.length > 0) {
128       var privacyMenu = $("privacy-menu").childNodesWithTag("ul")[0];
129       var menuEntries = $(privacyMenu).childNodesWithTag("li");
130       var chosenNode;
131       if (privacy == "CONFIDENTIAL")
132          chosenNode = menuEntries[1];
133       else if (privacy == "PRIVATE")
134          chosenNode = menuEntries[2];
135       else
136          chosenNode = menuEntries[0];
137       privacyMenu.chosenNode = chosenNode;
138       $(chosenNode).addClassName("_chosen");
139    }
140 }
141
142 function onComponentEditorLoad(event) {
143    if (!$("statusPercent"))
144       initializeAttendeesHref();
145    initializeDocumentHref();
146    initializePrivacyMenu();
147    var list = $("calendarList");
148    Event.observe(list, "mousedown",
149                  onChangeCalendar.bindAsEventListener(list),
150                  false);
151    list.fire("mousedown");
152
153    var menuItems = $("itemPrivacyList").childNodesWithTag("li");
154    for (var i = 0; i < menuItems.length; i++)
155       Event.observe(menuItems[i], "mousedown",
156                     onMenuSetClassification.bindAsEventListener(menuItems[i]),
157                     false);
158 }
159
160 FastInit.addOnLoad(onComponentEditorLoad);