ongoing recs are shown at startup

This commit is contained in:
boyska 2013-12-10 02:35:53 +01:00
parent 14521b223e
commit 466f9a0b7d
2 changed files with 28 additions and 9 deletions

View file

@ -227,11 +227,8 @@ class RecServer:
return ret
def get_ongoing(self):
recs = self.db.get_ongoing()
ret = {}
for rec in recs:
ret[rec.id] = rec_sanitize(rec)
return ret
return {rec.id: rec_sanitize(rec)
for rec in self.db.get_ongoing()}
# @route('/help')
def help(self):

View file

@ -29,6 +29,9 @@ var API = {
return $.post('/api/generate', {
id: rec.id
});
},
get_ongoing: function() {
return $.getJSON('/api/get/ongoing');
}
};
@ -38,7 +41,6 @@ $.widget("ror.countclock", {
to: null
},
_create: function() {
console.log("create");
this._update();
//TODO: aggiungi conto secondi/minuti passati
},
@ -75,10 +77,8 @@ $.widget("ror.ongoingrec", {
_create: function() {
"use strict";
//convert a Rec into a <tr>
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(
$('<td/>').append(
$('<input/>').attr('placeholder', 'Nome trasmissione')
@ -221,8 +221,30 @@ function show_ongoing(ongoing_recs) {
$(function() {
"use strict";
/*global getKeys*/
//TODO: get-ongoing
$('.add-new-rec').click(add_new_rec);
API.get_ongoing()
.done(function(recs) {
$('.add-new-rec').click(add_new_rec);
console.log(recs);
if(getKeys(recs).length !== 0) {
$('#rec-inizia').remove();
$('#rec-normal').show();
show_ongoing(getKeys(recs).map(function(id) { console.log(id); return recs[id]; }));
}
});
});
//POLYFILL for Object.keys
function getKeys(obj) {
var keys = [];
var key;
for(key in obj) {
if(obj.hasOwnProperty(key)) {
keys.push(key);
}
}
return keys;
}
/* vim: set ts=2 sw=2 noet fdm=indent: */