/**
* Class: $.Queue
* Kolejka z dźwiękami do odegrania
*/
(function ($, doc, win) {
'use strict';
if ($.isFunction($.fn.Queue)) {
return;
}
var NUMBER_OF_DAYS_IN_QUEUE = 10;
$.widget('pr.Queue', {
_version: '1.0.0 Beta',
_create: function () {
var _this = this,
_now = new Date();
this.view = $('#list-queue').empty();
this.queue = new Queue();
this.queue.removeByDate(_now.setDate(_now.getDate() - NUMBER_OF_DAYS_IN_QUEUE));
this.render();
$(doc).on('click', '#list-queue .delete', function (e) {
var $this = $(this),
id = $this.data('id');
var record = _this.queue.searchById(id);
if (record) {
_this.queue.removeById(id);
_this.render();
_this._trigger('onRemove', _this, record);
}
return false;
});
var media = (this.queue.select() || {}).Data;
if (!$.isEmptyObject(media)) {
this._trigger('onPlay', this, {
media: $.extend({}, media, {
autostart: false
}), first: true
});
}
this._trigger('onCreate', this);
},
render: function () {
var _this = this,
content = '
Kolejka
';
this.queue.get().forEach(function (item, index) {
var className = [item.Data.type, item.Data.category.name.replace(/ /g, "").toNonPolishChar().toLowerCase()],
buildPlayer = '', image = '';
if (item.Active) {
className.push('active');
buildPlayer = 'pause_circle_outlinedata_usage
';
}
image = !item.Data.image ? '/content/_img/icon_' + (item.Data.type === 'muzyka' ? 'album' : 'mic') + '.png' : (_this.options.staticPath || '') + item.Data.image;
content += '';
});
this.view.html(content);
$('#list-queue').trigger('list-queue:render');
},
add: function (media) {
if (this.queue.searchById(media.uid)) {
this.queue.select(media.uid);
} else {
this.queue[media.autostart ? 'insert' : 'add'](media.uid, $.extend({}, media, { autostart: true }));
}
this.render();
this._trigger('onAdd');
if (media.autostart) {
this._trigger('onPlay', this, {
media: $.extend({}, media),
first: false
});
}
var self = this;
win.setTimeout(function () {
self._trigger('onAutoHide');
//console.log('auto hide');
}, 5000);
},
select: function (id) {
var media = (this.queue.select(id) || {}).Data;
if (!$.isEmptyObject(media)) {
this.render();
this._trigger('onPlay', this, {
media: $.extend({}, media),
first: false
});
}
},
removeSelect: function () {
this.queue.clearActive();
this.render();
},
next: function () {
var media = this.queue.next();
if (media != null) {
this.render();
this._trigger('onPlay', this, {
media: $.extend({}, media.Data),
first: false
});
}
},
hide: function () {
//options.content.empty();
},
destroy: function () {
$.Widget.prototype.destroy.call(this);
}
});
})(jQuery, document, window);