Merge lp:~methanal-developers/methanal/track-saved-and-validity into lp:methanal

Proposed by Jonathan Jacobs
Status: Merged
Approved by: Tristan Seligmann
Approved revision: 168
Merged at revision: 167
Proposed branch: lp:~methanal-developers/methanal/track-saved-and-validity
Merge into: lp:methanal
Diff against target: 212 lines (+51/-31)
2 files modified
methanal/js/Methanal/Tests/TestView.js (+35/-29)
methanal/js/Methanal/View.js (+16/-2)
To merge this branch: bzr merge lp:~methanal-developers/methanal/track-saved-and-validity
Reviewer Review Type Date Requested Status
Tristan Seligmann Approve
Review via email: mp+54307@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Tristan Seligmann (mithrandi) wrote :

+ // An unsuccessful submissino will not remove the modified indicator.

I assume this is a typo.

review: Needs Fixing
Revision history for this message
Jonathan Jacobs (jjacobs) wrote :

> + // An unsuccessful submissino will not remove the modified indicator.
>
> I assume this is a typo.

Fixed.

167. By Jonathan Jacobs

Fix typo.

Revision history for this message
Tristan Seligmann (mithrandi) wrote :

Bleh. There are conflicts with trunk, now; please resolve them so we can see what the real diff is.

review: Needs Fixing
Revision history for this message
Jonathan Jacobs (jjacobs) wrote :

> Bleh. There are conflicts with trunk, now; please resolve them so we can see
> what the real diff is.

Done.

168. By Jonathan Jacobs

Merge trunk and resolve conflicts.

Revision history for this message
Tristan Seligmann (mithrandi) :
review: Approve
169. By Jonathan Jacobs

Fix broken test.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'methanal/js/Methanal/Tests/TestView.js'
2--- methanal/js/Methanal/Tests/TestView.js 2011-03-31 10:46:20 +0000
3+++ methanal/js/Methanal/Tests/TestView.js 2011-04-11 11:46:38 +0000
4@@ -13,13 +13,11 @@
5 */
6 Methanal.View.LiveForm.subclass(
7 Methanal.Tests.TestView, 'MockLiveForm').methods(
8- function __init__(self, controlNames, viewOnly) {
9- viewOnly = viewOnly || false;
10-
11+ function __init__(self, controlNames, args/*=undefined*/) {
12+ args = args || {};
13 var node = Nevow.Test.WidgetUtil.makeWidgetNode();
14 Methanal.Tests.TestView.MockLiveForm.upcall(
15- self, '__init__', node, viewOnly, controlNames);
16-
17+ self, '__init__', node, args, controlNames);
18 Methanal.Tests.Util.setUpForm(self);
19 });
20
21@@ -67,7 +65,7 @@
22 /**
23 * Create a C{Methanal.View.LiveForm}.
24 */
25- function createForm(self, viewOnly, controls/*=undefined*/,
26+ function createForm(self, args, controls/*=undefined*/,
27 postFormInsertion/*=undefined*/) {
28 controls = controls || [];
29 var controlNames = [];
30@@ -75,7 +73,7 @@
31 controlNames.push(controls[i].name);
32 }
33
34- var form = Methanal.Tests.TestView.MockLiveForm(controlNames, viewOnly);
35+ var form = Methanal.Tests.TestView.MockLiveForm(controlNames, args);
36 Methanal.Tests.Util.setUpForm(form);
37 Methanal.Util.nodeInserted(form);
38 if (postFormInsertion) {
39@@ -111,7 +109,9 @@
40 */
41 function test_freezeThaw(self) {
42 var control = self.createControl({'name': 'a'});
43- var form = self.createForm(false, [control]);
44+ var args = {
45+ 'viewOnly': false};
46+ var form = self.createForm(args, [control]);
47 form.freeze();
48 self.assertIdentical(form._frozen, 1);
49 form.freeze();
50@@ -130,10 +130,14 @@
51 * Setting the form valid / invalid enables / disables the actions.
52 */
53 function test_validInvalid(self) {
54- var form = self.createForm();
55+ var args = {
56+ 'viewOnly': false};
57+ var form = self.createForm(args);
58 form.setValid();
59+ self.assertIdentical(form.valid, true);
60 self.assertIdentical(form.actions._disabled, false);
61 form.setInvalid();
62+ self.assertIdentical(form.valid, false);
63 self.assertIdentical(form.actions._disabled, true);
64 },
65
66@@ -146,7 +150,9 @@
67 function test_submission(self) {
68 var success;
69 var control = self.createControl({'name': 'a'});
70- var form = self.createForm(false, [control]);
71+ var args = {
72+ 'viewOnly': false};
73+ var form = self.createForm(args, [control]);
74
75 function succeed(methodName, data) {
76 self.assertIdentical(form.actions._disabled, true);
77@@ -158,22 +164,20 @@
78 return Divmod.Defer.fail('too bad');
79 };
80
81- form.submitSuccess = function (data) {
82- self.assertIdentical(form.actions._disabled, false);
83- success = true;
84- };
85- form.submitFailure = function (error) {
86- self.assertIdentical(form.actions._disabled, false);
87- success = false;
88- };
89-
90 form.callRemote = succeed;
91+ form.formModified(true);
92+ self.assertIdentical(form.modified, true);
93 form.submit();
94- self.assertIdentical(success, true);
95+ self.assertIdentical(form.modified, false);
96+ self.assertIdentical(form.actions._disabled, false);
97
98 form.callRemote = fail;
99+ form.formModified(true);
100+ self.assertIdentical(form.modified, true);
101 form.submit();
102- self.assertIdentical(success, false);
103+ // An unsuccessful submission will not remove the modified indicator.
104+ self.assertIdentical(form.modified, true);
105+ self.assertIdentical(form.actions._disabled, false);
106 },
107
108
109@@ -251,15 +255,14 @@
110 */
111 function test_formModified(self) {
112 var control = self.createControl({'name': 'a'});
113- var form = self.createForm(false, [control]);
114+ var args = {
115+ 'viewOnly': false,
116+ 'submitted': true};
117+ var form = self.createForm(args, [control]);
118 var containsElementClass = Methanal.Util.containsElementClass;
119- self.assertIdentical(
120- containsElementClass(form.nodeById('modifiedIndicator'), 'hidden'),
121- true);
122+ self.assertIdentical(form.modified, false)
123 control.onChange();
124- self.assertIdentical(
125- containsElementClass(form.nodeById('modifiedIndicator'), 'hidden'),
126- false);
127+ self.assertIdentical(form.modified, true)
128 },
129
130
131@@ -269,7 +272,10 @@
132 function test_formLoaded(self) {
133 var success = false;
134 var control = self.createControl({'name': 'a'});
135- var form = self.createForm(false, [control], function (form) {
136+ var args = {
137+ 'viewOnly': false,
138+ 'submitted': true};
139+ var form = self.createForm(args, [control], function (form) {
140 self.assertIdentical(
141 success,
142 false);
143
144=== modified file 'methanal/js/Methanal/View.js'
145--- methanal/js/Methanal/View.js 2011-03-28 13:23:01 +0000
146+++ methanal/js/Methanal/View.js 2011-04-11 11:46:38 +0000
147@@ -930,7 +930,7 @@
148 * @type viewOnly: C{boolean}
149 * @ivar viewOnly: Are form actions disabled for this form?
150 *
151- * @type hideModificationIndicator: C{boolean}
152+ * @type hideModificationIndicator: C{Boolean}
153 * @ivar hideModificationIndicator: Hide the modification indicator for this
154 * form? Defaults to C{false}.
155 *
156@@ -940,6 +940,14 @@
157 * @type actions: L{Methanal.View.ActionContainer}
158 * @ivar actions: Action container widget, this is only assigned once the action
159 * container widget's C{nodeInserted} method has been called
160+ *
161+ * @type modified: C{Boolean}
162+ * @ivar modified: Have any inputs in this LiveForm been modified since
163+ * creation or the last successful submission?
164+ *
165+ * @type valid: C{Boolean}
166+ * @ivar valid: Is this LiveForm currently in a valid state, i.e. no
167+ * validation errors are present? Defaults to C{true}.
168 */
169 Methanal.View.FormBehaviour.subclass(Methanal.View, 'LiveForm').methods(
170 function __init__(self, node, args, controlNames) {
171@@ -949,7 +957,8 @@
172 Divmod.warn(
173 'Use an argument dictionary instead of the "viewOnly"' +
174 'boolean parameter', Divmod.DeprecationWarning);
175- args = {'viewOnly': args};
176+ args = {
177+ 'viewOnly': args};
178 }
179 self.viewOnly = args.viewOnly;
180 self.hideModificationIndicator = args.hideModificationIndicator;
181@@ -958,6 +967,8 @@
182 }
183 self.controlNames = Methanal.Util.arrayToMapping(controlNames);
184 self._controlNamesOrdered = controlNames;
185+ self.modified = false;
186+ self.valid = true;
187 self.formInit();
188 },
189
190@@ -1162,6 +1173,7 @@
191 if (!self.hideModificationIndicator) {
192 self.actions.modifiedIndicator(modified);
193 }
194+ self.modified = modified;
195 },
196
197
198@@ -1175,6 +1187,7 @@
199 * Enable the form for submission.
200 */
201 function setValid(self) {
202+ self.valid = true;
203 self.actions.enable();
204 },
205
206@@ -1183,6 +1196,7 @@
207 * Disable form submission.
208 */
209 function setInvalid(self) {
210+ self.valid = false;
211 self.actions.disable();
212 });
213

Subscribers

People subscribed via source and target branches

to all changes: