|
(function(m, v, c, api) { |
|
|
|
|
|
v.DocumentBinListView = Backbone.View.extend({ |
|
el: "#document-action-panel", |
|
|
|
template: Handlebars.compile($('#pre-sort-actions-template').html() || ''), |
|
listTemplate : Handlebars.compile($('#bin-sort-bin-list-template').html() || ''), |
|
filterCriteriaInputEl : {}, |
|
binListEl : {}, |
|
|
|
events : { |
|
'click .donor-corp-bin' : 'addDocumentToBin', |
|
'click .add-bin' : 'addBin', |
|
'click .view-bins-list' : 'viewBinsList', |
|
'click .view-bins-compact' : 'viewBinsCompact', |
|
'click .refresh-bins' : 'refresh', |
|
'click .edit-bin' : 'editBin', |
|
'click #sort-alpha' : 'sortBins', |
|
'click #sort-count' : 'sortBins', |
|
'keyup #filter-criteria-input' : 'applyFilter', |
|
'scroll' : 'setToolbarPosition' |
|
}, |
|
|
|
initialize : function () { |
|
_.bindAll(this); |
|
this.initializeKeyboardShortcuts(); |
|
this.initializeCollection(); |
|
this.render(); |
|
this.filterCriteriaInputEl = this.$el.find('#filter-criteria-input'); |
|
this.binListEl = this.$el.find('#donor-corp-bins'); |
|
$(window).on('resize', this.setToolbarPosition); |
|
Docr.on('docr:bin-changed', this.handleBinChanged); |
|
Docr.on('docr:bin-added', this.handleBinAdded); |
|
Docr.on('docr:bin-sort:bin-list-sort-changed', this.applySort); |
|
}, |
|
|
|
initializeCollection : function () { |
|
this.collection = c.FilterableCollection(this.collection); |
|
this.collection.bind('reset', this.renderList); |
|
this.collection.fetch(); |
|
}, |
|
|
|
initializeKeyboardShortcuts : function () { |
|
Mousetrap.bind('b+r', this.refresh); |
|
Mousetrap.bind('b+c', this.viewBinsCompact); |
|
Mousetrap.bind('b+l', this.viewBinsList); |
|
}, |
|
|
|
remove : function () { |
|
$(window).off('resize', this.setToolbarPosition); |
|
}, |
|
|
|
render: function (items) { |
|
this.$el.html(this.template({})); |
|
this.setToolbarPosition(); |
|
return this; |
|
}, |
|
|
|
renderList : function (items) { |
|
var list = this.listTemplate(this.collection.toJSON()); |
|
this.binListEl.html(list).fadeIn(this.animateBinDocumentCount); |
|
}, |
|
|
|
animateBinDocumentCount : function () { |
|
var targetEl = this.$el.find('.document-count'); |
|
var fromColor = '#000'; |
|
var toColor = targetEl.css('color'); |
|
targetEl |
|
.css({ 'color' : fromColor }) // set it to the highlight color |
|
.stop(true, true) // stop any existing/running animations |
|
.animate({ 'color' : fromColor }, 15000) // hold it at the highlight color for 15 seconds |
|
.animate({ 'color' : toColor }, 5000, function () { // fade out to original color |
|
$(this).removeAttr('style'); // remove the style attribute attached to the element |
|
}); |
|
}, |
|
|
|
handleBinAdded : function (bin) { |
|
this.refresh(); |
|
}, |
|
|
|
handleBinChanged : function (bin) { |
|
this.refresh(); |
|
}, |
|
|
|
addDocumentToBin : function (e) { |
|
Docr.trigger('bin-sort:bin:clicked', $(e.currentTarget)); |
|
}, |
|
|
|
editBin : function (e) { |
|
e.stopPropagation(); |
|
|
|
// var targetBin = _.find(this.collection.models, function (bin) { |
|
// return bin.get('Name') === $(e.currentTarget).parent().data('id'); |
|
// }); |
|
var targetBin = this.collection.get($(e.currentTarget).parent().data('id')); |
|
|
|
new v.BinEditView({ |
|
model : targetBin, |
|
action : $(e.currentTarget).data('bin-action'), |
|
method : $(e.currentTarget).data('save-method') |
|
}); |
|
}, |
|
|
|
addBin : function (e) { |
|
new v.BinEditView({ |
|
model : new m.Bin({ url : api.Resources.AddBin }), |
|
action : $(e.currentTarget).data('bin-action'), |
|
method : $(e.currentTarget).data('save-method') |
|
}); |
|
}, |
|
|
|
viewBinsList : function (e) { |
|
this.$el.find('.donor-corp-bins').removeClass('compact'); |
|
}, |
|
|
|
viewBinsCompact : function (e) { |
|
this.$el.find('.donor-corp-bins').addClass('compact'); |
|
}, |
|
|
|
setToolbarPosition : function (e) { |
|
var toolbar = this.$el.find('.bin-actions-toolbar'); |
|
var offset = this.$el.offset(); |
|
var height = this.$el.height(); |
|
toolbar.css({ |
|
'position' : 'fixed', |
|
'left' : offset.left, |
|
'top' : (offset.top + height) - toolbar.height(), |
|
'height' : toolbar.height(), |
|
'width' : (this.$el.width() - 17) + 'px' |
|
}); |
|
}, |
|
|
|
refresh : function () { |
|
this.binListEl.fadeOut('fast'); |
|
this.collection.fetch(); |
|
}, |
|
|
|
sortBins : function (e) { |
|
e.preventDefault(); |
|
var el = $(e.currentTarget); |
|
this.collection.sortBy(el.data('sort-key')); |
|
el.find('.sort-direction') |
|
.toggleClass('font-icon-caret-up') |
|
.toggleClass('font-icon-caret-down'); |
|
}, |
|
|
|
applySort : function () { |
|
// console.log(this.sort.toJSON()); |
|
}, |
|
|
|
applyFilter : function (e) { |
|
e.preventDefault(); |
|
|
|
var criteria = { |
|
value : this.filterCriteriaInputEl.val(), |
|
fields : ['Name', 'Description'] |
|
}; |
|
|
|
if (criteria.value.length > 0) { |
|
this.collection.filterLike(criteria); |
|
} else { |
|
this.collection.clearFilter(); |
|
} |
|
} |
|
}); |
|
|
|
}(Docr.Models, Docr.Views, Docr.Collections, Docr.Api)); |