Merge lp:~salgado/lazr-js/picker-refactoring into lp:lazr-js

Proposed by Guilherme Salgado
Status: Merged
Approved by: Edwin Grubbs
Approved revision: 131
Merged at revision: not available
Proposed branch: lp:~salgado/lazr-js/picker-refactoring
Merge into: lp:lazr-js
Diff against target: 185 lines (+111/-4)
2 files modified
src-js/lazrjs/picker/picker.js (+60/-3)
src-js/lazrjs/picker/tests/picker.js (+51/-1)
To merge this branch: bzr merge lp:~salgado/lazr-js/picker-refactoring
Reviewer Review Type Date Requested Status
Edwin Grubbs (community) code Approve
Review via email: mp+14789@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Guilherme Salgado (salgado) wrote :

Change the picker to clean itself upon save, with config options to have it cleared or not upon save/cancel

Revision history for this message
Guilherme Salgado (salgado) wrote :

My changes have caused the picker not to be hidden when we click on the close button, so I had to do the changes below to fix it.

=== modified file 'src-js/lazrjs/picker/picker.js'
--- src-js/lazrjs/picker/picker.js 2009-11-12 16:02:51 +0000
+++ src-js/lazrjs/picker/picker.js 2009-11-12 16:58:01 +0000
@@ -72,6 +72,7 @@
     /**
      * Whether or not the widget should be cleared when the save event is
      * fired.
+ *
      * @property clear_on_save
      * @type Boolean
      * default true
@@ -81,6 +82,7 @@
     /**
      * Whether or not the widget should be cleared when the cancel event is
      * fired.
+ *
      * @property clear_on_cancel
      * @type Boolean
      * default false
@@ -630,6 +632,7 @@
      * @protected
      */
     _defaultCancel : function(e) {
+ Picker.superclass._defaultCancel.apply(this, arguments);
         if ( this.clear_on_cancel ) {
             this._clear();
         }

=== modified file 'src-js/lazrjs/picker/tests/picker.js'
--- src-js/lazrjs/picker/tests/picker.js 2009-11-12 16:02:51 +0000
+++ src-js/lazrjs/picker/tests/picker.js 2009-11-12 16:55:25 +0000
@@ -379,6 +379,14 @@
             }, 3000);
     },

+ test_cancel_event_hides_widget: function () {
+ this.picker.render();
+
+ this.picker.fire('cancel', 'bogus');
+ Assert.isFalse(
+ this.picker.get('visible'), "The widget should be hidden.");
+ },
+
     test_save_event_hides_widget: function () {
         this.picker.render();

131. By Guilherme Salgado

Unbreak the close button of the picker so that it hides the picker as it used to.

Revision history for this message
Edwin Grubbs (edwin-grubbs) wrote :

Hi Salgado,

This looks good. A couple of minor comments below.

merge-approved

-Edwin

> === modified file 'src-js/lazrjs/picker/picker.js'
> --- src-js/lazrjs/picker/picker.js 2009-11-12 16:02:51 +0000
> +++ src-js/lazrjs/picker/picker.js 2009-11-12 16:58:01 +0000
> @@ -72,6 +72,7 @@
> /**
> * Whether or not the widget should be cleared when the save event is
> * fired.

I think it would be clearer to say "Whether or not the *search box and result list* should be cleared".

> + *
> * @property clear_on_save
> * @type Boolean
> * default true
> @@ -81,6 +82,7 @@
> /**
> * Whether or not the widget should be cleared when the cancel event is
> * fired.
> + *

Same here.

> * @property clear_on_cancel
> * @type Boolean
> * default false
> @@ -630,6 +632,7 @@
> * @protected
> */
> _defaultCancel : function(e) {
> + Picker.superclass._defaultCancel.apply(this, arguments);
> if ( this.clear_on_cancel ) {
> this._clear();
> }
>

review: Approve (code)
Revision history for this message
Guilherme Salgado (salgado) wrote :
Download full text (4.0 KiB)

On Thu, 2009-11-12 at 17:18 +0000, Edwin Grubbs wrote:
> Review: Approve code
> Hi Salgado,
>
> This looks good. A couple of minor comments below.

Thanks Edwin,

I've done the changes you suggested and the other ones we discussed
off-list. Here's the diff

=== modified file 'src-js/lazrjs/picker/picker.js'
--- src-js/lazrjs/picker/picker.js 2009-11-12 17:06:57 +0000
+++ src-js/lazrjs/picker/picker.js 2009-11-12 18:03:52 +0000
@@ -70,26 +70,6 @@

 Y.extend(Picker, Y.lazr.PrettyOverlay, {
     /**
- * Whether or not the widget should be cleared when the save event is
- * fired.
- *
- * @property clear_on_save
- * @type Boolean
- * default true
- */
- clear_on_save: true,
-
- /**
- * Whether or not the widget should be cleared when the cancel event is
- * fired.
- *
- * @property clear_on_cancel
- * @type Boolean
- * default false
- */
- clear_on_cancel: false,
-
- /**
      * The search input box node.
      *
      * @property _search_input
@@ -625,7 +605,7 @@

     /**
      * By default, the cancel event just hides the widget, but you can
- * have it also cleared by setting clear_on_save to 'true'.
+ * have it also cleared by setting clear_on_cancel to 'true'.
      *
      * @method _defaultCancel
      * @param e {Event.Facade} An Event Facade object.
@@ -633,7 +613,7 @@
      */
     _defaultCancel : function(e) {
         Picker.superclass._defaultCancel.apply(this, arguments);
- if ( this.clear_on_cancel ) {
+ if ( this.get('clear_on_cancel') ) {
             this._clear();
         }
     },
@@ -650,7 +630,7 @@
      */
     _defaultSave : function(e) {
         this.hide();
- if ( this.clear_on_save ) {
+ if ( this.get('clear_on_save') ) {
             this._clear();
         }
     },
@@ -696,6 +676,24 @@

 Picker.ATTRS = {
     /**
+ * Whether or not the search box and result list should be cleared when
+ * the save event is fired.
+ *
+ * @attribute clear_on_save
+ * @type Boolean
+ */
+ clear_on_save: { value: true },
+
+ /**
+ * Whether or not the search box and result list should be cleared when
+ * the cancel event is fired.
+ *
+ * @attribute clear_on_cancel
+ * @type Boolean
+ */
+ clear_on_cancel: { value: false },
+
+ /**
      * Minimum number of characters that need to be entered in the search
      * string input before a search event will be fired. The search string
      * will be trimmed before testing the length.

=== modified file 'src-js/lazrjs/picker/tests/picker.js'
--- src-js/lazrjs/picker/tests/picker.js 2009-11-12 17:06:57 +0000
+++ src-js/lazrjs/picker/tests/picker.js 2009-11-12 17:56:28 +0000
@@ -406,13 +406,13 @@
     },

     test_save_does_not_clear_widget_when_clear_on_save_is_false: function () {
- this.picker.render();
- this.picker.clear_on_save = false;
+ picker = new Y.Picker({clear_on_save: false});
+ picker.render();

- this.picker._search_input.set('value', 'foo');
- this.picker.fire('save', 'bogus');
+ picker._search_input.set('value', 'foo');
+ picker.fire('save', 'bogus...

Read more...

132. By Guilherme Salgado

Make the picker actually honor the new config values that specify whether or not it should clear itself.

Revision history for this message
Edwin Grubbs (edwin-grubbs) wrote :

Looks good.

133. By Guilherme Salgado

merge from trunk

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src-js/lazrjs/picker/picker.js'
2--- src-js/lazrjs/picker/picker.js 2009-10-22 19:27:45 +0000
3+++ src-js/lazrjs/picker/picker.js 2009-11-12 20:45:23 +0000
4@@ -166,6 +166,10 @@
5 * @preventable _defaultSave
6 */
7 this.publish(SAVE, { defaultFn: this._defaultSave } );
8+
9+ // Subscribe to the cancel event so that we can clear the widget when
10+ // requested.
11+ this.subscribe('cancel', this._defaultCancel);
12 },
13
14 /**
15@@ -499,7 +503,7 @@
16 // is changed, and reset the selected one to the first one.
17 this.after('batchesChange', function (e) {
18 this._syncBatchesUI();
19- if (this.get(SELECTED_BATCH) == 0){
20+ if (this.get(SELECTED_BATCH) === 0){
21 // If the attribute is already set to the same value,
22 // the 'after' events won't be triggered, so we have
23 // to trigger it manually.
24@@ -550,6 +554,21 @@
25 this._search_input.focus();
26 },
27
28+ /*
29+ * Clear all elements of the picker, resetting it to its original state.
30+ *
31+ * @method _clear
32+ * @param e {Object} The event object.
33+ * @protected
34+ */
35+ _clear: function() {
36+ this._search_input.set('value', '');
37+ this.set('error', '');
38+ this.set('results', [{}]);
39+ this._results_box.set('innerHTML', '');
40+ this.set('batches', []);
41+ },
42+
43 /**
44 * Handle clicks on the 'Search' button or entering the enter key in the
45 * search field. This fires the search event.
46@@ -585,8 +604,25 @@
47 },
48
49 /**
50- * By default, the save event simply hides the widget. The search entered
51- * by the user is passed in the first details attribute of the event.
52+ * By default, the cancel event just hides the widget, but you can
53+ * have it also cleared by setting clear_on_cancel to 'true'.
54+ *
55+ * @method _defaultCancel
56+ * @param e {Event.Facade} An Event Facade object.
57+ * @protected
58+ */
59+ _defaultCancel : function(e) {
60+ Picker.superclass._defaultCancel.apply(this, arguments);
61+ if ( this.get('clear_on_cancel') ) {
62+ this._clear();
63+ }
64+ },
65+
66+ /**
67+ * By default, the save event clears and hides the widget, but you can
68+ * have it not cleared by setting clear_on_save to 'false'. The search
69+ * entered by the user is passed in the first details attribute of the
70+ * event.
71 *
72 * @method _defaultSave
73 * @param e {Event.Facade} An Event Facade object.
74@@ -594,6 +630,9 @@
75 */
76 _defaultSave : function(e) {
77 this.hide();
78+ if ( this.get('clear_on_save') ) {
79+ this._clear();
80+ }
81 },
82
83 /**
84@@ -637,6 +676,24 @@
85
86 Picker.ATTRS = {
87 /**
88+ * Whether or not the search box and result list should be cleared when
89+ * the save event is fired.
90+ *
91+ * @attribute clear_on_save
92+ * @type Boolean
93+ */
94+ clear_on_save: { value: true },
95+
96+ /**
97+ * Whether or not the search box and result list should be cleared when
98+ * the cancel event is fired.
99+ *
100+ * @attribute clear_on_cancel
101+ * @type Boolean
102+ */
103+ clear_on_cancel: { value: false },
104+
105+ /**
106 * Minimum number of characters that need to be entered in the search
107 * string input before a search event will be fired. The search string
108 * will be trimmed before testing the length.
109
110=== modified file 'src-js/lazrjs/picker/tests/picker.js'
111--- src-js/lazrjs/picker/tests/picker.js 2009-10-21 21:43:07 +0000
112+++ src-js/lazrjs/picker/tests/picker.js 2009-11-12 20:45:23 +0000
113@@ -206,7 +206,7 @@
114 [false, true, false, true], results.hasClass(Y.lazr.ui.CSS_ODD));
115 },
116
117- test_clicking_search_button_fires_save_event: function () {
118+ test_clicking_search_button_fires_search_event: function () {
119 this.picker.render();
120
121 var bb = this.picker.get('boundingBox');
122@@ -379,6 +379,14 @@
123 }, 3000);
124 },
125
126+ test_cancel_event_hides_widget: function () {
127+ this.picker.render();
128+
129+ this.picker.fire('cancel', 'bogus');
130+ Assert.isFalse(
131+ this.picker.get('visible'), "The widget should be hidden.");
132+ },
133+
134 test_save_event_hides_widget: function () {
135 this.picker.render();
136
137@@ -387,6 +395,48 @@
138 this.picker.get('visible'), "The widget should be hidden.");
139 },
140
141+ test_save_event_clears_widget_by_default: function () {
142+ this.picker.render();
143+
144+ this.picker._search_input.set('value', 'foo');
145+ this.picker.fire('save', 'bogus');
146+ Assert.areEqual(
147+ '', this.picker._search_input.get('value'),
148+ "The widget hasn't been cleared");
149+ },
150+
151+ test_save_does_not_clear_widget_when_clear_on_save_is_false: function () {
152+ picker = new Y.Picker({clear_on_save: false});
153+ picker.render();
154+
155+ picker._search_input.set('value', 'foo');
156+ picker.fire('save', 'bogus');
157+ Assert.areEqual(
158+ 'foo', picker._search_input.get('value'),
159+ "The widget has been cleared but it should not");
160+ },
161+
162+ test_cancel_event_does_not_clear_widget_by_default: function () {
163+ this.picker.render();
164+
165+ this.picker._search_input.set('value', 'foo');
166+ this.picker.fire('cancel', 'bogus');
167+ Assert.areEqual(
168+ 'foo', this.picker._search_input.get('value'),
169+ "The widget has been cleared but it should not");
170+ },
171+
172+ test_cancel_event_clears_widget_when_clear_on_cancel_is_true: function () {
173+ picker = new Y.Picker({clear_on_cancel: true});
174+ picker.render();
175+
176+ picker._search_input.set('value', 'foo');
177+ picker.fire('cancel', 'bogus');
178+ Assert.areEqual(
179+ '', picker._search_input.get('value'),
180+ "The widget hasn't been cleared");
181+ },
182+
183 test_search_clears_any_eror: function () {
184 this.picker.render();
185 this.picker.set('error', "An error");

Subscribers

People subscribed via source and target branches