@@ -18,6 +18,7 @@ define([
18
18
meta : { } ,
19
19
errorMessage : null ,
20
20
displayMetadata : true ,
21
+ initialValue : { } ,
21
22
messages : {
22
23
UNKOWN_ERROR : $t ( 'Sorry, there was an error getting requested content. ' +
23
24
'Please contact the store owner.' ) ,
@@ -43,16 +44,52 @@ define([
43
44
}
44
45
} ,
45
46
listens : {
46
- id : 'updateFromServer'
47
+ id : 'updateFromServer' ,
48
+ '${ $.provider }:data.reset' : 'reset'
47
49
}
48
50
} ,
49
51
52
+ /**
53
+ * Invokes initialize method of parent class,
54
+ * contains initialization logic
55
+ */
56
+ initialize : function ( ) {
57
+ _ . bindAll ( this , 'reset' ) ;
58
+
59
+ this . _super ( )
60
+ . setInitialValue ( ) ;
61
+
62
+ return this ;
63
+ } ,
64
+
65
+ /**
66
+ * Sets initial value of the element and subscribes to it's changes.
67
+ *
68
+ * @returns {Abstract } Chainable.
69
+ */
70
+ setInitialValue : function ( ) {
71
+ if ( this . id ( ) ) {
72
+ this . initialValue ( false ) ;
73
+ }
74
+ return this ;
75
+ } ,
76
+
50
77
/**
51
78
* @inheritdoc
52
79
*/
53
80
initObservable : function ( ) {
54
81
return this . _super ( )
55
- . observe ( 'id meta errorMessage displayMetadata' ) ;
82
+ . observe ( 'id meta errorMessage displayMetadata initialValue' ) ;
83
+ } ,
84
+
85
+ /**
86
+ * Resets metadata
87
+ *
88
+ * @returns void
89
+ */
90
+ reset : function ( ) {
91
+ this . meta ( this . initialValue ( ) ) ;
92
+ this . errorMessage ( null ) ;
56
93
} ,
57
94
58
95
/**
@@ -90,6 +127,9 @@ define([
90
127
}
91
128
92
129
this . meta ( response ) ;
130
+ if ( this . initialValue ( ) === false ) {
131
+ this . initialValue ( response )
132
+ }
93
133
} . bind ( this ) )
94
134
. fail ( function ( ) {
95
135
this . meta ( { } ) ;
0 commit comments