From cf7ed2625456a5e619f68408f8ebfe78f443a672 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= Date: Tue, 10 Jul 2012 19:51:16 +0000 Subject: upgrade to bootstrap 2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Asbjørn Sloth Tønnesen --- web/js/labitrack.d/33-alerts.js | 12 ++++++++++++ web/js/labitrack.d/38-labelform.js | 36 ++++++++++++++++++++++++++++-------- web/js/labitrack.d/40-router.js | 6 +++++- web/js/labitrack.d/41-create.js | 11 +++++++++-- web/js/labitrack.d/46-edit.js | 5 ++++- 5 files changed, 58 insertions(+), 12 deletions(-) create mode 100644 web/js/labitrack.d/33-alerts.js (limited to 'web/js/labitrack.d') diff --git a/web/js/labitrack.d/33-alerts.js b/web/js/labitrack.d/33-alerts.js new file mode 100644 index 0000000..d94d3c8 --- /dev/null +++ b/web/js/labitrack.d/33-alerts.js @@ -0,0 +1,12 @@ +$(function(){ + var alerts = $('#alerts'); + + λ.alert = function (tmpl, ctx) { + var alert = $(λ.template('alert_'+tmpl, ctx)); + alerts.append(alert); + setTimeout(function(){ + alert.alert('close'); + }, 15000); + + }; +}); diff --git a/web/js/labitrack.d/38-labelform.js b/web/js/labitrack.d/38-labelform.js index 04031cf..6136e6b 100644 --- a/web/js/labitrack.d/38-labelform.js +++ b/web/js/labitrack.d/38-labelform.js @@ -4,13 +4,15 @@ var model = opts.model; var canvas = $('#label')[0]; var label = new λ.label(); - label.set_data(model.toJSON()); label.set_canvas(canvas); var rendertime = $('#rendertime'); - function updateimg(data, ms) { - rendertime.text(ms); - } + (label.trigger_refresh = function(){ + label.set_data(model.toJSON()); + label.render(function(data, ms){ + rendertime.text(ms); + }); + })(); var f = $('#labelform'); function update_data(){ @@ -40,8 +42,7 @@ break; } model.set(foo); - label.set_data(model.toJSON()); - label.render(updateimg); + label.trigger_refresh(); }, 0); }; f.find(':input').each(function (i,e){ @@ -50,10 +51,29 @@ $(e).bind('change', update_data); update_data.apply(this); }); - label.render(updateimg); + + print = null; + + submit_btn = f.find('button[type="submit"]'); + + f.find('a#saveandprint').bind('click', function(){ + print = true; + submit_btn.click(); + }); + + f.find('a#justsave').bind('click', function(){ + print = false; + submit_btn.click(); + }); + + reset_btn = f.find('button[type="reset"]'); + + f.find('a#reset').bind('click', function(){ + reset_btn.click(); + }); f.bind('submit', function(){ - opts.submit(label, model); + opts.submit(label, model, print); return false; }); }; diff --git a/web/js/labitrack.d/40-router.js b/web/js/labitrack.d/40-router.js index 153e0b1..50d4c8f 100644 --- a/web/js/labitrack.d/40-router.js +++ b/web/js/labitrack.d/40-router.js @@ -2,11 +2,15 @@ var r = λ.r = new Backbone.Router(); function handle_click(event) { - console.log('click'); if (!Modernizr.history) return true; event.preventDefault(); var href = $(event.target).attr('href'); + var curpath = window.location.pathname; if (href !== undef && href[0] === '/') { + if (curpath === href) { + console.log('ignoring click event for', href); + return; + } Backbone.history.navigate(href, true); } } diff --git a/web/js/labitrack.d/41-create.js b/web/js/labitrack.d/41-create.js index ec689c4..4a1f37f 100644 --- a/web/js/labitrack.d/41-create.js +++ b/web/js/labitrack.d/41-create.js @@ -1,11 +1,18 @@ (function(){ - function on_submit(label, o) { + function on_submit(label, o, print) { o.save(undef, { success: function(){ label.set_data(o.toJSON()); - label.print(); + if (print) { + label.print(); + } + var id = o.get('id'); console.log('Saved with id: ' + o.get('id')); + λ.alert('newlabel', {id: o.get('id')}); + + o.set('id', undefined); + label.trigger_refresh(); } }); } diff --git a/web/js/labitrack.d/46-edit.js b/web/js/labitrack.d/46-edit.js index c7039b0..ce8ac1c 100644 --- a/web/js/labitrack.d/46-edit.js +++ b/web/js/labitrack.d/46-edit.js @@ -1,10 +1,13 @@ (function(){ - function on_submit(label, o) + function on_submit(label, o, print) { o.save(undef, {success: function() { label.set_data(o.toJSON()); Backbone.history.navigate('/view/'+o.id, true); }}); + if (print) { + label.print(); + } } function success(o) -- cgit v1.2.1