mirror of
https://github.com/johannesjo/super-productivity.git
synced 2026-08-01 12:10:33 +00:00
50 lines
1.1 KiB
JavaScript
50 lines
1.1 KiB
JavaScript
/**
|
|
* @ngdoc function
|
|
* @name superProductivity.controller:DistractionsCtrl
|
|
* @description
|
|
* # DistractionsCtrl
|
|
* Controller of the superProductivity
|
|
*/
|
|
|
|
(function () {
|
|
'use strict';
|
|
|
|
angular
|
|
.module('superProductivity')
|
|
.controller('DistractionsCtrl', DistractionsCtrl);
|
|
|
|
/* @ngInject */
|
|
function DistractionsCtrl($mdDialog, $localStorage, SimpleToast) {
|
|
let vm = this;
|
|
vm.r = $localStorage;
|
|
vm.isOpen = false;
|
|
|
|
vm.close = () => {
|
|
vm.newDistraction = '';
|
|
vm.isOpen = false;
|
|
};
|
|
|
|
vm.onKeydown = (ev) => {
|
|
if (ev.ctrlKey && ev.keyCode === 13) {
|
|
// Ctrl-Enter pressed
|
|
vm.saveDistraction();
|
|
}
|
|
if (ev.keyCode === 27) {
|
|
// escape is pressed
|
|
vm.close();
|
|
}
|
|
};
|
|
|
|
vm.saveDistraction = () => {
|
|
if (vm.newDistraction.length > 0) {
|
|
$localStorage.distractions.push(vm.newDistraction);
|
|
}
|
|
SimpleToast('SUCCESS', 'Distraction saved for later');
|
|
$mdDialog.hide();
|
|
};
|
|
|
|
this.cancel = () => {
|
|
$mdDialog.cancel();
|
|
};
|
|
}
|
|
})();
|