- if ($.isArray(this.options.teasers))
- {
- for (var i = 0; i < this.options.teasers.length; i++)
- {
- var f = this.options.teasers[i];
- if (f instanceof _luci2.cbi.AbstractValue)
- tf.push(f);
- else if (typeof(f) == 'string' && this.fields[f] instanceof _luci2.cbi.AbstractValue)
- tf.push(this.fields[f]);
- }
+ _ev_panel_collapse: function(ev)
+ {
+ var self = ev.data.self;
+
+ var this_panel = $(ev.target);
+ var this_toggle = this_panel.prevAll('[data-toggle="collapse"]:first');
+
+ var prev_toggle = $($(ev.delegateTarget).find('[data-toggle="collapse"]:eq(%d)'.format(self.active_panel)));
+ var prev_panel = $(prev_toggle.attr('data-target'));
+
+ prev_panel
+ .removeClass('in')
+ .addClass('collapse');
+
+ prev_toggle.find('.luci2-section-teaser')
+ .show()
+ .children('span:last')
+ .empty()
+ .append(self.teaser(prev_panel.attr('data-luci2-sid')));
+
+ this_toggle.find('.luci2-section-teaser')
+ .hide();
+
+ self.active_panel = parseInt(this_panel.attr('data-luci2-panel-index'));
+ self.validate();
+ },
+
+ _ev_panel_open: function(ev)
+ {
+ var self = ev.data.self;
+ var panel = $($(this).attr('data-target'));
+ var index = parseInt(panel.attr('data-luci2-panel-index'));
+
+ if (index == self.active_panel)
+ ev.stopPropagation();
+ },
+
+ _ev_sort: function(ev)
+ {
+ var self = ev.data.self;
+ var cur_idx = ev.data.index;
+ var new_idx = cur_idx + (ev.data.up ? -1 : 1);
+ var s = self.sections();
+
+ if (new_idx >= 0 && new_idx < s.length)
+ {
+ var tmp = s[cur_idx]['.index'];
+
+ s[cur_idx]['.index'] = s[new_idx]['.index'];
+ s[new_idx]['.index'] = tmp;
+
+ if (self.active_panel == cur_idx)
+ self.active_panel = new_idx;
+ else if (self.active_panel == new_idx)
+ self.active_panel = cur_idx;
+
+ self.map.uci.reorder = true;
+
+ self.map.save();
+ self.map.redraw();
+ }
+
+ ev.stopPropagation();
+ },
+
+ teaser: function(sid)
+ {
+ var tf = this.teaser_fields;
+
+ if (!tf)
+ {
+ tf = this.teaser_fields = [ ];
+
+ if ($.isArray(this.options.teasers))
+ {
+ for (var i = 0; i < this.options.teasers.length; i++)
+ {
+ var f = this.options.teasers[i];
+ if (f instanceof _luci2.cbi.AbstractValue)
+ tf.push(f);
+ else if (typeof(f) == 'string' && this.fields[f] instanceof _luci2.cbi.AbstractValue)
+ tf.push(this.fields[f]);
+ }