diff --git a/src/assets/css/app.css b/src/assets/css/app.css index 3b7274b..ab6596c 100644 --- a/src/assets/css/app.css +++ b/src/assets/css/app.css @@ -7,6 +7,11 @@ cursor: pointer; } +#flash { + position: fixed; + top: 50px; +} + .counter { padding: 10px; margin-top: -10px; diff --git a/src/assets/js/app.js b/src/assets/js/app.js index e6bf2ba..1b567f9 100644 --- a/src/assets/js/app.js +++ b/src/assets/js/app.js @@ -109,8 +109,8 @@ var App = (function() { this.loadUpdatePanel = function() { if (app.counters.length) { var counters = []; - var today = new Date(); - var currentDate = [today.getFullYear(), today.getMonth() + 1, today.getDate()].join('-'); + var today = new Date(); + var currentDate = [today.getFullYear(), today.getMonth() + 1, today.getDate()].join('-'); for (i in app.counters) { if (app.counters[i]) { @@ -118,10 +118,10 @@ var App = (function() { app.counters[i].started = false; var c = app.counters[i]; c.update = { - time: app.convertTime(c.time + 60, true), - date: currentDate - }; - counters.push(c); + time: app.convertTime(c.time + 60, true), + date: currentDate + }; + counters.push(c); } } } @@ -130,10 +130,54 @@ var App = (function() { app.json2html({ counters: counters }, 'update-panel'); + + $('#do-update').click(app.doUpdate); } } } + this.doUpdate = function() { + var getInputValue = function(field, issueId) { + return $('#time_' + field + '_' + issueId).val(); + } + + $('.issue-time').each(function() { + var $form = $(this); + var issueId = $(this).data('issue'); + var data = { + time_entry: { + issue_id: issueId, + spent_on: getInputValue('date', issueId), + hours: getInputValue('time', issueId), + comments: getInputValue('comment', issueId), + activity_id: getInputValue('activity', issueId) + } + } + + app.post( + 'time_entries.xml', + function() { + //$form.remove(); + }, + data, 'time_entry' + ); + }); + + if (!$('.issue-time').length) { + app.flash('Some forms are not correct.', 'danger'); + } else { + app.counters = []; + $('#content').empty(); + $('#counters > ul').remove(); + + app.flash('Redmine has been fully updated!', 'info'); + + window.setTimeout(function() { + app.loadProjects(); + }, 3000); + } + } + this.setTitle = function(name, clickCallback) { var $oTitle = $('#title'); var $title = $oTitle.clone(); @@ -268,6 +312,7 @@ var App = (function() { $('#content').show(); $('#loading').hide(); console.log('Request failed.'); + console.log([uri, type, data]); app.flash('Request failed.', 'danger'); }, always: function() {} diff --git a/src/index.html b/src/index.html index 934e98a..3695d53 100644 --- a/src/index.html +++ b/src/index.html @@ -19,9 +19,9 @@ -
-
+ +
Loading… @@ -85,7 +85,7 @@

Redmine updating

{{#each counters}} -
+
@@ -120,10 +120,16 @@
- + + + + + + + + +
@@ -131,6 +137,8 @@
{{/each}} + +