1 // (c) Benoît PIN 2006-2007
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"));
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();};
23 // init event handler to show full metadata form
24 var showFullMetadataForm = function(evt
) {
26 disablePropagation(evt
);
28 var initFullMetadataForm = function () {
29 var metadataForm
= inspector
.contentNode
.getElementsByTagName('FORM')[0];
30 var fm
= new FormManager(metadataForm
);
31 fm
.onResponseLoad = function(){inspector
.collapse();};
33 addListener(document
.getElementById('showSimpleMetadataForm'),
35 function(evt
){inspector
.expand(); disableDefault(evt
); disablePropagation(evt
);});
37 var fi
= new FragmentImporter(absolute_url(), initFullMetadataForm
);
38 fi
.useMacro('header_widgets', 'fullMetadataForm', 'HeaderArea');
40 addListener(document
.getElementById('showFullMetadataForm'), 'click', showFullMetadataForm
);
42 var fi
= new FragmentImporter(ob_url
, onAfterPopulate
);
43 fi
.useMacro('header_widgets', 'titleAndDescForm', 'HeaderArea');
46 metadataInspector
.onCollapse = function(inspector
) {
47 var fi
= new FragmentImporter(ob_url
);
48 fi
.useMacro('header_widgets', 'viewTitleAndDesc', 'HeaderArea');
53 function MetadataDateManager(baseFieldName
, defaultDate
) {
54 var thisManager
= this;
55 this.baseFieldName
= baseFieldName
;
56 this.defaultDate
= defaultDate
;
57 this._previousDate
= new Date();
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
;
72 Calendar
.setup(calConfig
);
74 //init event listener on checkbox
75 var cb
= document
.getElementById(baseFieldName
+ "_cb");
77 addListener(cb
, 'click', function(){thisManager
.toggleDisplay();});
78 if ( this.builDateFromInputs().valueOf() == this.defaultDate
.valueOf() ) {
79 document
.getElementById(baseFieldName
+ "_fields").style
.display
= "none";
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
;
93 if ( (year
&& month
&& day
&& hour
&& minute
) != "" ) {
94 var dateStr
= month
+ "/" + day
+ "/" + year
+ " " + hour
+ ":" + minute
+ ":00";
95 return new Date(dateStr
) ;
101 MetadataDateManager
.prototype.splitDate = function(calendar
, date
) {
102 var inputId
= (typeof calendar
== "string") ? this.baseFieldName
: calendar
.params
['inputField'].id
;
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
);
118 tokens
= date
.split(" ");
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];
128 MetadataDateManager
.prototype.toggleDisplay = function() {
129 var cb
= document
.getElementById(this.baseFieldName
+ '_cb');
130 var fields
= document
.getElementById(this.baseFieldName
+ '_fields');
132 fields
.style
.display
= "none";
133 this._previousDate
= this.builDateFromInputs();
134 this.splitDate('', this.defaultDate
)
137 this.splitDate('', this._previousDate
);
138 fields
.style
.display
= "block";