Bug 978547 - [Clock] JavaScript functions should not rely on presence an... #18342
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,8 +47,12 @@ var AlarmEdit = function() { | |
|
||
this.buttons.time = new FormButton(this.selects.time, { | ||
formatLabel: function(value) { | ||
var time = Utils.parseTime(value); | ||
return Utils.format.time(time.hour, time.minute); | ||
var date = new Date(); | ||
// This split(':') is locale-independent per HTML5 <input type=time> | ||
var splitValue = value.split(':'); | ||
date.setHours(splitValue[0]); | ||
date.setMinutes(splitValue[1]); | ||
return Utils.getLocalizedTimeText(date); | ||
}.bind(this) | ||
}); | ||
this.buttons.repeat = new FormButton(this.selects.repeat, { | ||
|
@@ -69,6 +73,9 @@ var AlarmEdit = function() { | |
} | ||
}); | ||
|
||
this.scrollList = this.element.querySelector('#edit-alarm'); | ||
this.sundayListItem = this.element.querySelector('#repeat-select-sunday'); | ||
|
||
// When the system pops up the ValueSelector, it inadvertently | ||
// messes with the scrollTop of the current panel. This is a | ||
// workaround for bug 981255 until the Edit panel becomes a new | ||
|
@@ -104,47 +111,9 @@ var AlarmEdit = function() { | |
|
||
AlarmEdit.prototype = Object.create(Panel.prototype); | ||
|
||
var selectors = { | ||
scrollList: '#edit-alarm', | ||
labelInput: 'input[name="alarm.label"]', | ||
timeSelect: '#time-select', | ||
timeMenu: '#time-menu', | ||
alarmTitle: '#alarm-title', | ||
repeatMenu: '#repeat-menu', | ||
repeatSelect: '#repeat-select', | ||
sundayListItem: '#repeat-select-sunday', | ||
soundMenu: '#sound-menu', | ||
soundSelect: '#sound-select', | ||
snoozeMenu: '#snooze-menu', | ||
snoozeSelect: '#snooze-select', | ||
deleteButton: '#alarm-delete', | ||
backButton: '#alarm-close', | ||
doneButton: '#alarm-done' | ||
}; | ||
Object.keys(selectors).forEach(function(attr) { | ||
var selector = selectors[attr]; | ||
Object.defineProperty(AlarmEdit.prototype, attr, { | ||
get: function() { | ||
var element = this.element.querySelector(selector); | ||
Object.defineProperty(this, attr, { | ||
value: element | ||
}); | ||
return element; | ||
}, | ||
configurable: true | ||
}); | ||
}); | ||
|
||
Utils.extend(AlarmEdit.prototype, { | ||
|
||
alarm: null, | ||
alarmRef: null, | ||
timePicker: { | ||
hour: null, | ||
minute: null, | ||
hour24State: null, | ||
is12hFormat: false | ||
}, | ||
ringtonePlayer: AudioManager.createAudioPlayer(), | ||
|
||
handleNameInput: function(evt) { | ||
|
@@ -249,15 +218,19 @@ Utils.extend(AlarmEdit.prototype, { | |
}, | ||
|
||
initTimeSelect: function aev_initTimeSelect() { | ||
// The format of input type="time" should be in HH:MM | ||
var opts = { meridian: false, padHours: true }; | ||
var time = Utils.format.time(this.alarm.hour, this.alarm.minute, opts); | ||
this.buttons.time.value = time; | ||
// HTML5 <input type=time> expects 24-hour HH:MM format. | ||
var hour = parseInt(this.alarm.hour, 10); | ||
var minute = parseInt(this.alarm.minute, 10); | ||
this.selects.time.value = (hour < 10 ? '0' : '') + hour + | ||
':' + (minute < 10 ? '0' : '') + minute; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it would be good if we reused some There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe we even do |
||
}, | ||
|
||
getTimeSelect: function aev_getTimeSelect() { | ||
return Utils.parseTime(this.selects.time.value); | ||
// HTML5 <input type=time> returns data in 24-hour HH:MM format. | ||
var splitTime = this.selects.time.value.split(':'); | ||
return { hour: splitTime[0], minute: splitTime[1] }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why did you decide to remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. uhm.. I was just looking the reason why the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree; in the interest of time, I'm going to push that forward to a future commit -- I'd like to get rid of many of these helper functions in the views which are only used once to return the value; perhaps getting rid of all of these at once. |
||
}, | ||
|
||
initRepeatSelect: function aev_initRepeatSelect() { | ||
this.buttons.repeat.value = this.alarm.repeat; | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,9 +113,7 @@ RingView.prototype = { | |
this.ringDisplay.dataset.ringType = alert.type; | ||
|
||
// Set the time to display. | ||
var localeTime = Utils.getLocaleTime(alert.time); | ||
this.time.textContent = localeTime.time; | ||
this.hourState.textContent = localeTime.ampm; | ||
this.time.innerHTML = Utils.getLocalizedTimeHtml(alert.time); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so much better 👍 |
||
|
||
if (alert.sound) { | ||
this.ringtonePlayer.playRingtone(alert.sound); | ||
|
@@ -228,7 +226,6 @@ RingView.prototype = { | |
|
||
Utils.extendWithDomGetters(RingView.prototype, { | ||
time: '#ring-clock-time', | ||
hourState: '#ring-clock-hour24-state', | ||
ringLabel: '#ring-label', | ||
snoozeButton: '#ring-button-snooze', | ||
closeButton: '#ring-button-stop', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this A LOT. - abstract all the things!