@@ -61,31 +61,36 @@ function Master(activityId, config) {
61
61
* Collect the activity form data into a single javascript object
62
62
* @returns JS object containing form data, or null if there is no data
63
63
*/
64
- self . collectData = function ( ) {
65
- var activityData , outputs = [ ] , photoPoints ;
66
- $ . each ( this . subscribers , function ( i , obj ) {
67
- if ( obj . model === 'activityModel' ) {
68
- activityData = obj . get ( ) ;
69
- } else if ( obj . model === 'photoPoints' && obj . isDirty ( ) ) {
70
- photoPoints = obj . get ( ) ;
71
- }
72
- else { // Update outputs unconditionally, backend needs the activityModel and outputs to
73
- // create derived data even if outputs didn't change
74
- outputs . push ( obj . get ( ) ) ;
64
+ self . modelAsJS = function ( ) {
65
+ var activityData , outputs = [ ] ;
66
+ $ . each ( this . subscribers , function ( i , obj ) {
67
+ if ( obj . isDirty ( ) ) {
68
+ if ( obj . model === 'activityModel' ) {
69
+ activityData = obj . get ( ) ;
70
+ }
71
+ else {
72
+ outputs . push ( obj . get ( ) ) ;
73
+ }
75
74
}
76
-
77
75
} ) ;
78
- if ( outputs . length === 0 && activityData === undefined && photoPoints === undefined ) {
79
- return { validation : false , message : "Nothing need to be updated!" } ;
80
- }
81
76
82
- if ( activityData === undefined ) {
83
- activityData = { }
77
+ if ( activityData === undefined && outputs . length == 0 ) {
78
+ return undefined ;
79
+ }
80
+ if ( ! activityData ) {
81
+ activityData = { } ;
84
82
}
85
83
activityData . outputs = outputs ;
84
+
86
85
return activityData ;
87
86
} ;
88
87
88
+ self . modelAsJSON = function ( ) {
89
+ var jsData = self . modelAsJS ( ) ;
90
+
91
+ return jsData ? JSON . stringify ( jsData ) : undefined ;
92
+ } ;
93
+
89
94
self . removeTemporarySite = function ( ) {
90
95
if ( this . subscribers [ 0 ] . model . data && this . subscribers [ 0 ] . model . data . locationSitesArray && this . subscribers [ 0 ] . model . data . location ) {
91
96
var sites = this . subscribers [ 0 ] . model . data . locationSitesArray ( ) ;
@@ -124,7 +129,7 @@ function Master(activityId, config) {
124
129
*/
125
130
self . save = function ( ) {
126
131
if ( $ ( '#validation-container' ) . validationEngine ( 'validate' ) ) {
127
- var toSave = this . collectData ( ) ;
132
+ var toSave = this . modelAsJS ( ) ;
128
133
toSave = JSON . stringify ( toSave ) ;
129
134
130
135
// Don't allow another save to be initiated.
0 commit comments