rec.js 973 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*global $*/
  2. var config = {
  3. polling_interval: 500,
  4. date_write: function(d) {
  5. return Math.floor(d.getTime() / 1000);
  6. },
  7. datetimeformat: function(d) {
  8. if(Math.abs(new Date() - d) > (3*60*60*1000)) {
  9. return d.toLocaleString();
  10. }
  11. return d.toLocaleTimeString();
  12. }
  13. };
  14. var RecAPI = {
  15. create: function() {
  16. return $.ajax('/api/create', {
  17. method: 'POST',
  18. dataType: 'json'
  19. });
  20. },
  21. stop: function(rec) {
  22. return $.post('/api/update/' + rec.id, {
  23. starttime: rec.starttime
  24. });
  25. },
  26. update: function(id, data) {
  27. return $.post('/api/update/' + id, data);
  28. },
  29. fullcreate: function(name, start, end) {
  30. return $.ajax(
  31. '/api/create', {
  32. method: 'POST',
  33. dataType: 'json',
  34. data: { name: name,
  35. starttime: config.date_write(start),
  36. endtime: config.date_write(end)
  37. }
  38. });
  39. },
  40. generate: function(rec) {
  41. return $.post('/api/generate', {
  42. id: rec.id
  43. });
  44. },
  45. get_ongoing: function() {
  46. return $.getJSON('/api/get/ongoing');
  47. }
  48. };