From f19d1df9ccf61dfd456fb9841483e4cc068bacc7 Mon Sep 17 00:00:00 2001 From: Nace Logar Date: Sun, 15 Feb 2015 19:12:21 +0100 Subject: [PATCH] Implementing workout form --- www/js/workout/controllers/wrkDetailCtrl.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/www/js/workout/controllers/wrkDetailCtrl.js b/www/js/workout/controllers/wrkDetailCtrl.js index e2f32fd..6774a23 100644 --- a/www/js/workout/controllers/wrkDetailCtrl.js +++ b/www/js/workout/controllers/wrkDetailCtrl.js @@ -1,4 +1,4 @@ -angular.module('arete.controllers').controller('wrkDetailCtrl', function ($scope, $translate, $stateParams, Workout) { +angular.module('arete.controllers').controller('wrkDetailCtrl', function ($q, $scope, $translate, $stateParams, Workout) { 'use strict'; var vm = this; @@ -13,8 +13,6 @@ angular.module('arete.controllers').controller('wrkDetailCtrl', function ($scope ]; vm.workout.selectedRepeatType = _.first(vm.repeatList).id; - - for (var i = 1; i < 8; i++) { var day = { id: i, label: 'general.days.' + i }; vm.days.push(day); @@ -34,7 +32,14 @@ angular.module('arete.controllers').controller('wrkDetailCtrl', function ($scope }; vm.saveWorkout = function (workoutModel) { - var workout, + saveEntity(workoutModel).then(function() { + //notify and redirect or some other shit + }); + }; + + function saveEntity(workoutModel) { + var deferred = $q.defer(), + workout, repeatDaysArray = []; if (vm.workout.id) { @@ -71,6 +76,12 @@ angular.module('arete.controllers').controller('wrkDetailCtrl', function ($scope workout.repeatedDays = repeatDaysArray; } - }; + persistence.flush(function() { + deferred.resolve(); + }); + + return deferred.promise; + } + });