diff options
author | Frederic Guillot <fred@kanboard.net> | 2016-11-26 16:00:52 -0500 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2016-11-26 16:00:52 -0500 |
commit | 04ff67e26b880dde8bfb6462f312cf434457cd46 (patch) | |
tree | a3961289cbe8c60ca524490df1716229c555b379 /assets/js/components/submit-cancel.js | |
parent | e64faae69aec404b2641b8ae281afe20806e8292 (diff) |
Rewrite task move position component and remove Vuejs
Diffstat (limited to 'assets/js/components/submit-cancel.js')
-rw-r--r-- | assets/js/components/submit-cancel.js | 81 |
1 files changed, 49 insertions, 32 deletions
diff --git a/assets/js/components/submit-cancel.js b/assets/js/components/submit-cancel.js index 061b1146..ccb3c1d9 100644 --- a/assets/js/components/submit-cancel.js +++ b/assets/js/components/submit-cancel.js @@ -1,35 +1,52 @@ -Vue.component('submit-cancel', { - props: ['labelButton', 'labelOr', 'labelCancel', 'callback'], - template: '<div class="form-actions">' + - '<button type="button" class="btn btn-blue" @click="onSubmit" :disabled="isLoading">' + - '<span v-show="isLoading"><i class="fa fa-spinner fa-pulse"></i> </span>' + - '{{ labelButton }}' + - '</button> ' + - '{{ labelOr }} <a href="#" v-on:click.prevent="onCancel">{{ labelCancel }}</a>' + - '</div>' - , - data: function () { - return { - loading: false - }; - }, - computed: { - isLoading: function () { - return this.loading; - } - }, - methods: { - onSubmit: function () { - this.loading = true; - this.callback(); - }, - onCancel: function () { - _KB.get('Popover').close(); - } - }, - events: { - 'submitCancelled': function() { - this.loading = false; +KB.component('submit-cancel', function (containerElement, options) { + var isLoading = false; + + function onSubmit() { + isLoading = true; + KB.find('#modal-submit-button').replace(buildButton()); + KB.trigger('modal.submit'); + } + + function onCancel() { + KB.trigger('modal.cancel'); + _KB.get('Popover').close(); + } + + function onStop() { + isLoading = false; + KB.find('#modal-submit-button').replace(buildButton()); + } + + function buildButton() { + var button = KB.dom('button') + .click(onSubmit) + .attr('id', 'modal-submit-button') + .attr('type', 'submit') + .attr('class', 'btn btn-blue'); + + if (isLoading) { + button + .disable() + .add(KB.dom('i').attr('class', 'fa fa-spinner fa-pulse').build()) + .text(' ') + ; } + + return button + .text(options.submitLabel) + .build(); } + + this.render = function () { + KB.on('modal.stop', onStop); + + var element = KB.dom('div') + .attr('class', 'form-actions') + .add(buildButton()) + .text(' ' + options.orLabel + ' ') + .add(KB.dom('a').attr('href', '#').click(onCancel).text(options.cancelLabel).build()) + .build(); + + containerElement.appendChild(element); + }; }); |