From 866ebbeac4a13dc69e241011d2047d9b8d050001 Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Fri, 8 Nov 2013 21:55:08 +0100 Subject: [PATCH] refactor writer to use state scope --- src/js/controller/navigation.js | 22 +++++++--------------- src/js/controller/write.js | 22 +++++++++++++++------- src/tpl/desktop.html | 2 +- src/tpl/read.html | 4 ++-- src/tpl/write.html | 2 +- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/js/controller/navigation.js b/src/js/controller/navigation.js index 114b22e..f2b2ee6 100644 --- a/src/js/controller/navigation.js +++ b/src/js/controller/navigation.js @@ -40,14 +40,6 @@ define(function(require) { } }; - $scope.openWriter = function(replyTo) { - $scope.writerReply = !! (replyTo); - $scope.writerOpen = true; - }; - $scope.closeWriter = function() { - $scope.writerOpen = false; - }; - $scope.openFolder = function(folder) { $scope.currentFolder = folder; $scope.state.nav.toggle(false); @@ -284,27 +276,27 @@ define(function(require) { elm.bind('keydown', function(e) { var cs = scope.$$childTail; - if (e.keyCode === 78 && !cs.writerOpen) { + if (e.keyCode === 78 && !scope.state.writer.open) { // n -> new mail e.preventDefault(); - cs.openWriter(); + scope.state.writer.write(); - } else if (e.keyCode === 82 && !cs.writerOpen && cs.selected) { + } else if (e.keyCode === 82 && !scope.state.writer.open && cs.selected) { // r -> reply e.preventDefault(); - cs.openWriter(cs.selected); + scope.state.writer.write(cs.selected); - } else if (e.keyCode === 27 && cs.writerOpen) { + } else if (e.keyCode === 27 && scope.state.writer.open) { // escape -> close writer e.preventDefault(); - cs.closeWriter(); + scope.state.writer.close(); } else if (e.keyCode === 27 && cs.accountOpen) { // escape -> close account view e.preventDefault(); cs.closeAccount(); - } else if (e.keyCode === 83 && !cs.writerOpen && cs.synchronize) { + } else if (e.keyCode === 83 && !scope.state.writer.open && cs.synchronize) { // s -> sync folder e.preventDefault(); cs.synchronize(); diff --git a/src/js/controller/write.js b/src/js/controller/write.js index d2ad26c..bac7cc6 100644 --- a/src/js/controller/write.js +++ b/src/js/controller/write.js @@ -20,14 +20,22 @@ define(function(require) { // Init // - $scope.$watch('writerOpen', function() { - resetFields(); - if ($scope.writerReply) { - fillFields($scope.selected); - $scope.updatePreview(); + $scope.state.writer = { + open: false, + write: function(replyTo) { + this.open = true; + + resetFields(); + if (replyTo) { + fillFields(replyTo); + $scope.updatePreview(); + } + $scope.verifyTo(); + }, + close: function() { + this.open = false; } - $scope.verifyTo(); - }); + }; function resetFields() { $scope.writerTitle = 'New email'; diff --git a/src/tpl/desktop.html b/src/tpl/desktop.html index 5381bc7..4375cb7 100644 --- a/src/tpl/desktop.html +++ b/src/tpl/desktop.html @@ -19,7 +19,7 @@ -