diff --git a/.editorconfig b/.editorconfig index 6511313f..3a050c04 100644 --- a/.editorconfig +++ b/.editorconfig @@ -17,7 +17,7 @@ indent_size = 2 [*.js] indent_style = space -indent_size = 2 +indent_size = 4 [Makefile] indent_style = tab diff --git a/webroot/js/local.js b/webroot/js/local.js index ac977aa1..3de938e0 100644 --- a/webroot/js/local.js +++ b/webroot/js/local.js @@ -1,92 +1,115 @@ -$(function() { - - var bulkActionForm = $('.bulk-actions'); - if (bulkActionForm.length) { - bulkActionForm.submit(function (e) { - var action = $('.bulk-actions .bulk-action-submit select').val(); - if (!action) { - return e.preventDefault(); - } +var CrudView = { + bulkActionForm: function (selector) { + var bulkActionForm = $(selector); + if (bulkActionForm.length) { + bulkActionForm.submit(function (e) { + var action = $('.bulk-action-submit select', bulkActionForm).val(); + if (!action) { + return e.preventDefault(); + } - bulkActionForm.attr('action', action); - }); - } + bulkActionForm.attr('action', action); + }); + } + }, - $('[role=datetime-picker]').each(function() { + datePicker: function (selector) { + $(selector).each(function() { + var picker = $(this); + var date = null; - var picker = $(this); - var date = null; + if (picker.data('timestamp') && picker.data('timezone-offset')) { + var timezoneOffset = picker.data('timezone-offset'); + date = new Date(picker.data('timestamp') * 1000); - if (picker.data('timestamp') && picker.data('timezone-offset')) { - var timezoneOffset = picker.data('timezone-offset'); - date = new Date(picker.data('timestamp') * 1000); + picker.parents('form').on('submit', function () { + var timezoneDiff = timezoneOffset + date.getTimezoneOffset(); + var currentDate = picker.data('DateTimePicker').date(); + var convertedDate = currentDate.add(timezoneDiff, 'minutes'); + picker.data('DateTimePicker').date(convertedDate); + }); + } - picker.parents('form').on('submit', function () { - var timezoneDiff = timezoneOffset + date.getTimezoneOffset(); - var currentDate = picker.data('DateTimePicker').date(); - var convertedDate = currentDate.add(timezoneDiff, 'minutes'); - picker.data('DateTimePicker').date(convertedDate); + picker.datetimepicker({ + locale: $(this).data('locale'), + format: $(this).data('format'), + date: date ? date : picker.val() }); - } - - picker.datetimepicker({ - locale: $(this).data('locale'), - format: $(this).data('format'), - date: date ? date : picker.val() }); - }); + }, - $('select:not(.autocomplete, .no-selectize)').selectize({plugins: ['remove_button']}); + selectize: function (selector) { + $(selector).selectize({plugins: ['remove_button']}); + }, - $('input.autocomplete, select.autocomplete').each(function (i, e) { - e = $(e); - e.selectize({ - maxItems: e.data('max-items') || 1, - maxOptions: e.data('max-options') || 10, - hideSelected: e.data('hide-selected'), - closeAfterSelect: e.data('close-after-select'), - create: !e.data('exact-match'), - persist: false, - render: { - 'option_create': function(data, escape) { - return '