File: UIxComponentEditor.js

package info (click to toggle)
sogo 2.2.9%2Bgit20141017-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 43,812 kB
  • sloc: objc: 115,592; python: 5,696; sh: 1,380; perl: 861; makefile: 240; xml: 114; sql: 53; php: 43
file content (415 lines) | stat: -rw-r--r-- 12,891 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

var ComponentEditor = {
    attendeesWindow: null,
    recurrenceWindow: null,
    reminderWindow: null
};

function getOwnerLogin() {
    return ownerLogin;
}

function getCalendarOwner() {
    var ownerProfile;

    if (typeof organizer == "undefined") {
        var calendarIndex = $("calendarList").value;
        var ownersList = owners[0];
        var profiles = owners[1];
        var ownerUid = ownersList[calendarIndex];
        ownerProfile = profiles[ownerUid];
        ownerProfile["uid"] = ownerUid;
    }
    else {
        ownerProfile = organizer;
    }
    
    return ownerProfile;
}

function onPopupAttendeesWindow(event) {
    if (event)
        preventDefault(event);
    if (ComponentEditor.attendeesWindow && ComponentEditor.attendeesWindow.open && !ComponentEditor.attendeesWindow.closed)
        ComponentEditor.attendeesWindow.focus();
    else
        ComponentEditor.attendeesWindow = window.open(ApplicationBaseURL + "/editAttendees",
                                                      sanitizeWindowName(activeCalendar + activeComponent + "Attendees"),
                                                      "width=900,height=573");
    
    return false;
}

function onSelectClassification(event) {
    if (event.button == 0 || (isWebKit() && event.button == 1)) {
        var node = getTarget(event);
        if (node.tagName != 'A')
            node = $(node).up("A");
        popupToolbarMenu(node, "classification-menu");
        Event.stop(event);
    }
}

function onPopupAttachWindow(event) {
    if (event)
        preventDefault(event);

    var attachInput = $("attach");
    var newAttach = window.prompt(_("Target:"), attachInput.value || "http://");
    if (newAttach != null) {
        var documentHref = $("documentHref");
        var documentLabel = $("documentLabel");
        if (documentHref.childNodes.length > 0) {
            documentHref.childNodes[0].nodeValue = newAttach;
            if (newAttach.length > 0)
                documentLabel.setStyle({ display: "block" });
            else
                documentLabel.setStyle({ display: "none" });
        }
        else {
            documentHref.appendChild(document.createTextNode(newAttach)); 
            if (newAttach.length > 0)
                documentLabel.setStyle({ display: "block" });
        }
        attachInput.value = newAttach;
    }
    onWindowResize(event);
  
    return false;
}

function onPopupDocumentWindow(event) {
    var documentUrl = $("attach");

    preventDefault(event);
    window.open(documentUrl.value, "SOGo_Document");

    return false;
}

function onMenuSetClassification(event) {
    event.cancelBubble = true;

    var classification = this.getAttribute("classification");
    if (this.parentNode.chosenNode)
        this.parentNode.chosenNode.removeClassName("_chosen");
    this.addClassName("_chosen");
    this.parentNode.chosenNode = this;

    var classificationInput = $("classification");
    classificationInput.value = classification;
}

function onChangeCalendar(event) {
    var calendars = $("calendarFoldersList").value.split(",");
    var form = document.forms["editform"];
    var urlElems = form.getAttribute("action").split("?");
    var choice = calendars[this.value];
    var urlParam = "moveToCalendar=" + choice;
    if (urlElems.length == 1)
        urlElems.push(urlParam);
    else
        urlElems[2] = urlParam;

    while (urlElems.length > 2)
        urlElems.pop();

    form.setAttribute("action", urlElems.join("?"));
}

function initializeDocumentHref() {
    var documentHref = $("documentHref");
    var documentLabel = $("documentLabel");
    var documentUrl = $("attach");

    documentHref.on("click", onPopupDocumentWindow, false);
    if (documentUrl.value.length > 0) {
        documentHref.appendChild(document.createTextNode(documentUrl.value));
        documentLabel.setStyle({ display: "block" });
    }

    var changeUrlButton = $("changeAttachButton");
    if (changeUrlButton)
        changeUrlButton.on("click", onPopupAttachWindow, false);
}

function initializeClassificationMenu() {
    if ($("classification-menu")) {
        var classification = $("classification").value.toUpperCase();
        var classificationMenu = $("classification-menu").childNodesWithTag("ul")[0];
        var menuEntries = $(classificationMenu).childNodesWithTag("li");
        var chosenNode;
        if (classification == "CONFIDENTIAL")
            chosenNode = menuEntries[1];
        else if (classification == "PRIVATE")
            chosenNode = menuEntries[2];
        else
            chosenNode = menuEntries[0];
        classificationMenu.chosenNode = chosenNode;
        $(chosenNode).addClassName("_chosen");
    }
}

function findAttendeeWithFieldValue(field, fieldValue) {
    var foundAttendee = null;

    var attendeesKeys = attendees.keys();
    for (var i = 0; !foundAttendee && i < attendeesKeys.length; i++) {
        var attendee = attendees.get(attendeesKeys[i]);
        if (attendee[field] == fieldValue) {
            foundAttendee = attendee;
        }
    }

    return foundAttendee;
}

function findDelegateAddress() {
    var delegateAddress = null;

    var ownerAttendee = findAttendeeWithFieldValue("uid", ownerLogin);
    if (ownerAttendee && ownerAttendee["delegated-to"]) {
        var delegateAttendee
            = findAttendeeWithFieldValue("email",
                                         ownerAttendee["delegated-to"]);
        if (delegateAttendee) {
            if (delegateAttendee["name"]) {
                delegateAddress = (delegateAttendee["name"]
                                   + " <" + delegateAttendee["email"] + ">");
            }
            else {
                delegateAddress = delegateAttendee["email"];
            }
        }
    }

    return delegateAddress;
}

function onComponentEditorLoad(event) {
    initializeDocumentHref();
    initializeClassificationMenu();
    var list = $("calendarList");
    if (list) {
        list.on("change", onChangeCalendar);
        list.fire("mousedown");
    }
    
    var tmp = $("itemClassificationList");
    if (tmp) {
        var menuItems = tmp.childNodesWithTag("li");
        for (var i = 0; i < menuItems.length; i++)
            menuItems[i].on("mousedown", onMenuSetClassification);
    }

    tmp = $("replyList");
    if (tmp) {
        tmp.on("change", onReplyChange);
        var isDelegated = (tmp.value == 4);
        tmp = $("delegatedTo");
        tmp.addInterface(SOGoAutoCompletionInterface);
        tmp.uidField = "c_mail";
        tmp.excludeGroups = true;
        var delegateEditor = $("delegateEditor");
        tmp.animationParent = delegateEditor;
        if (isDelegated) {
            var delegateAddress = findDelegateAddress();
            if (delegateAddress) {
                tmp.value = delegateAddress;
            }
            delegateEditor.show();
        }
     }

    tmp = $("repeatHref");
    if (tmp)
        tmp.on("click", onPopupRecurrenceWindow);
    tmp = $("repeatList");
    if (tmp)
        tmp.on("change", onPopupRecurrenceWindow);
    tmp = $("reminderHref");
    if (tmp)
        tmp.on("click", onPopupReminderWindow);
    tmp = $("reminderList");
    if (tmp)
        tmp.on("change", onPopupReminderWindow);
    tmp = $("summary");
    if (tmp)
        tmp.on("keyup", onSummaryChange);
    
    Event.on(window, "resize", onWindowResize);
    Event.on(window, "beforeunload", onComponentEditorClose);
    
    onPopupRecurrenceWindow(null);
    onPopupReminderWindow(null);
    onSummaryChange (null);
    
    var summary = $("summary");
    if (summary) {
  	summary.focus();
        summary.selectText(0, summary.value.length);
    }
    
    tmp = $("okButton");
    if (tmp)
        tmp.on ("click", onOkButtonClick);
    tmp = $("cancelButton");
    if (tmp)
        tmp.on ("click", onCancelButtonClick);
}

function onSummaryChange (e) {
    if ($("summary"))
        document.title = $("summary").value;
}

function onReplyChange(event) {
    var delegateEditor = $("delegateEditor");
    if (this.value == 4) {
        // Delegated
        delegateEditor.show();
        $("delegatedTo").focus();
    }
    else {
        delegateEditor.hide();
    }
    onWindowResize(null);

    return true;
}

function onComponentEditorClose(event) {
    if (ComponentEditor.attendeesWindow && ComponentEditor.attendeesWindow.open && !ComponentEditor.attendeesWindow.closed)
        ComponentEditor.attendeesWindow.close();
    if (ComponentEditor.recurrenceWindow && ComponentEditor.recurrenceWindow.open && !ComponentEditor.recurrenceWindow.closed)
        ComponentEditor.recurrenceWindow.close();
    if (ComponentEditor.reminderWindow && ComponentEditor.reminderWindow.open && !ComponentEditor.reminderWindow.closed)
        ComponentEditor.reminderWindow.close();
}

function onWindowResize(event) {
    var comment = $("commentArea");
    if (comment) {
        // Resize comment area of read-write component
        var document = $("documentLabel");
        var area = comment.select("textarea").first();
        var offset = 6;
        var height;
        
        height = window.height() - comment.cumulativeOffset().top - offset;
        
        if (document.visible()) {
            // Component has an attachment
            if ($("changeAttachButton"))
                height -= $("changeAttachButton").getHeight();
            else
                height -= $("documentHref").getHeight();
        }
        
        if (area)
            area.setStyle({ height: (height - offset*2) + "px" });

        comment.setStyle({ height: (height - offset) + "px" });
    }
    else {
        // Resize attendees area of a read-only component
        $("eventView").style.height = window.height () + "px";
        var height = window.height() - 120;
        var tmp = $("generalDiv");
        if (tmp)
            height -= tmp.offsetHeight;
        tmp = $("descriptionDiv");
        if (tmp)
            height -= tmp.offsetHeight;
        
        tmp = $("attendeesDiv");
        if (tmp) {
            tmp.style.height = height + "px";
            $("attendeesMenu").style.height = (height - 20) + "px";
        }
    }
    
    return true;
}

function onPopupRecurrenceWindow(event) {
    if (event)
        preventDefault(event);
    
    var repeatHref = $("repeatHref");
    
    var repeatList = $("repeatList");
    if (repeatList && repeatList.value == 7) {
        // Custom repeat rule
        repeatHref.show();
        if (event) {
            if (ComponentEditor.recurrenceWindow && ComponentEditor.recurrenceWindow.open && !ComponentEditor.recurrenceWindow.closed)
                ComponentEditor.recurrenceWindow.focus();
            else
                ComponentEditor.recurrenceWindow = window.open(ApplicationBaseURL + "/editRecurrence",
                                                               sanitizeWindowName(activeCalendar + activeComponent + "Recurrence"),
                                                               "width=500,height=400");
        }
    }
    else if (repeatHref)
        repeatHref.hide();
    
    return false;
}

function onPopupReminderWindow(event) {
    if (event)
        preventDefault(event);

    var reminderHref = $("reminderHref");

    var reminderList = $("reminderList");
    if (reminderList && reminderList.value == 15) {
        reminderHref.show();
        if (event) {
            if (ComponentEditor.reminderWindow && ComponentEditor.reminderWindow.open && !ComponentEditor.reminderWindow.closed)
                ComponentEditor.reminderWindow.focus();
            else {
                var height = (emailAlarmsEnabled ? 235 : 150);
                ComponentEditor.reminderWindow
                    = window.open(ApplicationBaseURL + "/editReminder",
                                  sanitizeWindowName(activeCalendar + activeComponent + "Reminder"),
                                  "width=255,height=" + height);
            }
        }
    }
    else if (reminderHref)
        reminderHref.hide();

    return false;
}

function onOkButtonClick (e) {
    var item = $("replyList");
    var value = parseInt(item.options[item.selectedIndex].value);
    var action = "";
    var parameters = "";
  
    if (value == 0)
        action = 'accept';
    else if (value == 1)
        action = 'decline';
    else if (value == 2)
        action = 'needsaction';
    else if (value == 3)
        action = 'tentative';
    else if (value == 4) {
        var url = ApplicationBaseURL + "/" + activeCalendar + "/" + activeComponent;
        delegateInvitation(url, modifyEventCallback);
    }

    if (action != "")
        modifyEvent (item, action, parameters);
}

function onCancelButtonClick (e) {
    window.close ();
}

document.on("dom:loaded", onComponentEditorLoad);