|
@@ -1,57 +1,30 @@
|
|
|
var $ = require('jquery');
|
|
|
|
|
|
-var initInlines = function() {
|
|
|
- $('.module').each(function() {
|
|
|
- var $module = $(this);
|
|
|
- var $items = function() { return $module.find('.stacked-inline-list-item'); };
|
|
|
- var $inlinesRelated = function() { return $module.find('.inline-related'); };
|
|
|
-
|
|
|
- $module.on('click', '.stacked-inline-list-item-link', function(e) {
|
|
|
- var $itemLink = $(this);
|
|
|
- var $item = $itemLink.closest('.stacked-inline-list-item');
|
|
|
- var moduleId = $itemLink.data('inline-related-id');
|
|
|
-
|
|
|
- $items().removeClass('selected');
|
|
|
- $item.addClass('selected');
|
|
|
- $inlinesRelated().removeClass('selected').filter('#' + moduleId).addClass('selected');
|
|
|
-
|
|
|
- e.preventDefault();
|
|
|
- });
|
|
|
-
|
|
|
- $module.on('click', '.stacked-inline-list-item-link-remove', function(e) {
|
|
|
- var $itemLink = $(this).closest('.stacked-inline-list-item-link');
|
|
|
- var $item = $itemLink.closest('.stacked-inline-list-item');
|
|
|
- var moduleId = $itemLink.data('inline-related-id');
|
|
|
-
|
|
|
- $item.remove();
|
|
|
- $inlinesRelated().filter('#' + moduleId).remove();
|
|
|
-
|
|
|
- e.preventDefault();
|
|
|
- });
|
|
|
-
|
|
|
- $module.find('.inline-related').each(function() {
|
|
|
- var $inline = $(this);
|
|
|
-
|
|
|
- $inline.find('.delete input').on('change', function(e) {
|
|
|
- var $input = $(this);
|
|
|
- var id = $inline.attr('id');
|
|
|
- var $link = $module.find('.stacked-inline-list-item-link[data-inline-related-id="' + id + '"]');
|
|
|
- var $item = $link.closest('.stacked-inline-list-item');
|
|
|
-
|
|
|
- if ($input.is(':checked')) {
|
|
|
- $item.addClass('delete');
|
|
|
- } else {
|
|
|
- $item.removeClass('delete');
|
|
|
- }
|
|
|
- });
|
|
|
- });
|
|
|
+var Inline = function($inline) {
|
|
|
+ this.$inline = $inline;
|
|
|
+};
|
|
|
|
|
|
- $module.find('.add-row a').on('click', function() {
|
|
|
- $module.find('select').trigger('select:init');
|
|
|
+Inline.prototype = {
|
|
|
+ initSelectsOnAddRow: function($inline) {
|
|
|
+ $inline.find('.add-row a').on('click', function() {
|
|
|
+ $inline.find('.inline-related:not(.empty-form)').last().find('select').trigger('select:init');
|
|
|
});
|
|
|
- });
|
|
|
+ },
|
|
|
+ run: function() {
|
|
|
+ var $inline = this.$inline;
|
|
|
+
|
|
|
+ try {
|
|
|
+ this.initSelectsOnAddRow($inline);
|
|
|
+ } catch (e) {
|
|
|
+ console.error(e, e.stack);
|
|
|
+ }
|
|
|
+
|
|
|
+ $inline.addClass('initialized');
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
$(document).ready(function() {
|
|
|
- initInlines();
|
|
|
+ $('.inline-group').each(function() {
|
|
|
+ new Inline($(this)).run();
|
|
|
+ });
|
|
|
});
|