mumuki-laboratory 7.6.1 → 7.7.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +193 -2
- data/Rakefile +3 -0
- data/app/assets/javascripts/mumuki_laboratory/application.js +0 -1
- data/app/assets/javascripts/mumuki_laboratory/application/assets-loader.js +1 -1
- data/app/assets/javascripts/mumuki_laboratory/application/bridge.js +36 -10
- data/app/assets/javascripts/mumuki_laboratory/application/button.js +90 -1
- data/app/assets/javascripts/mumuki_laboratory/application/codemirror.js +1 -0
- data/app/assets/javascripts/mumuki_laboratory/application/custom-editor.js +46 -4
- data/app/assets/javascripts/mumuki_laboratory/application/discussions.js +14 -13
- data/app/assets/javascripts/mumuki_laboratory/application/kids.js +73 -36
- data/app/assets/javascripts/mumuki_laboratory/application/progress.js +3 -0
- data/app/assets/javascripts/mumuki_laboratory/application/results-renderer.js +51 -0
- data/app/assets/javascripts/mumuki_laboratory/application/submission.js +184 -35
- data/app/assets/stylesheets/mumuki_laboratory/application/_modules.scss +1 -0
- data/app/assets/stylesheets/mumuki_laboratory/application/modules/_discussion.scss +43 -5
- data/app/assets/stylesheets/mumuki_laboratory/application/modules/_kids.scss +3 -3
- data/app/assets/stylesheets/mumuki_laboratory/application/modules/_kindergarten.scss +55 -0
- data/app/controllers/assets_controller.rb +2 -0
- data/app/controllers/concerns/with_authorization.rb +4 -0
- data/app/controllers/concerns/with_user_discussion_validation.rb +14 -0
- data/app/controllers/discussions_controller.rb +6 -14
- data/app/controllers/discussions_messages_controller.rb +10 -1
- data/app/controllers/exercise_solutions_controller.rb +4 -2
- data/app/helpers/application_helper.rb +9 -5
- data/app/helpers/discussions_helper.rb +37 -23
- data/app/helpers/exercise_input_helper.rb +1 -1
- data/app/helpers/icons_helper.rb +3 -3
- data/app/views/book_discussions/index.html.erb +3 -3
- data/app/views/discussions/_message.html.erb +20 -8
- data/app/views/discussions/index.html.erb +0 -1
- data/app/views/discussions/new.html.erb +33 -0
- data/app/views/discussions/show.html.erb +18 -46
- data/app/views/exercise_solutions/_contextualization_results_container.html.erb +1 -1
- data/app/views/exercise_solutions/_results_title.html.erb +2 -2
- data/app/views/exercises/_read_only.html.erb +33 -6
- data/app/views/layouts/_copyright.html.erb +1 -1
- data/app/views/layouts/_discussions.html.erb +21 -3
- data/app/views/layouts/_social_media.html.erb +3 -3
- data/app/views/layouts/_test_results.html.erb +1 -1
- data/app/views/layouts/exercise_inputs/editors/_custom.html.erb +1 -1
- data/app/views/layouts/exercise_inputs/forms/_kids_form.html.erb +1 -1
- data/app/views/layouts/exercise_inputs/forms/_problem_form.html.erb +1 -1
- data/app/views/layouts/exercise_inputs/layouts/_input_bottom.html.erb +1 -1
- data/app/views/layouts/exercise_inputs/layouts/_input_kindergarten.html.erb +40 -0
- data/app/views/layouts/exercise_inputs/layouts/{_input_kids.html.erb → _input_primary.html.erb} +1 -1
- data/app/views/layouts/exercise_inputs/layouts/_input_right.html.erb +1 -1
- data/app/views/layouts/modals/_kids_context.html.erb +1 -8
- data/app/views/user_mailer/1st_reminder.html.erb +3 -3
- data/app/views/user_mailer/1st_reminder.text.erb +1 -1
- data/app/views/user_mailer/2nd_reminder.html.erb +3 -3
- data/app/views/user_mailer/2nd_reminder.text.erb +1 -1
- data/app/views/user_mailer/3rd_reminder.html.erb +3 -3
- data/app/views/user_mailer/3rd_reminder.text.erb +1 -1
- data/app/views/user_mailer/no_submissions_reminder.html.erb +3 -3
- data/app/views/user_mailer/no_submissions_reminder.text.erb +1 -1
- data/config/routes.rb +2 -1
- data/lib/mumuki/laboratory/controllers/results_rendering.rb +1 -2
- data/lib/mumuki/laboratory/locales/en.yml +8 -2
- data/lib/mumuki/laboratory/locales/es.yml +7 -1
- data/lib/mumuki/laboratory/locales/pt.yml +8 -4
- data/lib/mumuki/laboratory/version.rb +1 -1
- data/spec/controllers/confirmations_controller_spec.rb +1 -1
- data/spec/controllers/discussions_messages_controller_spec.rb +73 -0
- data/spec/controllers/exercise_solutions_controller_spec.rb +41 -6
- data/spec/dummy/db/schema.rb +12 -1
- data/spec/features/discussion_flow_spec.rb +190 -0
- data/spec/features/exercise_flow_spec.rb +1 -1
- data/spec/features/menu_bar_spec.rb +88 -7
- data/spec/helpers/breadcrumbs_helper_spec.rb +1 -1
- data/spec/javascripts/bridge-spec.js +5 -0
- data/spec/javascripts/csrf-token-spec.js +7 -0
- data/spec/javascripts/elipsis-spec.js +25 -0
- data/spec/javascripts/results-renderers-spec.js +17 -0
- data/spec/javascripts/spec-helper.js +30 -0
- data/spec/javascripts/speech-bubble-renderer-spec.js +11 -0
- data/spec/javascripts/timeout-spec.js +5 -0
- data/spec/javascripts/timer-spec.js +5 -0
- data/spec/teaspoon_env.rb +187 -0
- metadata +33 -9
- data/app/views/layouts/modals/_new_discussion.html.erb +0 -27
- data/vendor/assets/javascripts/hotjar.js +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa8619681047d1ea5b8230abc24e7b4b38c63f722d355a3facd956d725b0b3dd
|
4
|
+
data.tar.gz: bdefac6e50c9a9cb6950222bc822f8460e095f47a3602ae7ad86b4c3c41ea634
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a91405f88b73103163b212bbc08b6a00da9f1d109e13630d4713094cf32736621e38de66d007ab739e86bca4f7782a8081faabf50425e4e45dc49c8022ced0d
|
7
|
+
data.tar.gz: 9c7a7398eb308154dc585d8d4d3401e27ced3322314bffbbf5a016ef951aeeeb3c109860afb4457bd93f6b5f509b0f36d7b321baa4c4ae26c445e7c3b3275840
|
data/README.md
CHANGED
@@ -135,6 +135,15 @@ rails s
|
|
135
135
|
bundle exec rspec
|
136
136
|
```
|
137
137
|
|
138
|
+
## Running JS tests
|
139
|
+
|
140
|
+
> You need first to download [geckodriver](https://github.com/mozilla/geckodriver/releases/download/v0.27.0/geckodriver-v0.27.0-linux64.tar.gz), uncrompress
|
141
|
+
> it and add it to your path
|
142
|
+
|
143
|
+
```bash
|
144
|
+
bundle exec rake teaspoon
|
145
|
+
```
|
146
|
+
|
138
147
|
## JavaScript API Docs
|
139
148
|
|
140
149
|
In order to be customized by runners, Laboratory exposes the following selectors and methods
|
@@ -158,7 +167,9 @@ which are granted to be safe and stable.
|
|
158
167
|
* `.mu-kids-submit-button`
|
159
168
|
* `.mu-multiple-scenarios`
|
160
169
|
* `.mu-scenarios`
|
170
|
+
* `.mu-submit-button`
|
161
171
|
* `#mu-actual-state-text`
|
172
|
+
* `#mu-${languageName}-custom-editor`
|
162
173
|
* `#mu-custom-editor-default-value`
|
163
174
|
* `#mu-custom-editor-extra`
|
164
175
|
* `#mu-custom-editor-test`
|
@@ -170,7 +181,6 @@ which are granted to be safe and stable.
|
|
170
181
|
* `.mu-kids-gbs-board-initial`: Use `.mu-initial-state` instead
|
171
182
|
* `.mu-state-final`: Use `.mu-final-state` instead
|
172
183
|
* `.mu-state-initial`: Use `.mu-initial-state` instead
|
173
|
-
* `#kids-context`: Use `.mu-kids-context` instead
|
174
184
|
* `#kids-results-aborted`: Use `.mu-kids-results-aborted` instead
|
175
185
|
* `#kids-results`: Use `.mu-kids-results` instead
|
176
186
|
|
@@ -178,6 +188,8 @@ which are granted to be safe and stable.
|
|
178
188
|
|
179
189
|
* `mumuki.bridge.Laboratory`
|
180
190
|
* `.runTests`
|
191
|
+
* `mumuki.CustomEditor`
|
192
|
+
* `addSource`
|
181
193
|
* `mumuki.editor`
|
182
194
|
* `formatContent`
|
183
195
|
* `reset`
|
@@ -191,6 +203,7 @@ which are granted to be safe and stable.
|
|
191
203
|
* `scaleBlocksArea`
|
192
204
|
* `scaleState`
|
193
205
|
* `showResult`
|
206
|
+
* `showContext`
|
194
207
|
* `mumuki.renderers`
|
195
208
|
* `SpeechBubbleRenderer`
|
196
209
|
* `renderSpeechBubbleResultItem`
|
@@ -205,6 +218,9 @@ which are granted to be safe and stable.
|
|
205
218
|
* `setUpDeleteFiles`
|
206
219
|
* `setUpDeleteFile`
|
207
220
|
* `updateButtonsVisibility`
|
221
|
+
* `mumuki.submission`
|
222
|
+
* `processSolution`
|
223
|
+
* `registerContentSyncer`
|
208
224
|
* `mumuki.version`
|
209
225
|
|
210
226
|
### Bridge Response Format
|
@@ -213,7 +229,6 @@ which are granted to be safe and stable.
|
|
213
229
|
{
|
214
230
|
"status": "passed|passed_with_warnings|failed",
|
215
231
|
"guide_finished_by_solution": "boolean",
|
216
|
-
"class_for_progress_list_item": "string",
|
217
232
|
"html": "string",
|
218
233
|
"remaining_attempts_html": "string" ,
|
219
234
|
"title_html": "string", // kids-only
|
@@ -243,6 +258,182 @@ which are granted to be safe and stable.
|
|
243
258
|
2. Laboratory Kids Layout Initialization
|
244
259
|
3. Runner Editor HTML
|
245
260
|
|
261
|
+
## Custom editors
|
262
|
+
|
263
|
+
Mumuki provides several editor types: code editors, multiple choice, file upload, and so on.
|
264
|
+
However, some runners will require custom editors in order to provide better ways of entering
|
265
|
+
solutions.
|
266
|
+
|
267
|
+
The process to do so is not difficult, but tricky, since there are a few hooks you need to implement. Let's look at them:
|
268
|
+
|
269
|
+
### 1. Before state: adding layout assets
|
270
|
+
|
271
|
+
If you need to provide a custom editor, chances are that you also need to provide assets to augment the layout, e.g. providing ways
|
272
|
+
to render some custom components on descriptions or corollaries. That code will be included first.
|
273
|
+
|
274
|
+
In order to do that, add to your runner the layout html, css and js code. Layout code has no further requirements. It can customize any public selector previously.
|
275
|
+
|
276
|
+
Although it is not required, it is recommended that your layout code works with any of the mumuki layouts:
|
277
|
+
|
278
|
+
* `input_right`
|
279
|
+
* `input_bottom`
|
280
|
+
* `input_primary`
|
281
|
+
* `input_kindergarten`
|
282
|
+
|
283
|
+
:warning: Not all the selectors will be available to all layouts.
|
284
|
+
|
285
|
+
Then expose code in the `MetadataHook`:
|
286
|
+
|
287
|
+
```ruby
|
288
|
+
class ... < Mumukit::Hook
|
289
|
+
def metadata
|
290
|
+
{
|
291
|
+
layout_assets_urls: {
|
292
|
+
js: [
|
293
|
+
'assets/....'
|
294
|
+
],
|
295
|
+
css: [
|
296
|
+
'assets/....'
|
297
|
+
],
|
298
|
+
html: [
|
299
|
+
'assets/....'
|
300
|
+
]
|
301
|
+
}
|
302
|
+
}
|
303
|
+
end
|
304
|
+
end
|
305
|
+
```
|
306
|
+
|
307
|
+
Finally, it is _recommended_ that you layout code calls `mumuki.assetsLoadedFor('layout')` when fully loaded.
|
308
|
+
|
309
|
+
That's it!
|
310
|
+
|
311
|
+
### 2. Adding custom editor assets
|
312
|
+
|
313
|
+
The process for registering custom editors is more involving.
|
314
|
+
|
315
|
+
#### 2.1 Add your assets and expose them
|
316
|
+
|
317
|
+
Add your js, css and html assets to your runner, and expose them in `MetadataHook`:
|
318
|
+
|
319
|
+
```ruby
|
320
|
+
class ... < Mumukit::Hook
|
321
|
+
def metadata
|
322
|
+
{
|
323
|
+
editor_assets_urls: {
|
324
|
+
js: [
|
325
|
+
'assets/....'
|
326
|
+
],
|
327
|
+
css: [
|
328
|
+
'assets/....'
|
329
|
+
],
|
330
|
+
html: [
|
331
|
+
'assets/....'
|
332
|
+
]
|
333
|
+
}
|
334
|
+
}
|
335
|
+
end
|
336
|
+
end
|
337
|
+
```
|
338
|
+
|
339
|
+
These assets will only be loaded when the editor `custom` is used.
|
340
|
+
|
341
|
+
#### 2.2 Add your components to the custom editor
|
342
|
+
|
343
|
+
Using JavaScript, append your components the custom-editor root, which can be found using the following selectors:
|
344
|
+
|
345
|
+
* `mu-${languageName}-custom-editor`
|
346
|
+
* `#mu-${languageName}-custom-editor`
|
347
|
+
* `.mu-${languageName}-custom-editor`
|
348
|
+
|
349
|
+
```javascript
|
350
|
+
$('#mu-mylang-custom-editor').append(/* ... */)
|
351
|
+
```
|
352
|
+
|
353
|
+
#### 2.3 Extract the test
|
354
|
+
|
355
|
+
If necessary, read the test definition from `#mu-custom-editor-test`, and plump into your custom components
|
356
|
+
|
357
|
+
```javascript
|
358
|
+
const test = $('#mu-custom-editor-test').val()
|
359
|
+
//...use test...
|
360
|
+
```
|
361
|
+
|
362
|
+
#### 2.4 Exposing your content
|
363
|
+
|
364
|
+
Before sending a submission, mumuki needs to be able to your read you editor components
|
365
|
+
contents. There are two different approaches:
|
366
|
+
|
367
|
+
* Register a syncer that writes `#mu-custom-editor-value` or any other custom editor selectors
|
368
|
+
* Add one or more content sources
|
369
|
+
|
370
|
+
```javascript
|
371
|
+
// simplest method - you can register just one
|
372
|
+
mumuki.submission.registerContentSyncer(() => {
|
373
|
+
// ... write here your custom component content...
|
374
|
+
$('#mu-custom-editor-value').val(/* ... */);
|
375
|
+
});
|
376
|
+
|
377
|
+
// alternate method
|
378
|
+
// you can register many sources
|
379
|
+
mumuki.CustomEditor.addSource({
|
380
|
+
getContent() {
|
381
|
+
return { name: "solution[content]", value: /* ... */ } ;
|
382
|
+
}
|
383
|
+
});
|
384
|
+
```
|
385
|
+
|
386
|
+
#### 2.5 Optional: Sending your solution to the server programmatically
|
387
|
+
|
388
|
+
Your solution will be automatically sent to the client when the submit button is pressed. However,
|
389
|
+
if you need to trigger submission process programmatically, call `mumuki.submission.processSolution`:
|
390
|
+
|
391
|
+
```javascript
|
392
|
+
mumuki.submission.processSolution({solution: {content: /* ... */}});
|
393
|
+
```
|
394
|
+
|
395
|
+
#### 2.6 Optional: customizing your submit button
|
396
|
+
|
397
|
+
You can alternatively override the default submit button UI and behaviour, by replacing it with a custom component. In order to
|
398
|
+
do that, override the `.mu-submit-button` or the kids-specific `.mu-kids-submit-button`:
|
399
|
+
|
400
|
+
```javascript
|
401
|
+
$(".mu-submit-button").html(/* ... */);
|
402
|
+
```
|
403
|
+
|
404
|
+
However, doing this is tricky, since you will need to manually update the UI and connecting to the server. See:
|
405
|
+
|
406
|
+
* `mumuki.kids.showResult`
|
407
|
+
* `mumuki.bridge.Laboratory.runTests`
|
408
|
+
* `mumuki.updateProgressBarAndShowModal`
|
409
|
+
|
410
|
+
#### 2.7 Register kids scalers
|
411
|
+
|
412
|
+
Kids layouts have some special areas:
|
413
|
+
|
414
|
+
* _state area_: its display initial and/or final states of the exercise
|
415
|
+
* _blocks area_: a workspace that contains the building blocks of the solution - which are not necessary programming or blockly blocks, actually
|
416
|
+
|
417
|
+
If you want to support kids layouts, you **need** to register scalers that will be called when device is resized. Skip this step otherwise.
|
418
|
+
|
419
|
+
```javascript
|
420
|
+
mumuki.kids.registerStateScaler(($state, fullMargin, preferredWidth, preferredHeight) => {
|
421
|
+
// ... resize your components ...
|
422
|
+
});
|
423
|
+
|
424
|
+
mumuki.kids.registerBlocksAreaScaler(($blocks) => {
|
425
|
+
// ... resize your components ...
|
426
|
+
});
|
427
|
+
```
|
428
|
+
|
429
|
+
#### 2.8 Notify when your assets have been loaded
|
430
|
+
|
431
|
+
In order to remove loading spinners, you will need to call `mumuki.assetsLoadedFor` when your code is ready.
|
432
|
+
|
433
|
+
```javascript
|
434
|
+
mumuki.assetsLoadedFor('editor');
|
435
|
+
```
|
436
|
+
|
246
437
|
## Transparent Navigation API Docs
|
247
438
|
|
248
439
|
In order to be able to link content, laboratory exposes slug-based routes that will redirect to the actual
|
data/Rakefile
CHANGED
@@ -27,6 +27,9 @@ require 'rspec/core/rake_task'
|
|
27
27
|
desc "Run all specs in spec directory (excluding plugin specs)"
|
28
28
|
RSpec::Core::RakeTask.new(:spec => 'app:db:test:prepare')
|
29
29
|
|
30
|
+
desc "Run the javascript specs"
|
31
|
+
task :teaspoon => "app:teaspoon"
|
32
|
+
|
30
33
|
task default: :spec
|
31
34
|
|
32
35
|
|
@@ -1,3 +1,11 @@
|
|
1
|
+
/**
|
2
|
+
* @typedef {{status: string, test_results: [{status: string, title: string}]}} ClientResult
|
3
|
+
*/
|
4
|
+
|
5
|
+
/**
|
6
|
+
* @typedef {{solution: object, client_result?: ClientResult}} Submission
|
7
|
+
*/
|
8
|
+
|
1
9
|
var mumuki = mumuki || {};
|
2
10
|
|
3
11
|
(function (mumuki) {
|
@@ -19,19 +27,28 @@ var mumuki = mumuki || {};
|
|
19
27
|
return lastSubmission.result && lastSubmission.result.status !== 'aborted';
|
20
28
|
}
|
21
29
|
|
22
|
-
function sendNewSolution(
|
30
|
+
function sendNewSolution(submission){
|
23
31
|
var token = new mumuki.CsrfToken();
|
24
32
|
var request = token.newRequest({
|
25
33
|
type: 'POST',
|
26
34
|
url: window.location.origin + window.location.pathname + '/solutions' + window.location.search,
|
27
|
-
data:
|
35
|
+
data: submission
|
28
36
|
});
|
29
37
|
|
30
|
-
return $.ajax(request).done(function (result) {
|
31
|
-
lastSubmission = { content: solution, result: result };
|
38
|
+
return $.ajax(request).then(preRenderResult).done(function (result) {
|
39
|
+
lastSubmission = { content: {solution: submission.solution}, result: result };
|
32
40
|
});
|
33
41
|
}
|
34
42
|
|
43
|
+
|
44
|
+
/**
|
45
|
+
* Pre-renders some html parts of submission UI
|
46
|
+
* */
|
47
|
+
function preRenderResult(result) {
|
48
|
+
result.class_for_progress_list_item = mumuki.renderers.progressListItemClassForStatus(result.status, true)
|
49
|
+
return result;
|
50
|
+
}
|
51
|
+
|
35
52
|
mumuki.load(function () {
|
36
53
|
lastSubmission = {};
|
37
54
|
});
|
@@ -42,8 +59,12 @@ var mumuki = mumuki || {};
|
|
42
59
|
// Public API
|
43
60
|
// ==========
|
44
61
|
|
45
|
-
|
46
|
-
|
62
|
+
/**
|
63
|
+
* Runs tests for the current exercise using the given submission
|
64
|
+
* content.
|
65
|
+
*
|
66
|
+
* @param {object} content the content object
|
67
|
+
* */
|
47
68
|
runTests: function(content) {
|
48
69
|
return this._submitSolution({ solution: content });
|
49
70
|
},
|
@@ -52,13 +73,18 @@ var mumuki = mumuki || {};
|
|
52
73
|
// Private API
|
53
74
|
// ===========
|
54
75
|
|
55
|
-
|
56
|
-
|
76
|
+
/**
|
77
|
+
* Sends a solution object
|
78
|
+
*
|
79
|
+
* @param {Submission} submission the submission object
|
80
|
+
*/
|
81
|
+
_submitSolution: function (submission) {
|
82
|
+
if(lastSubmissionFinishedSuccessfully() && sameAsLastSolution(submission)){
|
57
83
|
return $.Deferred().resolve(lastSubmission.result);
|
58
84
|
} else {
|
59
|
-
return sendNewSolution(
|
85
|
+
return sendNewSolution(submission);
|
60
86
|
}
|
61
|
-
}
|
87
|
+
}
|
62
88
|
};
|
63
89
|
|
64
90
|
mumuki.bridge = {
|
@@ -1,3 +1,20 @@
|
|
1
|
+
/**
|
2
|
+
* A generic button component.
|
3
|
+
*
|
4
|
+
* It exposes three APIs: low level, common and high level.
|
5
|
+
*
|
6
|
+
* The low level allows you to control all aspects of the button, but it is legacy
|
7
|
+
* and should not be used in new code.
|
8
|
+
*
|
9
|
+
* The common API offers the start function, which can be used under both the low
|
10
|
+
* and high level APIs to configure the initial on-click button handler.
|
11
|
+
*
|
12
|
+
* The high level allows to implement a simple state-like button handling
|
13
|
+
* that goes as follow:
|
14
|
+
*
|
15
|
+
* 1. simple flow: {init} -start-> {enabled} -wait-> {waiting} -continue-> {enabled}
|
16
|
+
* 2. extended flow: {init} -start-> {enabled} -wait-> {waiting} -ready-> {ready-to-continue} -continue-> {enabled}
|
17
|
+
*/
|
1
18
|
mumuki.Button = class {
|
2
19
|
|
3
20
|
constructor($button, $container) {
|
@@ -6,10 +23,78 @@ mumuki.Button = class {
|
|
6
23
|
this.originalContent = $button.html();
|
7
24
|
}
|
8
25
|
|
26
|
+
// ==========
|
27
|
+
// Common API
|
28
|
+
// ==========
|
29
|
+
|
30
|
+
/**
|
31
|
+
* Initializes the button, configuring the action that will be called
|
32
|
+
* before wating, moving it into the {enabled} state.
|
33
|
+
*/
|
34
|
+
start(main) {
|
35
|
+
this.main = (e) => {
|
36
|
+
e.preventDefault();
|
37
|
+
main();
|
38
|
+
};
|
39
|
+
this.$button.on('click', this.main)
|
40
|
+
}
|
41
|
+
|
42
|
+
// ==============
|
43
|
+
// High level API
|
44
|
+
// ==============
|
45
|
+
|
46
|
+
/**
|
47
|
+
* Moves this button into the {waiting} state,
|
48
|
+
* disabling its usage and updating its legend
|
49
|
+
*/
|
50
|
+
wait() {
|
51
|
+
this.$button.off('click');
|
52
|
+
|
53
|
+
this.setWaiting();
|
54
|
+
}
|
55
|
+
|
56
|
+
/**
|
57
|
+
* Moves this button into {ready-to-continue} state,
|
58
|
+
* and sets the given callback to be called before continue.
|
59
|
+
*
|
60
|
+
* Going through this state is optional.
|
61
|
+
*/
|
62
|
+
ready(secondary) {
|
63
|
+
this.$button.off('click');
|
64
|
+
|
65
|
+
this.undisable();
|
66
|
+
this.setRetryText();
|
67
|
+
|
68
|
+
this.$button.on('click', (e) => {
|
69
|
+
e.preventDefault();
|
70
|
+
secondary();
|
71
|
+
});
|
72
|
+
}
|
73
|
+
|
74
|
+
/**
|
75
|
+
* Puts this button back in the {enabled} state,
|
76
|
+
* making it ready-to-use.
|
77
|
+
*/
|
78
|
+
continue() {
|
79
|
+
this.$button.off('click');
|
80
|
+
|
81
|
+
this.enable();
|
82
|
+
|
83
|
+
this.$button.on('click', this.main)
|
84
|
+
}
|
85
|
+
|
86
|
+
// =============
|
87
|
+
// Low level API
|
88
|
+
// =============
|
89
|
+
|
9
90
|
disable () {
|
10
91
|
this.$container.attr('disabled', 'disabled');
|
11
92
|
}
|
12
93
|
|
94
|
+
undisable() {
|
95
|
+
this.$container.removeAttr('disabled');
|
96
|
+
}
|
97
|
+
|
13
98
|
setWaiting () {
|
14
99
|
this.preventClick();
|
15
100
|
this.setWaitingText();
|
@@ -17,13 +102,17 @@ mumuki.Button = class {
|
|
17
102
|
|
18
103
|
enable () {
|
19
104
|
this.setOriginalContent();
|
20
|
-
this
|
105
|
+
this.undisable();
|
21
106
|
}
|
22
107
|
|
23
108
|
setWaitingText () {
|
24
109
|
this.$button.html('<i class="fa fa-refresh fa-spin"></i> ' + this.$button.attr('data-waiting'));
|
25
110
|
}
|
26
111
|
|
112
|
+
setRetryText() {
|
113
|
+
this.$button.html('<i class="fa fa-undo"></i>');
|
114
|
+
}
|
115
|
+
|
27
116
|
setOriginalContent () {
|
28
117
|
this.$button.html(this.originalContent);
|
29
118
|
}
|