Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50659 views
1
// Copyright (c) IPython Development Team.
2
// Distributed under the terms of the Modified BSD License.
3
4
define([
5
"widgets/js/widget",
6
"jquery",
7
"bootstrap",
8
], function(widget, $){
9
10
var ButtonView = widget.DOMWidgetView.extend({
11
render : function(){
12
/**
13
* Called when view is rendered.
14
*/
15
this.setElement($("<button />")
16
.addClass('btn btn-default'));
17
this.$el.attr("data-toggle", "tooltip");
18
this.model.on('change:button_style', function(model, value) {
19
this.update_button_style();
20
}, this);
21
this.update_button_style('');
22
23
this.update(); // Set defaults.
24
},
25
26
update : function(){
27
/**
28
* Update the contents of this view
29
*
30
* Called when the model is changed. The model may have been
31
* changed by another view or by a state update from the back-end.
32
*/
33
this.$el.prop("disabled", this.model.get("disabled"));
34
this.$el.attr("title", this.model.get("tooltip"));
35
36
var description = this.model.get("description");
37
var icon = this.model.get("icon");
38
if (description.trim().length === 0 && icon.trim().length ===0) {
39
this.$el.html("&nbsp;"); // Preserve button height
40
} else {
41
this.$el.text(description);
42
$('<i class="fa"></i>').prependTo(this.$el).addClass(icon);
43
}
44
45
return ButtonView.__super__.update.apply(this);
46
},
47
48
update_button_style: function(previous_trait_value) {
49
var class_map = {
50
primary: ['btn-primary'],
51
success: ['btn-success'],
52
info: ['btn-info'],
53
warning: ['btn-warning'],
54
danger: ['btn-danger']
55
};
56
this.update_mapped_classes(class_map, 'button_style', previous_trait_value);
57
},
58
59
events: {
60
// Dictionary of events and their handlers.
61
'click': '_handle_click',
62
},
63
64
_handle_click: function(){
65
/**
66
* Handles when the button is clicked.
67
*/
68
this.send({event: 'click'});
69
},
70
});
71
72
return {
73
'ButtonView': ButtonView,
74
};
75
});
76
77