File: UIxCalendarProperties.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 (121 lines) | stat: -rw-r--r-- 3,517 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
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

function onLoadCalendarProperties() {
    var tabsContainer = $("propertiesTabs");
    var controller = new SOGoTabsController();
    controller.attachToTabsContainer(tabsContainer);

    var colorButton = $("colorButton");
    var calendarColor = $("calendarColor");
    colorButton.setStyle({ "backgroundColor": colorButton.readAttribute('data-color') });
    colorButton.observe("click", onColorClick);
    
    $('colorPickerDialog').on('click', 'span', onColorPickerChoice);
    $(document.body).on("click", onBodyClickHandler);

    var cancelButton = $("cancelButton");
    cancelButton.observe("click", onCancelClick);
    
    var okButton = $("okButton");
    okButton.observe("click", onOKClick);
  
    Event.observe(document, "keydown", onDocumentKeydown);
}

function onDocumentKeydown(event) {
  var target = Event.element(event);
  if (target.tagName == "INPUT" || target.tagName == "SELECT") {
    if (event.keyCode == Event.KEY_RETURN) {
      onOKClick(event);
    }
  }
  if (event.keyCode == Event.KEY_ESC) {
    onCancelClick();
  }
}

function onCancelClick(event) {
    window.close();
}

function onOKClick(event) {
  var calendarName = $("calendarName");
  var calendarColor = $("calendarColor");
  var calendarID = $("calendarID");
  var save = true;
  var tag = $("calendarSyncTag");
  var originalTag = $("originalCalendarSyncTag");
  var allTags = $("allCalendarSyncTags");

  if (calendarName.value.blank()) {
      alert(_("Please specify a calendar name."));
      save = false;
  }

  if (save
      && allTags)
      allTags = allTags.value.split(",");
  
  if (save
      && tag
      && $("synchronizeCalendar").checked) {
      if (tag.value.blank()) {
          alert(_("tagNotDefined"));
          save = false;
      }
      else if (allTags
               && allTags.indexOf(tag.value) > -1) {
          alert(_("tagAlreadyExists"));
          save = false;
      }
      else if (originalTag
               && !originalTag.value.blank()) {
          if (tag.value != originalTag.value)
              save = confirm(_("tagHasChanged"));
      }
      else
          save = confirm(_("tagWasAdded"));
  }
  else if (save
           && originalTag
           && !originalTag.value.blank())
      save = confirm(_("tagWasRemoved"));
  
  if (save) {
      window.opener.updateCalendarProperties(calendarID.value,
                                             calendarName.value,
                                             calendarColor.value);
      $("propertiesform").submit();
  }
  else
      Event.stop(event);
}

function onBodyClickHandler(event) {
    var target = getTarget(event);
    if (!target.hasClassName('colorBox'))
        $("colorPickerDialog").hide();
}

function onColorClick(event) {
    var cellPosition = this.cumulativeOffset();
    var cellDimensions = this.getDimensions();
    var div = $('colorPickerDialog');
    var divDimensions = div.getDimensions();
    var left = cellPosition[0] + cellDimensions["width"] + 4;
    var top = cellPosition[1] - 5;
    div.setStyle({ left: left + "px", top: top + "px" });
    div.show();

    preventDefault(event);
}

function onColorPickerChoice(event) {
    var span = getTarget(event);
    var newColor = "#" + span.className.substr(4);
    var colorButton = $("colorButton");
    colorButton.setStyle({ "backgroundColor": newColor });
    $("calendarColor").value = newColor;
}

document.observe("dom:loaded", onLoadCalendarProperties);