From 43fd9c7055dabb958980602610e3f0a99f443c87 Mon Sep 17 00:00:00 2001 From: Enrico Fasoli Date: Wed, 1 Apr 2015 16:13:02 +0200 Subject: [PATCH] fixed raweditor --- src/app.coffee | 16 ++++++++++++---- src/controllers.coffee | 13 ++++++++++++- src/rawedit.html | 5 +++-- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/app.coffee b/src/app.coffee index 2209004..7791872 100644 --- a/src/app.coffee +++ b/src/app.coffee @@ -35,9 +35,10 @@ pertApp.config ($stateProvider,$urlRouterProvider) -> pertController = ($scope) -> $scope.toLocalStorage = (data,options) -> - options = options || {} + options ?= {} + data ?= [] try - console.log data + console.log "Saving: "+data localStorage.setItem 'ganttpert', JSON.stringify data unless options.silent swal 'Ok', 'Data updated', 'success' @@ -54,8 +55,15 @@ pertController = ($scope) -> unless options.silent swal 'JSON Error', e, 'error' if options.raw + console.log 'Loading: []' return [] - else return activities: [], days: [] + else + console.log 'Loading: {list: [], days: []}' + return list: [], days: [] if options.raw + console.log 'Loading: '+jdata return jdata - else return new Pert(jdata).calculate() + else + r = new Pert(jdata).calculate() + console.log 'Loading: '+r + return r diff --git a/src/controllers.coffee b/src/controllers.coffee index 605185d..1c933ce 100644 --- a/src/controllers.coffee +++ b/src/controllers.coffee @@ -46,7 +46,18 @@ pertApp.controller 'ganttDiagController', ($scope) -> $scope.buildTimeline $scope.fromLocalStorage() pertApp.controller 'rawEditorController', ($scope) -> - $scope.rawdata = $scope.fromLocalStorage silent: yes, raw: yes + $scope.saveData = -> + try + data = JSON.parse $scope.taData + catch e + return swal 'Error', 'The data entered is invalid', 'error' + $scope.toLocalStorage data + $scope.reloadData = -> + $scope.taData = JSON.stringify $scope.fromLocalStorage silent: yes, raw: yes + $scope.$on 'dataChanged', -> + $scope.reloadData() + #$('#ta').val JSON.stringify $scope.fromLocalStorage silent: yes, raw: yes + $scope.reloadData() pertApp.controller 'editorController', ($scope) -> $scope.clone = (id) -> diff --git a/src/rawedit.html b/src/rawedit.html index 05cc80a..31446fe 100644 --- a/src/rawedit.html +++ b/src/rawedit.html @@ -1,4 +1,5 @@
- - + + +