Merge lp:~methanal-developers/methanal/759805-form-action-ids into lp:methanal

Proposed by Jonathan Jacobs
Status: Merged
Approved by: Tristan Seligmann
Approved revision: 168
Merged at revision: 169
Proposed branch: lp:~methanal-developers/methanal/759805-form-action-ids
Merge into: lp:methanal
Diff against target: 100 lines (+35/-4)
2 files modified
methanal/js/Methanal/View.js (+24/-0)
methanal/view.py (+11/-4)
To merge this branch: bzr merge lp:~methanal-developers/methanal/759805-form-action-ids
Reviewer Review Type Date Requested Status
Tristan Seligmann Approve
Review via email: mp+57497@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Tristan Seligmann (mithrandi) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'methanal/js/Methanal/View.js'
2--- methanal/js/Methanal/View.js 2011-04-11 09:19:48 +0000
3+++ methanal/js/Methanal/View.js 2011-04-13 14:08:23 +0000
4@@ -5,6 +5,13 @@
5
6
7 /**
8+ * An unknown identifier was used.
9+ */
10+Divmod.Error.subclass(Methanal.View, 'UnknownIdentifier');
11+
12+
13+
14+/**
15 * Build a mapping of input node values to DOM nodes.
16 */
17 Methanal.View.buildInputNodeMapping = function buildInputNodeMapping(node) {
18@@ -829,12 +836,16 @@
19 *
20 * @type throbber: L{Methanal.Util.Throbber}
21 * @ivar throbber: Action throbber
22+ *
23+ * @ivar _actionMapping: Mapping of L{FormAction} identifiers to
24+ * L{FormAction}s.
25 */
26 Nevow.Athena.Widget.subclass(Methanal.View, 'ActionContainer').methods(
27 function __init__(self, node, args) {
28 Methanal.View.ActionContainer.upcall(self, '__init__', node);
29 self._disabled = false;
30 self.actionIDs = args.actionIDs;
31+ self._actionMapping = {};
32 },
33
34
35@@ -861,11 +872,24 @@
36 */
37 function loadedUp(self, action) {
38 delete self.actionIDs[action.actionID];
39+ self._actionMapping[action.actionID] = action;
40 self._finishLoading();
41 },
42
43
44 /**
45+ * Get a L{Methanal.View.FormAction} by identifier.
46+ */
47+ function getAction(self, actionID) {
48+ var action = self._actionMapping[actionID];
49+ if (action === undefined) {
50+ throw Methanal.View.UnknownIdentifier(actionID);
51+ }
52+ return action;
53+ },
54+
55+
56+ /**
57 * Enable all form actions.
58 *
59 * Actions for view-only forms cannot be enabled.
60
61=== modified file 'methanal/view.py'
62--- methanal/view.py 2011-03-31 10:35:52 +0000
63+++ methanal/view.py 2011-04-13 14:08:23 +0000
64@@ -43,14 +43,19 @@
65 """
66 defaultName = None
67 allowViewOnly = False
68-
69-
70- def __init__(self, name=None, **kw):
71+ identifier = None
72+
73+
74+ def __init__(self, name=None, identifier=None, **kw):
75 super(FormAction, self).__init__(**kw)
76 if not name:
77 name = self.defaultName
78+ if identifier is None:
79+ identifier = self.identifier
80+ if identifier is None:
81+ identifier = unicode(id(self))
82 self.name = name
83- self.id = unicode(id(self))
84+ self.id = identifier
85
86
87 def getInitialArguments(self):
88@@ -88,6 +93,7 @@
89 jsClass = u'Methanal.View.SubmitAction'
90 defaultName = u'Submit'
91 type = 'submit'
92+ identifier = u'submit'
93
94
95
96@@ -99,6 +105,7 @@
97 allowViewOnly = True
98 defaultName = u'Reset'
99 type = 'reset'
100+ identifier = u'reset'
101
102
103

Subscribers

People subscribed via source and target branches

to all changes: