/*global $*/ //TODO: move to a separate file(?) var config = { //TODO: create a dedicate widget for pretty date/clock datetimeformat: function(d) { if(Math.abs(new Date() - d) > (3*60*60*1000)) { return d.toLocaleString(); } return d.toLocaleTimeString(); } }; $.widget("ror.countclock", { options: { since: null, }, _create: function() { console.log("create"); this._update(); //TODO: aggiungi conto secondi/minuti passati }, _setOption: function(key, value) { this.options[key] = value; this._update(); }, _update: function() { if(this.options.since !== null) { this.element.text("Registrando da " + config.datetimeformat(this.options.since) ); } else { this.element.text(''); } } }); $.widget("ror.ongoingrec", { options: { rec: null, state: 0, /*0 = ongoing, 1 = encoding, 2 = ready to download*/ }, _create: function() { "use strict"; //convert a Rec into a console.log(this.element); var widget = this; var rec = this.options.rec; console.log("rec", rec); var view = this.element.data('rec', rec).addClass('ongoing-rec').append( $('').append( $('').attr('placeholder', 'Nome trasmissione') ) ).append( $('').countclock()).append( $('').append($('