diff --git a/server/pages/new.html b/server/pages/new.html index 91123f4..74a6954 100644 --- a/server/pages/new.html +++ b/server/pages/new.html @@ -13,6 +13,7 @@ + diff --git a/server/pages/old.html b/server/pages/old.html index ada95d2..8fa9b06 100644 --- a/server/pages/old.html +++ b/server/pages/old.html @@ -12,6 +12,9 @@ + + + @@ -20,7 +23,7 @@
-
+ diff --git a/server/server.py b/server/server.py index 953f43d..218272e 100644 --- a/server/server.py +++ b/server/server.py @@ -81,15 +81,16 @@ class RecAPI(Bottle): def create(self): req = dict(request.POST.allitems()) ret = {} - logger.debug("Server:: Create request %s " % req) + logger.debug("Create request %s " % req) - starttime = datetime.now() - name = "" - endtime = datetime.now() + now = datetime.now() + start = date_read(req['starttime']) if 'starttime' in req else now + name = req['name'] if 'name' in req else "" + end = date_read(req['endtime']) if 'endtime' in req else now rec = Rec(name=name, - starttime=starttime, - endtime=endtime) + starttime=start, + endtime=end) ret = self.db.add(rec) return self.rec_msg("Nuova registrazione creata! (id:%d)" % ret.id, @@ -151,9 +152,9 @@ class RecAPI(Bottle): (rec.endtime - rec.starttime).total_seconds() } rec.filename = get_config()['AUDIO_OUTPUT_FORMAT'] % { - 'time': rec.starttime.strftime('%y%m%d_%H%M'), - 'name': filter(lambda c: c.isalpha(), rec.name) - } + 'time': rec.starttime.strftime('%y%m%d_%H%M'), + 'name': filter(lambda c: c.isalpha(), rec.name) + } self.db.update(rec.id, rec.serialize()) job_id = get_process_queue().submit( create_mp3, @@ -262,8 +263,8 @@ class RecServer: self._app.route('/new.html', callback=partial(static_file, 'new.html', root='pages/')) - self._app.route('/tempo.html', - callback=partial(static_file, 'tempo.html', + self._app.route('/old.html', + callback=partial(static_file, 'old.html', root='pages/')) diff --git a/server/static/js/jquery.form.min.js b/server/static/js/jquery.form.min.js new file mode 100644 index 0000000..ee9b9ef --- /dev/null +++ b/server/static/js/jquery.form.min.js @@ -0,0 +1,7 @@ +/* +* jQuery Form Plugin; v20140218 +* http://jquery.malsup.com/form/ +* Copyright (c) 2014 M. Alsup; Dual licensed: MIT/GPL +* https://github.com/malsup/form#copyright-and-license +*/ +;!function(a){"use strict";"function"==typeof define&&define.amd?define(["jquery"],a):a("undefined"!=typeof jQuery?jQuery:window.Zepto)}(function(a){"use strict";function b(b){var c=b.data;b.isDefaultPrevented()||(b.preventDefault(),a(b.target).ajaxSubmit(c))}function c(b){var c=b.target,d=a(c);if(!d.is("[type=submit],[type=image]")){var e=d.closest("[type=submit]");if(0===e.length)return;c=e[0]}var f=this;if(f.clk=c,"image"==c.type)if(void 0!==b.offsetX)f.clk_x=b.offsetX,f.clk_y=b.offsetY;else if("function"==typeof a.fn.offset){var g=d.offset();f.clk_x=b.pageX-g.left,f.clk_y=b.pageY-g.top}else f.clk_x=b.pageX-c.offsetLeft,f.clk_y=b.pageY-c.offsetTop;setTimeout(function(){f.clk=f.clk_x=f.clk_y=null},100)}function d(){if(a.fn.ajaxSubmit.debug){var b="[jquery.form] "+Array.prototype.join.call(arguments,"");window.console&&window.console.log?window.console.log(b):window.opera&&window.opera.postError&&window.opera.postError(b)}}var e={};e.fileapi=void 0!==a("").get(0).files,e.formdata=void 0!==window.FormData;var f=!!a.fn.prop;a.fn.attr2=function(){if(!f)return this.attr.apply(this,arguments);var a=this.prop.apply(this,arguments);return a&&a.jquery||"string"==typeof a?a:this.attr.apply(this,arguments)},a.fn.ajaxSubmit=function(b){function c(c){var d,e,f=a.param(c,b.traditional).split("&"),g=f.length,h=[];for(d=0;g>d;d++)f[d]=f[d].replace(/\+/g," "),e=f[d].split("="),h.push([decodeURIComponent(e[0]),decodeURIComponent(e[1])]);return h}function g(d){for(var e=new FormData,f=0;f').val(m.extraData[n].value).appendTo(x)[0]):k.push(a('').val(m.extraData[n]).appendTo(x)[0]));m.iframeTarget||q.appendTo("body"),r.attachEvent?r.attachEvent("onload",h):r.addEventListener("load",h,!1),setTimeout(b,15);try{x.submit()}catch(p){var s=document.createElement("form").submit;s.apply(x)}}finally{x.setAttribute("action",f),x.setAttribute("enctype",j),c?x.setAttribute("target",c):l.removeAttr("target"),a(k).remove()}}function h(b){if(!s.aborted&&!F){if(E=e(r),E||(d("cannot access response document"),b=A),b===z&&s)return s.abort("timeout"),y.reject(s,"timeout"),void 0;if(b==A&&s)return s.abort("server abort"),y.reject(s,"error","server abort"),void 0;if(E&&E.location.href!=m.iframeSrc||v){r.detachEvent?r.detachEvent("onload",h):r.removeEventListener("load",h,!1);var c,f="success";try{if(v)throw"timeout";var g="xml"==m.dataType||E.XMLDocument||a.isXMLDoc(E);if(d("isXml="+g),!g&&window.opera&&(null===E.body||!E.body.innerHTML)&&--G)return d("requeing onLoad callback, DOM not available"),setTimeout(h,250),void 0;var i=E.body?E.body:E.documentElement;s.responseText=i?i.innerHTML:null,s.responseXML=E.XMLDocument?E.XMLDocument:E,g&&(m.dataType="xml"),s.getResponseHeader=function(a){var b={"content-type":m.dataType};return b[a.toLowerCase()]},i&&(s.status=Number(i.getAttribute("status"))||s.status,s.statusText=i.getAttribute("statusText")||s.statusText);var j=(m.dataType||"").toLowerCase(),k=/(json|script|text)/.test(j);if(k||m.textarea){var l=E.getElementsByTagName("textarea")[0];if(l)s.responseText=l.value,s.status=Number(l.getAttribute("status"))||s.status,s.statusText=l.getAttribute("statusText")||s.statusText;else if(k){var o=E.getElementsByTagName("pre")[0],p=E.getElementsByTagName("body")[0];o?s.responseText=o.textContent?o.textContent:o.innerText:p&&(s.responseText=p.textContent?p.textContent:p.innerText)}}else"xml"==j&&!s.responseXML&&s.responseText&&(s.responseXML=H(s.responseText));try{D=J(s,j,m)}catch(t){f="parsererror",s.error=c=t||f}}catch(t){d("error caught: ",t),f="error",s.error=c=t||f}s.aborted&&(d("upload aborted"),f=null),s.status&&(f=s.status>=200&&s.status<300||304===s.status?"success":"error"),"success"===f?(m.success&&m.success.call(m.context,D,"success",s),y.resolve(s.responseText,"success",s),n&&a.event.trigger("ajaxSuccess",[s,m])):f&&(void 0===c&&(c=s.statusText),m.error&&m.error.call(m.context,s,f,c),y.reject(s,"error",c),n&&a.event.trigger("ajaxError",[s,m,c])),n&&a.event.trigger("ajaxComplete",[s,m]),n&&!--a.active&&a.event.trigger("ajaxStop"),m.complete&&m.complete.call(m.context,s,f),F=!0,m.timeout&&clearTimeout(w),setTimeout(function(){m.iframeTarget?q.attr("src",m.iframeSrc):q.remove(),s.responseXML=null},100)}}}var j,k,m,n,o,q,r,s,t,u,v,w,x=l[0],y=a.Deferred();if(y.abort=function(a){s.abort(a)},c)for(k=0;k'),q.css({position:"absolute",top:"-1000px",left:"-1000px"})),r=q[0],s={aborted:0,responseText:null,responseXML:null,status:0,statusText:"n/a",getAllResponseHeaders:function(){},getResponseHeader:function(){},setRequestHeader:function(){},abort:function(b){var c="timeout"===b?"timeout":"aborted";d("aborting upload... "+c),this.aborted=1;try{r.contentWindow.document.execCommand&&r.contentWindow.document.execCommand("Stop")}catch(e){}q.attr("src",m.iframeSrc),s.error=c,m.error&&m.error.call(m.context,s,c,b),n&&a.event.trigger("ajaxError",[s,m,c]),m.complete&&m.complete.call(m.context,s,c)}},n=m.global,n&&0===a.active++&&a.event.trigger("ajaxStart"),n&&a.event.trigger("ajaxSend",[s,m]),m.beforeSend&&m.beforeSend.call(m.context,s,m)===!1)return m.global&&a.active--,y.reject(),y;if(s.aborted)return y.reject(),y;t=x.clk,t&&(u=t.name,u&&!t.disabled&&(m.extraData=m.extraData||{},m.extraData[u]=t.value,"image"==t.type&&(m.extraData[u+".x"]=x.clk_x,m.extraData[u+".y"]=x.clk_y)));var z=1,A=2,B=a("meta[name=csrf-token]").attr("content"),C=a("meta[name=csrf-param]").attr("content");C&&B&&(m.extraData=m.extraData||{},m.extraData[C]=B),m.forceSync?g():setTimeout(g,10);var D,E,F,G=50,H=a.parseXML||function(a,b){return window.ActiveXObject?(b=new ActiveXObject("Microsoft.XMLDOM"),b.async="false",b.loadXML(a)):b=(new DOMParser).parseFromString(a,"text/xml"),b&&b.documentElement&&"parsererror"!=b.documentElement.nodeName?b:null},I=a.parseJSON||function(a){return window.eval("("+a+")")},J=function(b,c,d){var e=b.getResponseHeader("content-type")||"",f="xml"===c||!c&&e.indexOf("xml")>=0,g=f?b.responseXML:b.responseText;return f&&"parsererror"===g.documentElement.nodeName&&a.error&&a.error("parsererror"),d&&d.dataFilter&&(g=d.dataFilter(g,c)),"string"==typeof g&&("json"===c||!c&&e.indexOf("json")>=0?g=I(g):("script"===c||!c&&e.indexOf("javascript")>=0)&&a.globalEval(g)),g};return y}if(!this.length)return d("ajaxSubmit: skipping submit process - no element selected"),this;var i,j,k,l=this;"function"==typeof b?b={success:b}:void 0===b&&(b={}),i=b.type||this.attr2("method"),j=b.url||this.attr2("action"),k="string"==typeof j?a.trim(j):"",k=k||window.location.href||"",k&&(k=(k.match(/^([^#]+)/)||[])[1]),b=a.extend(!0,{url:k,success:a.ajaxSettings.success,type:i||a.ajaxSettings.type,iframeSrc:/^https/i.test(window.location.href||"")?"javascript:false":"about:blank"},b);var m={};if(this.trigger("form-pre-serialize",[this,b,m]),m.veto)return d("ajaxSubmit: submit vetoed via form-pre-serialize trigger"),this;if(b.beforeSerialize&&b.beforeSerialize(this,b)===!1)return d("ajaxSubmit: submit aborted via beforeSerialize callback"),this;var n=b.traditional;void 0===n&&(n=a.ajaxSettings.traditional);var o,p=[],q=this.formToArray(b.semantic,p);if(b.data&&(b.extraData=b.data,o=a.param(b.data,n)),b.beforeSubmit&&b.beforeSubmit(q,this,b)===!1)return d("ajaxSubmit: submit aborted via beforeSubmit callback"),this;if(this.trigger("form-submit-validate",[q,this,b,m]),m.veto)return d("ajaxSubmit: submit vetoed via form-submit-validate trigger"),this;var r=a.param(q,n);o&&(r=r?r+"&"+o:o),"GET"==b.type.toUpperCase()?(b.url+=(b.url.indexOf("?")>=0?"&":"?")+r,b.data=null):b.data=r;var s=[];if(b.resetForm&&s.push(function(){l.resetForm()}),b.clearForm&&s.push(function(){l.clearForm(b.includeHidden)}),!b.dataType&&b.target){var t=b.success||function(){};s.push(function(c){var d=b.replaceTarget?"replaceWith":"html";a(b.target)[d](c).each(t,arguments)})}else b.success&&s.push(b.success);if(b.success=function(a,c,d){for(var e=b.context||this,f=0,g=s.length;g>f;f++)s[f].apply(e,[a,c,d||l,l])},b.error){var u=b.error;b.error=function(a,c,d){var e=b.context||this;u.apply(e,[a,c,d,l])}}if(b.complete){var v=b.complete;b.complete=function(a,c){var d=b.context||this;v.apply(d,[a,c,l])}}var w=a("input[type=file]:enabled",this).filter(function(){return""!==a(this).val()}),x=w.length>0,y="multipart/form-data",z=l.attr("enctype")==y||l.attr("encoding")==y,A=e.fileapi&&e.formdata;d("fileAPI :"+A);var B,C=(x||z)&&!A;b.iframe!==!1&&(b.iframe||C)?b.closeKeepAlive?a.get(b.closeKeepAlive,function(){B=h(q)}):B=h(q):B=(x||z)&&A?g(q):a.ajax(b),l.removeData("jqxhr").data("jqxhr",B);for(var D=0;Dj;j++)if(n=i[j],l=n.name,l&&!n.disabled)if(b&&g.clk&&"image"==n.type)g.clk==n&&(d.push({name:l,value:a(n).val(),type:n.type}),d.push({name:l+".x",value:g.clk_x},{name:l+".y",value:g.clk_y}));else if(m=a.fieldValue(n,!0),m&&m.constructor==Array)for(c&&c.push(n),k=0,p=m.length;p>k;k++)d.push({name:l,value:m[k]});else if(e.fileapi&&"file"==n.type){c&&c.push(n);var q=n.files;if(q.length)for(k=0;kf;f++)c.push({name:d,value:e[f]});else null!==e&&"undefined"!=typeof e&&c.push({name:this.name,value:e})}}),a.param(c)},a.fn.fieldValue=function(b){for(var c=[],d=0,e=this.length;e>d;d++){var f=this[d],g=a.fieldValue(f,b);null===g||"undefined"==typeof g||g.constructor==Array&&!g.length||(g.constructor==Array?a.merge(c,g):c.push(g))}return c},a.fieldValue=function(b,c){var d=b.name,e=b.type,f=b.tagName.toLowerCase();if(void 0===c&&(c=!0),c&&(!d||b.disabled||"reset"==e||"button"==e||("checkbox"==e||"radio"==e)&&!b.checked||("submit"==e||"image"==e)&&b.form&&b.form.clk!=b||"select"==f&&-1==b.selectedIndex))return null;if("select"==f){var g=b.selectedIndex;if(0>g)return null;for(var h=[],i=b.options,j="select-one"==e,k=j?g+1:i.length,l=j?g:0;k>l;l++){var m=i[l];if(m.selected){var n=m.value;if(n||(n=m.attributes&&m.attributes.value&&!m.attributes.value.specified?m.text:m.value),j)return n;h.push(n)}}return h}return a(b).val()},a.fn.clearForm=function(b){return this.each(function(){a("input,select,textarea",this).clearFields(b)})},a.fn.clearFields=a.fn.clearInputs=function(b){var c=/^(?:color|date|datetime|email|month|number|password|range|search|tel|text|time|url|week)$/i;return this.each(function(){var d=this.type,e=this.tagName.toLowerCase();c.test(d)||"textarea"==e?this.value="":"checkbox"==d||"radio"==d?this.checked=!1:"select"==e?this.selectedIndex=-1:"file"==d?/MSIE/.test(navigator.userAgent)?a(this).replaceWith(a(this).clone(!0)):a(this).val(""):b&&(b===!0&&/hidden/.test(d)||"string"==typeof b&&a(this).is(b))&&(this.value="")})},a.fn.resetForm=function(){return this.each(function(){("function"==typeof this.reset||"object"==typeof this.reset&&!this.reset.nodeType)&&this.reset()})},a.fn.enable=function(a){return void 0===a&&(a=!0),this.each(function(){this.disabled=!a})},a.fn.selected=function(b){return void 0===b&&(b=!0),this.each(function(){var c=this.type;if("checkbox"==c||"radio"==c)this.checked=b;else if("option"==this.tagName.toLowerCase()){var d=a(this).parent("select");b&&d[0]&&"select-one"==d[0].type&&d.find("option").selected(!1),this.selected=b}})},a.fn.ajaxSubmit.debug=!1}); \ No newline at end of file diff --git a/server/static/js/new.js b/server/static/js/new.js index 9b68689..5c38634 100644 --- a/server/static/js/new.js +++ b/server/static/js/new.js @@ -1,40 +1,6 @@ -/*global $*/ +/*global $, config, RecAPI*/ + //TODO: move to a separate file(?) -var config = { - polling_interval: 500, - datetimeformat: function(d) { - if(Math.abs(new Date() - d) > (3*60*60*1000)) { - return d.toLocaleString(); - } - return d.toLocaleTimeString(); - } -}; - -var API = { - create: function() { - return $.ajax('/api/create', { - method: 'POST', - dataType: 'json' - }); - }, - stop: function(rec) { - return $.post('/api/update/' + rec.id, { - starttime: rec.starttime - }); - }, - update: function(id, data) { - return $.post('/api/update/' + id, data); - }, - generate: function(rec) { - return $.post('/api/generate', { - id: rec.id - }); - }, - get_ongoing: function() { - return $.getJSON('/api/get/ongoing'); - } -}; - $.widget("ror.countclock", { options: { errormsg: null, @@ -88,7 +54,6 @@ $.widget("ror.ongoingrec", { $('').append($('') .addClass('pure-button pure-button-large')) ); - this._update(); view.on("change", "input", function(evt) { @@ -148,7 +113,7 @@ $.widget("ror.ongoingrec", { } this.element.find('a').removeClass( - 'pure-button-disabled rec-encoding rec-download rec-failed rec-stop') + 'pure-button-disabled rec-encoding rec-download rec-failed rec-stop'); switch(this.options.state) { case 0: this.element.find('a').addClass("rec-stop").html( @@ -189,21 +154,23 @@ function poll_job(job_id, callback) { function add_new_rec() { //progress() - return API.create() + return RecAPI.create() .done(function(res) { + /*global show_ongoing*/ //passa alla seconda schermata $('#rec-inizia').remove(); $('#rec-normal').show(); show_ongoing([res.rec]); }) .fail(function() { + /*global alert*/ alert("C'e' stato qualche problema nella comunicazione col server"); }); } function gen_rec(rec, widget) { "use strict"; - var gen_xhr = API.generate(rec); + var gen_xhr = RecAPI.generate(rec); gen_xhr.done(function(res_gen) { widget.option("state", 1); poll_job(res_gen.job_id, function(data) { @@ -227,7 +194,7 @@ function gen_rec(rec, widget) { function stop_rec(rec, widget) { "use strict"; - var stop_xhr = API.stop(rec); + var stop_xhr = RecAPI.stop(rec); stop_xhr.done(function(res_update) { widget.option("rec", res_update.rec); return gen_rec(rec, widget); @@ -237,7 +204,7 @@ function stop_rec(rec, widget) { widget.option("errormsg", error); widget.option("state", 9); }); - return stop_xhr; //API.stop + return stop_xhr; //RecAPI.stop } function show_ongoing(ongoing_recs) { @@ -250,7 +217,7 @@ function show_ongoing(ongoing_recs) { gen_rec(data.rec, data.widget); }).on("ongoingrecchange", function(evt, data) { //TODO: aggiorna nome sul server - API.update(data.rec.id, data.rec); + RecAPI.update(data.rec.id, data.rec); }); $('#ongoing-recs-table tbody').prepend(viewrec); return viewrec; @@ -261,7 +228,7 @@ $(function() { "use strict"; /*global getKeys*/ //TODO: get-ongoing - API.get_ongoing() + RecAPI.get_ongoing() .done(function(recs) { $('.add-new-rec').click(add_new_rec); console.log(recs); diff --git a/server/static/js/old.js b/server/static/js/old.js index 5021b2f..f8114a1 100644 --- a/server/static/js/old.js +++ b/server/static/js/old.js @@ -1,59 +1,101 @@ -/* BEGIN Validation */ -function form_check() { - "use strict"; - var errs = []; - function err(msg, element) { - errs.unshift({ msg: msg, el: element}); - } - if($('#name').val() == '') { - errs.unshift("Nome mancante", $('#name')); - } - if(parseInt($('#to-hour').val(), 10) - parseInt($('#from-hour').val(), 10) > 5) { - errs.unshift("Too long"); - } - if(parseInt($('#to-hour').val(), 10) - parseInt($('#from-hour').val(), 10) < 0) { - //TODO: better date handling - errs.unshift("Inverted from/to ?"); - } - return errs; -} +/*global $*/ -function update_form_check(errors) { - "use strict"; - /* This function reads results and changes "things" consequently */ - if(errors.length > 0) { - console.log(errors); - $('#download').addClass("pure-button-disabled"); - } else { /* everything fine */ - $('#download').removeClass("pure-button-disabled"); - } -} -/* END validation */ +var form = { + MAX_MINS: 5*60, // 5 hours + get_values: function() { + var name = $('#name').val(); + var start = $('#from-date').datepicker('getDate'); + if(start !== null) { + start.setHours($('#from-hour').val()); + start.setMinutes($('#from-min').val()); + } + var end = $('#to-date').datepicker('getDate'); + if(end !== null) { + end.setHours($('#to-hour').val()); + end.setMinutes($('#to-min').val()); + } + return { name: name, start: start, end: end }; + }, + check: function() { + "use strict"; + var errs = []; + function err(msg, element) { + errs.unshift({ msg: msg, el: element}); + } + var v = form.get_values(); + if(v.val === '') { + err("Nome mancante", $('#name')); + } + if(v.start === null) { + err("Start unspecified"); + } + if(v.end === null) { + err("End unspecified"); + } + if(v.end <= v.start) { + err("Inverted from/to ?"); + } + if( (v.end - v.start) / (1000*60) > form.MAX_MINS) { + err("Too long"); + } + return errs; + } +}; $(function() { - "use strict"; - $( "#from-date" ).datepicker({ - defaultDate: "+0d", - changeMonth: true, - numberOfMonths: 1, - onClose: function( selectedDate ) { - if($('#to-date').val() == '') { - $('#to-date').datepicker("setDate", selectedDate); - } - $("#to-date").datepicker("option", "minDate", selectedDate); - } - }); - $( "#to-date" ).datepicker({ - defaultDate: "+0d", - changeMonth: true, - numberOfMonths: 1, - onClose: function( selectedDate ) { - $("#from-date").datepicker("option", "maxDate", selectedDate); - } - }); - $('#to-date, #from-date').datepicker($.datepicker.regional['it']); + "use strict"; + $( "#from-date" ).datepicker({ + defaultDate: "+0d", + changeMonth: true, + numberOfMonths: 1, + maxDate: new Date(), + onClose: function( selectedDate ) { + if($('#to-date').val() === '') { + $('#to-date').datepicker("setDate", selectedDate); + } + $("#to-date").datepicker("option", "minDate", selectedDate); + } + }); + $( "#to-date" ).datepicker({ + defaultDate: "+0d", + changeMonth: true, + numberOfMonths: 1, + maxDate: new Date(), + onClose: function( selectedDate ) { + $("#from-date").datepicker("option", "maxDate", selectedDate); + } + }); + $('#to-date, #from-date').datepicker($.datepicker.regional.it); - $('form input').change(function() { - update_form_check(form_check()); - }) + $('#form').ajaxForm({ + beforeSubmit: function() { + console.log("check", form.check()); + if(form.check().length > 0) { + console.log("Form not valid, aborting"); + return false; + } + return true; + }, + success: function() { + /*global RecAPI*/ + var v = form.get_values(); + RecAPI.fullcreate(v.name, v.start, v.end) + .done(function(res) { + console.log("ok, created"); + RecAPI.generate(res.rec) + .done(function(res) { + console.log("ok, generated", res); + }) + .fail(function() { + console.error("Oh shit, generate failed", res.rec); + }); + }) + .fail(function() { + console.error("Oh shit, fullcreate failed"); + }); + + return false; + } + }); }); +/* vim: set ts=2 sw=2 noet fdm=indent: */ diff --git a/server/static/js/rec.js b/server/static/js/rec.js new file mode 100644 index 0000000..ab7a8be --- /dev/null +++ b/server/static/js/rec.js @@ -0,0 +1,49 @@ +/*global $*/ +var config = { + polling_interval: 500, + date_write: function(d) { + return Math.floor(d.getTime() / 1000); + }, + datetimeformat: function(d) { + if(Math.abs(new Date() - d) > (3*60*60*1000)) { + return d.toLocaleString(); + } + return d.toLocaleTimeString(); + } +}; + +var RecAPI = { + create: function() { + return $.ajax('/api/create', { + method: 'POST', + dataType: 'json' + }); + }, + stop: function(rec) { + return $.post('/api/update/' + rec.id, { + starttime: rec.starttime + }); + }, + update: function(id, data) { + return $.post('/api/update/' + id, data); + }, + fullcreate: function(name, start, end) { + return $.ajax( + '/api/create', { + method: 'POST', + dataType: 'json', + data: { name: name, + starttime: config.date_write(start), + endtime: config.date_write(end) + } + }); + }, + generate: function(rec) { + return $.post('/api/generate', { + id: rec.id + }); + }, + get_ongoing: function() { + return $.getJSON('/api/get/ongoing'); + } +};