var $this = this;
this.items = this.fluidbook.cache.get('cart', []);
this.boxes = this.fluidbook.cache.get('boxes', [{name: 'Box 1', refs: []}]);
- if (this.boxes===undefined || this.boxes===null || this.boxes.length === 0) {
+ if (typeof this.boxes === "string" || this.boxes === undefined || this.boxes === null || this.boxes.length === 0) {
this.boxes = [{name: 'Box 1', refs: []}];
}
this.boxIndex = Math.max(0, Math.min(this.boxes.length - 1, parseInt(this.fluidbook.cache.get('boxindex', '0'))));
});
$(document).on('change', 'select[name="box"]', function () {
- $this.boxIndex = parseInt($(this).find('option[value="' + $(this).val() + '"]').data('i'));
+ var val = $(this).val();
+ var opt = $(this).find('option[value="' + val + '"]');
+ var i = $(opt).data('index');
+ console.log(val, opt, i);
+ $this.boxIndex = parseInt(i);
+ $this.fluidbook.cache.set('boxindex', $this.boxIndex);
+ $this.setBox();
return true;
});
$this.updateBoxesSelector();
return false;
});
+
+ $(document).on('click', '[data-action="export"]', function () {
+ $this.exportBoxes();
+ });
+ },
+
+ exportBoxes:function(){
+
},
- addNewBox:function(){
- this.boxes.push({name: 'Box ' + (this.boxes.length + 2), refs: []});
+ addNewBox: function () {
+ this.boxes.push({name: 'Box ' + (this.boxes.length + 1), refs: []});
this.boxIndex = this.boxes.length - 1;
this.fluidbook.cache.set('boxes', this.boxes);
this.updateBoxesSelector();
this.setBox();
-
},
removeFromCart: function (ref) {
var $this = this;
$.each(this.boxes, function (k, b) {
var selected = (k === $this.boxIndex) ? ' selected ' : '';
- res += '<option data-index="' + k + '"' + selected + '>' + b.name + '</option>';
+ res += '<option data-index="' + k + '"' + selected + ' value="' + b.name + '">' + b.name + '</option>';
});
$("select[name='box']").html(res);
},