##// END OF EJS Templates
Valid widget
Sylvain Corlay -
Show More
@@ -1477,6 +1477,12 b' h6:hover .anchor-link {'
1477 .widget_item .dropdown-menu li a {
1477 .widget_item .dropdown-menu li a {
1478 color: inherit;
1478 color: inherit;
1479 }
1479 }
1480 .widget-valid {
1481 margin-top: 9px;
1482 margin-bottom: 10px;
1483 margin-left: 3px;
1484 margin-right: 3px;
1485 }
1480 .widget-hbox {
1486 .widget-hbox {
1481 /* Horizontal widgets */
1487 /* Horizontal widgets */
1482 /* Old browsers */
1488 /* Old browsers */
@@ -10269,6 +10269,12 b' h6:hover .anchor-link {'
10269 .widget_item .dropdown-menu li a {
10269 .widget_item .dropdown-menu li a {
10270 color: inherit;
10270 color: inherit;
10271 }
10271 }
10272 .widget-valid {
10273 margin-top: 9px;
10274 margin-bottom: 10px;
10275 margin-left: 3px;
10276 margin-right: 3px;
10277 }
10272 .widget-hbox {
10278 .widget-hbox {
10273 /* Horizontal widgets */
10279 /* Horizontal widgets */
10274 /* Old browsers */
10280 /* Old browsers */
@@ -41,19 +41,19 b' define(['
41 /**
41 /**
42 * Handles when the checkbox is clicked.
42 * Handles when the checkbox is clicked.
43 *
43 *
44 * Calling model.set will trigger all of the other views of the
44 * Calling model.set will trigger all of the other views of the
45 * model to update.
45 * model to update.
46 */
46 */
47 var value = this.model.get('value');
47 var value = this.model.get('value');
48 this.model.set('value', ! value, {updated_view: this});
48 this.model.set('value', ! value, {updated_view: this});
49 this.touch();
49 this.touch();
50 },
50 },
51
51
52 update : function(options){
52 update : function(options){
53 /**
53 /**
54 * Update the contents of this view
54 * Update the contents of this view
55 *
55 *
56 * Called when the model is changed. The model may have been
56 * Called when the model is changed. The model may have been
57 * changed by another view or by a state update from the back-end.
57 * changed by another view or by a state update from the back-end.
58 */
58 */
59 this.$checkbox.prop('checked', this.model.get('value'));
59 this.$checkbox.prop('checked', this.model.get('value'));
@@ -71,7 +71,6 b' define(['
71 }
71 }
72 return CheckboxView.__super__.update.apply(this);
72 return CheckboxView.__super__.update.apply(this);
73 },
73 },
74
75 });
74 });
76
75
77
76
@@ -107,12 +106,12 b' define(['
107 };
106 };
108 this.update_mapped_classes(class_map, 'button_style', previous_trait_value);
107 this.update_mapped_classes(class_map, 'button_style', previous_trait_value);
109 },
108 },
110
109
111 update : function(options){
110 update : function(options){
112 /**
111 /**
113 * Update the contents of this view
112 * Update the contents of this view
114 *
113 *
115 * Called when the model is changed. The model may have been
114 * Called when the model is changed. The model may have been
116 * changed by another view or by a state update from the back-end.
115 * changed by another view or by a state update from the back-end.
117 */
116 */
118 if (this.model.get('value')) {
117 if (this.model.get('value')) {
@@ -136,12 +135,12 b' define(['
136 }
135 }
137 return ToggleButtonView.__super__.update.apply(this);
136 return ToggleButtonView.__super__.update.apply(this);
138 },
137 },
139
138
140 handle_click: function(e) {
139 handle_click: function(e) {
141 /**
140 /**
142 * Handles and validates user input.
141 * Handles and validates user input.
143 *
142 *
144 * Calling model.set will trigger all of the other views of the
143 * Calling model.set will trigger all of the other views of the
145 * model to update.
144 * model to update.
146 */
145 */
147 var value = this.model.get('value');
146 var value = this.model.get('value');
@@ -150,8 +149,41 b' define(['
150 },
149 },
151 });
150 });
152
151
152
153 var ValidView = widget.DOMWidgetView.extend({
154 render: function() {
155 /**
156 * Called when view is rendered.
157 */
158 this.$el.addClass("fa widget-valid");
159 this.model.on("change:value", this.update, this);
160 this.update();
161 },
162 update: function() {
163 /**
164 * Update the contents of this view
165 *
166 * Called when the model is changed. The model may have been
167 * changed by another view or by a state update from the back-end.
168 */
169 if (this.model.get("value")) {
170 this.$el.removeClass("fa-close").addClass("fa-check");
171 this.after_displayed(function() {
172 this.$el.css("color", "green");
173 }, this);
174 } else {
175 this.$el.removeClass("fa-check").addClass("fa-close");
176 this.after_displayed(function() {
177 this.$el.css("color", "red");
178 }, this);
179 }
180 }
181 });
182
183
153 return {
184 return {
154 'CheckboxView': CheckboxView,
185 'CheckboxView': CheckboxView,
155 'ToggleButtonView': ToggleButtonView,
186 'ToggleButtonView': ToggleButtonView,
187 'ValidView': ValidView,
156 };
188 };
157 });
189 });
@@ -209,6 +209,13 b''
209 color: inherit;
209 color: inherit;
210 }
210 }
211
211
212 .widget-valid {
213 margin-top: 9px;
214 margin-bottom: 10px;
215 margin-left: 3px;
216 margin-right: 3px;
217 }
218
212 .widget-hbox {
219 .widget-hbox {
213 /* Horizontal widgets */
220 /* Horizontal widgets */
214 .hbox();
221 .hbox();
@@ -2,7 +2,7 b' from .widget import Widget, DOMWidget, CallbackDispatcher, register'
2
2
3 from .trait_types import Color
3 from .trait_types import Color
4
4
5 from .widget_bool import Checkbox, ToggleButton
5 from .widget_bool import Checkbox, ToggleButton, Valid
6 from .widget_button import Button
6 from .widget_button import Button
7 from .widget_box import Box, FlexBox, HBox, VBox
7 from .widget_box import Box, FlexBox, HBox, VBox
8 from .widget_float import FloatText, BoundedFloatText, FloatSlider, FloatProgress, FloatRangeSlider
8 from .widget_float import FloatText, BoundedFloatText, FloatSlider, FloatProgress, FloatRangeSlider
@@ -60,17 +60,29 b' class ToggleButton(_Bool):'
60 icon: str
60 icon: str
61 font-awesome icon name
61 font-awesome icon name
62 """
62 """
63
64 _view_name = Unicode('ToggleButtonView', sync=True)
63 _view_name = Unicode('ToggleButtonView', sync=True)
65 tooltip = Unicode(help="Tooltip caption of the toggle button.", sync=True)
64 tooltip = Unicode(help="Tooltip caption of the toggle button.", sync=True)
66 icon = Unicode('', help= "Font-awesome icon.", sync=True)
65 icon = Unicode('', help= "Font-awesome icon.", sync=True)
67
66
68 button_style = CaselessStrEnum(
67 button_style = CaselessStrEnum(
69 values=['primary', 'success', 'info', 'warning', 'danger', ''],
68 values=['primary', 'success', 'info', 'warning', 'danger', ''],
70 default_value='', allow_none=True, sync=True, help="""Use a
69 default_value='', allow_none=True, sync=True, help="""Use a
71 predefined styling for the button.""")
70 predefined styling for the button.""")
72
71
73
72
73 @register('IPython.Valid')
74 class Valid(_Bool):
75
76 """Displays a boolean `value` in the form of a green check (True / valid)
77 or a red cross (False / invalid).
78
79 Parameters
80 ----------
81 value: {True,False}
82 value of the Valid widget
83 """
84 _view_name = Unicode('ValidView', sync=True)
85
74 # Remove in IPython 4.0
86 # Remove in IPython 4.0
75 CheckboxWidget = DeprecatedClass(Checkbox, 'CheckboxWidget')
87 CheckboxWidget = DeprecatedClass(Checkbox, 'CheckboxWidget')
76 ToggleButtonWidget = DeprecatedClass(ToggleButton, 'ToggleButtonWidget')
88 ToggleButtonWidget = DeprecatedClass(ToggleButton, 'ToggleButtonWidget')
General Comments 0
You need to be logged in to leave comments. Login now