(function (ns) { "use strict"; ns.OptionsForm = function (options) { qs.CustomForm.apply(this, arguments); this.formPart = options.formPart; this.get('addNewButton').on('click', _.bind(this.addNewOnClick, this)); this.notifyDatasetChanged(); this.initOptionButtons(); }; ns.OptionsForm.prototype = Object.create(qs.CustomForm.prototype); var fn = ns.OptionsForm.prototype; fn.notifyDatasetChanged = function () { var self = this; this.initOptionCells(this.getOptionCells()); this.getOptionItems().each(function() { var item = $(this), index = 1; self.initOptionCells(item.find('table [data-options-cell]')); item.find('[data-collection-item] .c_number').each(function () { $(this).text(index++); }); }); }; fn.initOptionButtons = function () { this.node.find('[data-action-delete]').on('click', _.bind(this.onDeleteClick, this)); this.node.find('[data-action-up]').on('click', _.bind(this.onMoveUpClick, this)); this.node.find('[data-action-down]').on('click', _.bind(this.onMoveDownClick, this)); }; fn.addNewOnClick = function (event) { var node = $(event.currentTarget); var itemName = node.data('action-add'); var options = { formPartAction: 'addNew', formPartItemName: itemName }; if (itemName == 'choice') { options.formPartOptionIndex = node.parents('[data-collection-item]:first').data('collection-item') } Qs_Form.updatePart(event.target.form, this.formPart, options); }; fn.onDeleteClick = function (event) { var element = $(event.currentTarget); var row = element.parents('[data-collection-item]:first'); var table = row.parents('[data-collection-type]:first'); var collectionType = table.data('collection-type'); if (element.hasClass('disabled')) { return false; } var itemName = collectionType == 'options' ? 'Option' : 'Choice'; if (!confirm('Do you really want to delete this ' + itemName + '?')) { return false; } var itemsCount = table.find('> tbody > [data-collection-item]').length; if (1 == itemsCount) { var addNewButton = table.find('> tbody > tr > td > [data-action-add]'); var elementContainer = $('