Ajout classes pour bordure et fond standards.
[Plinn.git] / skins / ajax_scripts / generic_header_script.js
1 // (c) BenoƮt PIN 2006-2007
2 // http://plinn.org
3 // Licence GPL
4 //
5 //
6
7
8 function initHeaderScript() {
9 var toggleButton = document.getElementById("ToggleFormButton");
10 if (!toggleButton) return;
11 var ob_url = absolute_url();
12 var metadataInspector = new InspectorPalette(portal_url(),
13 document.getElementById("ToggleFormButton").childNodes[0],
14 document.getElementById("HeaderArea"));
15
16 metadataInspector.onExpand = function(inspector) {
17 var onAfterPopulate = function() {
18 // init simple metadata form manager
19 var metadataForm = inspector.contentNode.getElementsByTagName('FORM')[0];
20 var fm = new FormManager(metadataForm);
21 fm.onResponseLoad = function(){inspector.collapse();};
22
23 // init event handler to show full metadata form
24 var showFullMetadataForm = function(evt) {
25 disableDefault(evt);
26 disablePropagation(evt);
27
28 var initFullMetadataForm = function () {
29 var metadataForm = inspector.contentNode.getElementsByTagName('FORM')[0];
30 var fm = new FormManager(metadataForm);
31 fm.onResponseLoad = function(){inspector.collapse();};
32
33 addListener(document.getElementById('showSimpleMetadataForm'),
34 'click',
35 function(evt){inspector.expand(); disableDefault(evt); disablePropagation(evt);});
36 };
37 var fi = new FragmentImporter(absolute_url(), initFullMetadataForm);
38 fi.useMacro('header_widgets', 'fullMetadataForm', 'HeaderArea');
39 };
40 addListener(document.getElementById('showFullMetadataForm'), 'click', showFullMetadataForm);
41 };
42 var fi = new FragmentImporter(ob_url, onAfterPopulate);
43 fi.useMacro('header_widgets', 'titleAndDescForm', 'HeaderArea');
44 };
45
46 metadataInspector.onCollapse = function(inspector) {
47 var fi = new FragmentImporter(ob_url);
48 fi.useMacro('header_widgets', 'viewTitleAndDesc', 'HeaderArea');
49 };
50 }
51
52
53 function MetadataDateManager(baseFieldName, defaultDate) {
54 var thisManager = this;
55 this.baseFieldName = baseFieldName;
56 this.defaultDate = defaultDate;
57 this._previousDate = new Date();
58
59 var calConfig = [];
60 // setup js calendar
61 calConfig["inputField"] = baseFieldName; // id of the input field
62 calConfig["ifFormat"] = "%Y %m %d %H %M"; // format of the input field
63 calConfig["date"] = function() { return thisManager.builDateFromInputs(); };
64 calConfig["showsTime"] = true; // will display a time selector
65 calConfig["button"] = "show_" + baseFieldName + "_cal"; // trigger for the calendar (button ID)
66 calConfig["singleClick"] = false; // double-click mode
67 calConfig["showOthers"] = true; // show overlapping months
68 calConfig["weekNumbers"] = false;
69 calConfig["firstDay"] = 1;
70 calConfig["onSelect"] = thisManager.splitDate;
71
72 Calendar.setup(calConfig);
73
74 //init event listener on checkbox
75 var cb = document.getElementById(baseFieldName + "_cb");
76 if (cb) {
77 addListener(cb, 'click', function(){thisManager.toggleDisplay();});
78 if ( this.builDateFromInputs().valueOf() == this.defaultDate.valueOf() ) {
79 document.getElementById(baseFieldName + "_fields").style.display = "none";
80 cb.checked = true;
81 }
82 }
83 }
84
85 MetadataDateManager.prototype.builDateFromInputs = function() {
86 var baseFieldName = this.baseFieldName;
87 var year = document.getElementById(baseFieldName + "_year").value;
88 var month = document.getElementById(baseFieldName + "_month").value;
89 var day = document.getElementById(baseFieldName + "_day").value;
90 var hour = document.getElementById(baseFieldName + "_hour").value;
91 var minute = document.getElementById(baseFieldName + "_minute").value;
92
93 if ( (year && month && day && hour && minute) != "" ) {
94 var dateStr = month + "/" + day + "/" + year + " " + hour + ":" + minute + ":00";
95 return new Date(dateStr) ;
96 }
97 else
98 return new Date();
99 };
100
101 MetadataDateManager.prototype.splitDate = function(calendar, date) {
102 var inputId = (typeof calendar == "string") ? this.baseFieldName : calendar.params['inputField'].id;
103
104 var tokens;
105 if (typeof date == "object") {
106 tokens = new Array(5);
107 tokens[0] = String( date.getFullYear() );
108 var month = date.getMonth() +1;
109 tokens[1] = (month <10) ? "0" + String(month) : String(month);
110 var day = date.getDate()
111 tokens[2] = (day < 10) ? "0" + String(day) : String(day);
112 var hours = date.getHours();
113 tokens[3] = (hours < 10) ? "0" + String(hours) : String(hours);
114 var minutes = date.getMinutes();
115 tokens[4] = (minutes < 10) ? "0" + String(minutes) : String(minutes);
116 }
117 else
118 tokens = date.split(" ");
119
120 document.getElementById(inputId + "_year").value = tokens[0];
121 document.getElementById(inputId + "_month").value = tokens[1];
122 document.getElementById(inputId + "_day").value = tokens[2];
123 document.getElementById(inputId + "_hour").value = tokens[3];
124 document.getElementById(inputId + "_minute").value = tokens[4];
125 };
126
127
128 MetadataDateManager.prototype.toggleDisplay = function() {
129 var cb = document.getElementById(this.baseFieldName + '_cb');
130 var fields = document.getElementById(this.baseFieldName + '_fields');
131 if (cb.checked) {
132 fields.style.display = "none";
133 this._previousDate = this.builDateFromInputs();
134 this.splitDate('', this.defaultDate)
135 }
136 else {
137 this.splitDate('', this._previousDate);
138 fields.style.display = "block";
139 }
140 };