View | Details | Raw Unified | Return to bug 26546
Collapse All | Expand All

(-)umc/widgets/TimeBox.js (+122 lines)
Line 0    Link Here 
1
/*
2
 * Copyright 2011 Univention GmbH
3
 *
4
 * http://www.univention.de/
5
 *
6
 * All rights reserved.
7
 *
8
 * The source code of this program is made available
9
 * under the terms of the GNU Affero General Public License version 3
10
 * (GNU AGPL V3) as published by the Free Software Foundation.
11
 *
12
 * Binary versions of this program provided by Univention to you as
13
 * well as other copyrighted, protected or trademarked materials like
14
 * Logos, graphics, fonts, specific documentations and configurations,
15
 * cryptographic keys etc. are subject to a license agreement between
16
 * you and Univention and not subject to the GNU AGPL V3.
17
 *
18
 * In the case you use this program under the terms of the GNU AGPL V3,
19
 * the program is provided in the hope that it will be useful,
20
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
 * GNU Affero General Public License for more details.
23
 *
24
 * You should have received a copy of the GNU Affero General Public
25
 * License with the Debian GNU/Linux or Univention distribution in file
26
 * /usr/share/common-licenses/AGPL-3; if not, see
27
 * <http://www.gnu.org/licenses/>.
28
 */
29
/*global dojo dijit dojox umc console */
30
31
dojo.provide("umc.widgets.TimeBox");
32
33
dojo.require("dijit.form.TimeTextBox");
34
//dojo.require("dojox.string.sprintf");
35
dojo.require("umc.widgets.ContainerWidget");
36
dojo.require("umc.widgets._FormWidgetMixin");
37
dojo.require("umc.widgets._WidgetsInWidgetsMixin");
38
dojo.require("umc.tools");
39
40
dojo.declare("umc.widgets.TimeBox", [
41
	umc.widgets.ContainerWidget,
42
	umc.widgets._FormWidgetMixin,
43
	umc.widgets._WidgetsInWidgetsMixin
44
], {
45
	// the widget's class name as CSS class
46
	'class': 'umcTimeBox',
47
48
	_timeBox: null,
49
50
	sizeClass: null,
51
52
	disabled: false,
53
54
	postMixInProperties: function() {
55
		this.inherited(arguments);
56
57
		this.sizeClass = null;
58
	},
59
60
	buildRendering: function() {
61
		this.inherited(arguments);
62
63
		this._timeBox = this.adopt(dijit.form.TimeTextBox, {
64
			name: this.name,
65
			disabled: this.disabled
66
		});
67
		this.addChild(this._timeBox);
68
69
		// hook to the onChange event
70
		this.connect(this._timeBox, 'onChange', function(val) {
71
			this.onChange(this.get('value'));
72
		});
73
	},
74
75
	_dateToTime: function(dateObj) {
76
		try {
77
			return dojox.string.sprintf('%02d:%02d', dateObj.getHours(), dateObj.getMinutes());
78
		} catch(e) {
79
			return '';
80
		}
81
	},
82
83
	// return time in the format 'HH:MM'
84
	_getValueAttr: function() {
85
		return this._dateToTime(this._timeBox.get('value'));
86
	},
87
88
	_setValueAttr: function(newVal) {
89
		if (newVal && newVal instanceof Date) {
90
			newVal = this._dateToTime(newVal);
91
		}
92
		try {
93
			var parts = newVal.split(':');
94
			this._timeBox.set('value', new Date(1970, 1, 1, parseInt(parts[0], 10) || 0, parseInt(parts[1], 10) || 0));
95
		} catch(e) {
96
			console.log('ERROR: invalid time format: ' + newVal);
97
			this._timeBox.set('value', null);
98
		}
99
	},
100
101
	isValid: function() {
102
		// use the property 'valid' in case it has been set
103
		// otherwise fall back to the default
104
		if (null !== this.valid) {
105
			return this.get('valid');
106
		}
107
		return this._timeBox.isValid();
108
	},
109
110
	_setBlockOnChangeAttr: function(/*Boolean*/ value) {
111
		// execute the inherited functionality in the widget's scope
112
		umc.tools.delegateCall(this, arguments, this._timeBox);
113
	},
114
115
	_getBlockOnChangeAttr: function(/*Boolean*/ value) {
116
		// execute the inherited functionality in the widget's scope
117
		umc.tools.delegateCall(this, arguments, this._timeBox);
118
	}
119
});
120
121
122
(-)umc/widgets/DateBox.js (-7 / +14 lines)
 Lines 37-44    Link Here 
37
dojo.require("umc.widgets._WidgetsInWidgetsMixin");
37
dojo.require("umc.widgets._WidgetsInWidgetsMixin");
38
dojo.require("umc.tools");
38
dojo.require("umc.tools");
39
39
40
dojo.declare("umc.widgets.DateBox", [ 
40
dojo.declare("umc.widgets.DateBox", [
41
	umc.widgets.ContainerWidget, 
41
	umc.widgets.ContainerWidget,
42
	umc.widgets._FormWidgetMixin,
42
	umc.widgets._FormWidgetMixin,
43
	umc.widgets._WidgetsInWidgetsMixin
43
	umc.widgets._WidgetsInWidgetsMixin
44
], {
44
], {
 Lines 70-85    Link Here 
70
		this.connect(this._dateBox, 'onChange', 'onChange');
70
		this.connect(this._dateBox, 'onChange', 'onChange');
71
	},
71
	},
72
72
73
	_dateToString: function(dateObj) {
74
		return dojox.string.sprintf('%04d-%02d-%02d', dateObj.getFullYear(), dateObj.getMonth() + 1, dateObj.getDate());
75
	},
76
73
	// return ISO8601/RFC3339 format (yyyy-MM-dd) as string
77
	// return ISO8601/RFC3339 format (yyyy-MM-dd) as string
74
	_getValueAttr: function() {
78
	_getValueAttr: function() {
75
		var date = this._dateBox.get('value');
79
		var dateObj = this._dateBox.get('value');
76
		if (date && date instanceof Date) {
80
		if (dateObj && dateObj instanceof Date) {
77
			return dojox.string.sprintf('%04d-%02d-%02d', date.getFullYear(), date.getMonth() + 1, date.getDate());
81
			return this._dateToString(dateObj);
78
		}
82
		}
79
		return date;
83
		return dateObj;
80
	},
84
	},
81
85
82
	_setValueAttr: function(newVal) {
86
	_setValueAttr: function(/*String|Date*/ newVal) {
87
		if (newVal && newVal instanceof Date) {
88
			newVal = this._dateToString(newVal);
89
		}
83
		this._dateBox.set('value', newVal);
90
		this._dateBox.set('value', newVal);
84
	},
91
	},
85
92

Return to bug 26546