save: function aev_save(callback) { if (this.element.dataset.id && this.element.dataset.id !== '') { this.alarm.id = parseInt(this.element.dataset.id, 10); } else { delete this.alarm.id; } this.alarm.label = this.inputs.name.value; var time = this.getTimeSelect(); this.alarm.time = [time.hour, time.minute]; this.alarm.repeat = this.buttons.repeat.value; this.alarm.sound = this.getSoundSelect(); this.alarm.vibrate = this.getVibrateSelect(); this.alarm.snooze = parseInt(this.getSnoozeSelect(), 10); AudioManager.setAlarmVolume(this.getAlarmVolumeValue()); this.alarm.cancel(); this.alarm.setEnabled(true, function(err, alarm) { if (err) { callback && callback(err, alarm); return; } window.dispatchEvent(new CustomEvent('alarm-changed', { detail: { alarm: alarm, showBanner: true } })); callback && callback(null, alarm); }); },
save: function aev_save(callback) { if (this.element.dataset.id && this.element.dataset.id !== '') { this.alarm.id = parseInt(this.element.dataset.id, 10); } else { delete this.alarm.id; } this.alarm.label = this.inputs.name.value; var time = this.getTimeSelect(); this.alarm.hour = time.hour; this.alarm.minute = time.minute; this.alarm.repeat = this.buttons.repeat.value; this.alarm.sound = this.getSoundSelect(); this.alarm.vibrate = this.checkboxes.vibrate.checked; this.alarm.snooze = parseInt(this.getSnoozeSelect(), 10); AudioManager.setAlarmVolume(this.getAlarmVolumeValue()); this.alarm.schedule('normal').then(() => { window.dispatchEvent(new CustomEvent('alarm-changed', { detail: { alarm: this.alarm, showBanner: true } })); callback && callback(null, this.alarm); }); },
handleDomEvent: function aev_handleDomEvent(evt) { evt.preventDefault(); var input = evt.target; if (!input) { return; } switch (input) { case this.buttons.close: ClockView.show(); break; case this.buttons.done: ClockView.show(); this.save(); break; case this.selects.sound: switch (evt.type) { case 'change': this.previewSound(); break; case 'blur': this.stopPreviewSound(); break; } break; case this.buttons.delete: ClockView.show(); this.delete(); break; case this.selects.repeat: this.alarm.repeat = this.buttons.repeat.value; break; case this.inputs.volume: // Alarm Volume is applied to all alarms. AudioManager.setAlarmVolume(this.getAlarmVolumeValue()); break; } },
save: function aev_save(callback) { if (this.isSaving) { // Ignore double-taps on the "Save" button. When this view gets // refactored, we should opt for a more coherent way of managing // UI state to avoid glitches like this. return; } var alarm = this.alarm; if (this.element.dataset.id && this.element.dataset.id !== '') { alarm.id = parseInt(this.element.dataset.id, 10); } else { delete alarm.id; } alarm.label = this.inputs.name.value; var time = this.getTimeSelect(); alarm.hour = time.hour; alarm.minute = time.minute; alarm.repeat = this.buttons.repeat.value; alarm.sound = this.getSoundSelect(); alarm.vibrate = this.checkboxes.vibrate.checked; alarm.snooze = parseInt(this.getSnoozeSelect(), 10); AudioManager.setAlarmVolume(this.getAlarmVolumeValue()); this.isSaving = true; alarm.schedule('normal').then(() => { this.isSaving = false; window.dispatchEvent(new CustomEvent('alarm-changed', { detail: { alarm: alarm, showBanner: true } })); callback && callback(null, alarm); }); },