Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50659 views
1
//----------------------------------------------------------------------------
2
// Copyright (C) 2013 The IPython Development Team
3
//
4
// Distributed under the terms of the BSD License. The full license is in
5
// the file COPYING, distributed as part of this software.
6
//----------------------------------------------------------------------------
7
8
//============================================================================
9
// BoolWidget
10
//============================================================================
11
12
/**
13
* @module IPython
14
* @namespace IPython
15
**/
16
17
define(["widgets/js/widget"], function(WidgetManager){
18
19
var CheckboxView = IPython.DOMWidgetView.extend({
20
render : function(){
21
// Called when view is rendered.
22
this.$el
23
.addClass('widget-hbox-single');
24
this.$label = $('<div />')
25
.addClass('widget-hlabel')
26
.appendTo(this.$el)
27
.hide();
28
this.$checkbox = $('<input />')
29
.attr('type', 'checkbox')
30
.appendTo(this.$el)
31
.click($.proxy(this.handle_click, this));
32
33
this.$el_to_style = this.$checkbox; // Set default element to style
34
this.update(); // Set defaults.
35
},
36
37
handle_click: function() {
38
// Handles when the checkbox is clicked.
39
40
// Calling model.set will trigger all of the other views of the
41
// model to update.
42
var value = this.model.get('value');
43
this.model.set('value', ! value, {updated_view: this});
44
this.touch();
45
},
46
47
update : function(options){
48
// Update the contents of this view
49
//
50
// Called when the model is changed. The model may have been
51
// changed by another view or by a state update from the back-end.
52
this.$checkbox.prop('checked', this.model.get('value'));
53
54
if (options === undefined || options.updated_view != this) {
55
var disabled = this.model.get('disabled');
56
this.$checkbox.prop('disabled', disabled);
57
58
var description = this.model.get('description');
59
if (description.trim().length === 0) {
60
this.$label.hide();
61
} else {
62
this.$label.text(description);
63
this.$label.show();
64
}
65
}
66
return CheckboxView.__super__.update.apply(this);
67
},
68
69
});
70
WidgetManager.register_widget_view('CheckboxView', CheckboxView);
71
72
73
var ToggleButtonView = IPython.DOMWidgetView.extend({
74
render : function() {
75
// Called when view is rendered.
76
var that = this;
77
this.setElement($('<button />')
78
.addClass('btn')
79
.attr('type', 'button')
80
.on('click', function (e) {
81
e.preventDefault();
82
that.handle_click();
83
}));
84
85
this.update(); // Set defaults.
86
},
87
88
update : function(options){
89
// Update the contents of this view
90
//
91
// Called when the model is changed. The model may have been
92
// changed by another view or by a state update from the back-end.
93
if (this.model.get('value')) {
94
this.$el.addClass('active');
95
} else {
96
this.$el.removeClass('active');
97
}
98
99
if (options === undefined || options.updated_view != this) {
100
101
var disabled = this.model.get('disabled');
102
this.$el.prop('disabled', disabled);
103
104
var description = this.model.get('description');
105
if (description.trim().length === 0) {
106
this.$el.html("&nbsp;"); // Preserve button height
107
} else {
108
this.$el.text(description);
109
}
110
}
111
return ToggleButtonView.__super__.update.apply(this);
112
},
113
114
handle_click: function(e) {
115
// Handles and validates user input.
116
117
// Calling model.set will trigger all of the other views of the
118
// model to update.
119
var value = this.model.get('value');
120
this.model.set('value', ! value, {updated_view: this});
121
this.touch();
122
},
123
});
124
WidgetManager.register_widget_view('ToggleButtonView', ToggleButtonView);
125
});
126
127