diff options
| author | Xinhui | 2017-05-19 12:10:09 +0200 |
|---|---|---|
| committer | Xinhui | 2017-05-19 16:47:53 +0200 |
| commit | 4c1a2a33fde5b29f3b4c4024281ad80277a967d5 (patch) | |
| tree | 5a65ea426a2e8fdb4848faebc2e29ef36b484c79 /app/assets/javascripts | |
| parent | 6566451b49ba70b5bf47174de80c4bc6f49caa0d (diff) | |
| download | chouette-core-4c1a2a33fde5b29f3b4c4024281ad80277a967d5.tar.bz2 | |
Refactoring TimeTableCombination with calendar support
Diffstat (limited to 'app/assets/javascripts')
| -rw-r--r-- | app/assets/javascripts/select2.coffee | 58 |
1 files changed, 45 insertions, 13 deletions
diff --git a/app/assets/javascripts/select2.coffee b/app/assets/javascripts/select2.coffee index e8d9c313e..510e6fe9b 100644 --- a/app/assets/javascripts/select2.coffee +++ b/app/assets/javascripts/select2.coffee @@ -1,20 +1,52 @@ +bind_select2 = (el, cfg = {}) -> + target = $(el) + default_cfg = + theme: 'bootstrap' + language: 'fr' + placeholder: target.data('select2ed-placeholder') + allowClear: true + + target.select2 $.extend({}, default_cfg, cfg) + +bind_select2_ajax = (el, cfg = {}) -> + target = $(el) + cfg = + ajax: + data: (params) -> + q: + "#{target.data('term')}": params.term + url: target.data('url'), + dataType: 'json', + delay: 125, + processResults: (data, params) -> results: data + minimumInputLength: 3 + templateResult: eval(target.data('formater')) + templateSelection: (item) -> + item.text + + bind_select2(el, cfg) + +select2_time_table = (item) -> + return item.text if item.loading + wrap = $('<div>', "class":'select2-result clearfix') + wrap.html(["<h5>Time table : #{item.comment}</h5>"].join("\n")) + +select2_calendar = (item) -> + return item.text if item.loading + wrap = $('<div>', "class":'select2-result clearfix') + wrap.html(["<h5>Calendar : #{item.name}</h5>"].join("\n")) + + @select_2 = -> $("[data-select2ed='true']").each -> - target = $(this) - target.select2 - theme: 'bootstrap' - language: 'fr' - placeholder: target.data('select2ed-placeholder') - allowClear: true + bind_select2(this) + + $("[data-select2-ajax='true']").each -> + bind_select2_ajax(this) $('select.form-control.tags').each -> - target = $(this) - target.select2 - theme: 'bootstrap' - language: 'fr' - placeholder: target.data('select2ed-placeholder') - allowClear: true - tags: true + bind_select2(this, {tags: true}) + $(document).on 'turbolinks:load', select_2 |
