diff options
author | Asbjørn Sloth Tønnesen <asbjorn@asbjorn.biz> | 2012-07-10 19:51:16 +0000 |
---|---|---|
committer | Asbjørn Sloth Tønnesen <asbjorn@asbjorn.biz> | 2012-07-10 19:51:16 +0000 |
commit | cf7ed2625456a5e619f68408f8ebfe78f443a672 (patch) | |
tree | ae6787275ea9b9b8bd29e320c55bb3dbcbb62d30 /web/js | |
parent | 5e54ba7aa27b95d1e0568693915e735ab8058ff7 (diff) | |
download | labitrack-cf7ed2625456a5e619f68408f8ebfe78f443a672.tar.gz labitrack-cf7ed2625456a5e619f68408f8ebfe78f443a672.tar.xz labitrack-cf7ed2625456a5e619f68408f8ebfe78f443a672.zip |
upgrade to bootstrap 2
Signed-off-by: Asbjørn Sloth Tønnesen <asbjorn@asbjorn.biz>
Diffstat (limited to 'web/js')
l--------- | web/js/corelibs.d/60-bootstrap.js | 1 | ||||
-rw-r--r-- | web/js/labitrack.d/33-alerts.js | 12 | ||||
-rw-r--r-- | web/js/labitrack.d/38-labelform.js | 36 | ||||
-rw-r--r-- | web/js/labitrack.d/40-router.js | 6 | ||||
-rw-r--r-- | web/js/labitrack.d/41-create.js | 11 | ||||
-rw-r--r-- | web/js/labitrack.d/46-edit.js | 5 |
6 files changed, 59 insertions, 12 deletions
diff --git a/web/js/corelibs.d/60-bootstrap.js b/web/js/corelibs.d/60-bootstrap.js new file mode 120000 index 0000000..fb75b27 --- /dev/null +++ b/web/js/corelibs.d/60-bootstrap.js @@ -0,0 +1 @@ +../../pub/bootstrap/js/bootstrap.js
\ No newline at end of file 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) |