@@ -10,17 +10,20 @@ folderPluginApp.controller('folderPluginCtrl', ['$scope', function ($scope) {
1010
1111 $scope . editorOptions = folderPluginShared . getEditorOptions ( ) ;
1212
13- $scope . data = folderPluginShared . getDefaultScopeData ( ) ;
13+ // $scope.data = folderPluginShared.getDefaultScopeData();
1414
15- $scope . data . _buildfire = {
16- "plugins" : {
17- "dataType" : "pluginInstance" ,
18- "data" : [ ]
19- }
20- } ;
15+ $scope . masterData = folderPluginShared . getDefaultScopeData ( ) ;
2116
2217 $scope . datastoreInitialized = false ;
2318
19+ function isUnchanged ( data ) {
20+ return angular . equals ( data , $scope . masterData ) ;
21+ }
22+
23+ function updateMasterItem ( data ) {
24+ $scope . masterData = angular . copy ( data ) ;
25+ }
26+
2427 /*
2528 * Go pull any previously saved data
2629 * */
@@ -40,11 +43,11 @@ folderPluginApp.controller('folderPluginCtrl', ['$scope', function ($scope) {
4043
4144 $scope . data = result . data ;
4245 $scope . id = result . id ;
43- if ( $scope . data . content && $scope . data . content . carouselImages ) {
46+ if ( $scope . data && $scope . data . content && $scope . data . content . carouselImages ) {
4447 editor . loadItems ( $scope . data . content . carouselImages ) ;
4548 }
4649
47- if ( $scope . data . _buildfire && $scope . data . _buildfire . plugins && $scope . data . _buildfire . plugins . result ) {
50+ if ( $scope . data && $scope . data . _buildfire && $scope . data . _buildfire . plugins && $scope . data . _buildfire . plugins . result ) {
4851 var pluginsData = folderPluginShared . getPluginDetails ( $scope . data . _buildfire . plugins . result , $scope . data . _buildfire . plugins . data ) ;
4952 if ( $scope . data . content && $scope . data . content . loadAllPlugins ) {
5053 if ( pluginsData . length ) {
@@ -60,7 +63,7 @@ folderPluginApp.controller('folderPluginCtrl', ['$scope', function ($scope) {
6063 }
6164 }
6265
63- if ( ! $scope . data . _buildfire ) {
66+ if ( $scope . data && ! $scope . data . _buildfire ) {
6467 $scope . data . _buildfire = {
6568 plugins : {
6669 dataType : "pluginInstance" ,
@@ -69,7 +72,7 @@ folderPluginApp.controller('folderPluginCtrl', ['$scope', function ($scope) {
6972 } ;
7073 }
7174
72- if ( ! $scope . data . design ) {
75+ if ( $scope . data && ! $scope . data . design ) {
7376 $scope . data . design = {
7477 backgroundImage : null ,
7578 selectedLayout : 1 ,
@@ -107,20 +110,24 @@ folderPluginApp.controller('folderPluginCtrl', ['$scope', function ($scope) {
107110 newObj . _buildfire . plugins . result = plugins . items ;
108111 }
109112
113+ updateMasterItem ( newObj ) ;
114+
110115 folderPluginShared . save ( newObj ) ;
111116 } ;
112117
113118 /*
114119 * create an artificial delay so api isnt called on every character entered
115120 * */
116- var saveDataWithDelay = function ( newObj , oldObj ) {
121+ var saveDataWithDelay = function ( newObj ) {
117122
118123 if ( tmrDelay ) clearTimeout ( tmrDelay ) ;
119- if ( angular . equals ( newObj , oldObj ) ) return ;
124+ if ( isUnchanged ( newObj ) ) {
125+ return ;
126+ }
120127 if ( newObj . default ) {
121128 newObj = folderPluginShared . getDefaultScopeBlankData ( ) ;
122129 editor . loadItems ( [ ] ) ;
123- $scope . data . content . text = ""
130+ $scope . data = newObj ;
124131 }
125132 tmrDelay = setTimeout ( function ( ) {
126133 saveData ( newObj ) ;
0 commit comments