Class: IRuby::Input::InputForm
- Inherits:
-
Widget
- Object
- Erector::Widget
- Widget
- IRuby::Input::InputForm
show all
- Defined in:
- lib/iruby/input/form.rb
Instance Method Summary
collapse
Methods inherited from Widget
builder, #content, #widget_display, #widget_join
Instance Method Details
#submit ⇒ Object
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/iruby/input/form.rb', line 65
def submit
result = MultiJson.load(Kernel.instance.session.recv_input)
unless result.has_key? @id
submit
else
Display.clear_output
result[@id]
end
end
|
53
54
55
56
|
# File 'lib/iruby/input/form.rb', line 53
def widget_css
spacing = '#iruby-form > * { margin-bottom: 5px; }'
widget_join :widget_css, spacing, *@fields, *@buttons
end
|
58
59
60
61
62
63
|
# File 'lib/iruby/input/form.rb', line 58
def widget_html
form id: 'iruby-form', class: 'col-md-12' do
@fields.each {|field| widget field}
end
@buttons.each {|button| widget button}
end
|
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/iruby/input/form.rb', line 8
def widget_js
javascript = " var remove = function () {\n Jupyter.notebook.kernel.send_input_reply(\n JSON.stringify({\n '\#{@id = SecureRandom.uuid}': null\n })\n );\n };\n \n $(\"#iruby-form\").on(\"remove\", remove);\n\n $('#iruby-form').submit(function() {\n var result = {};\n $(this).off('remove', remove);\n\n $('[data-iruby-key]').each(function() {\n if ($(this).data('iruby-key')) {\n var value = $(this).data('iruby-value');\n if (value) {\n result[$(this).data('iruby-key')] = value;\n }\n }\n });\n\n Jupyter.notebook.kernel.send_input_reply(\n JSON.stringify({'\#{@id}': result})\n );\n \n $(this).remove();\n return false;\n });\n\n $('#iruby-form').keydown(function(event) {\n if (event.keyCode == 13 && !event.shiftKey) { \n $('#iruby-form').submit();\n } else if (event.keyCode == 27) { \n $('#iruby-form').remove(); \n }\n });\n JS\n\n widget_join :widget_js, javascript, *@fields, *@buttons\nend\n"
|