From fabebe84d31655b96061f4339bdc51643a433f4d Mon Sep 17 00:00:00 2001 From: Anon Ray Date: Thu, 25 Sep 2014 15:47:59 +0530 Subject: [PATCH] Fix: Duplicate swts show when swting next swts - Hack to fix bug of duplicate swts showing up. - Minor UI change in checkbox of show annotated areas --- swtr/static/css/swtmaker.css | 7 +++++++ swtr/static/js/img_swtr.js | 4 ++++ swtr/static/js/lib/custom-fields-plugin.js | 8 ++++++++ swtr/static/js/main.js | 18 +++++++++--------- swtr/templates/index.html | 6 +++--- 5 files changed, 31 insertions(+), 12 deletions(-) diff --git a/swtr/static/css/swtmaker.css b/swtr/static/css/swtmaker.css index 7a8c955..a8e4db6 100644 --- a/swtr/static/css/swtmaker.css +++ b/swtr/static/css/swtmaker.css @@ -25,6 +25,12 @@ body { margin: 30px auto 0 auto; } +#img-anno-controls { + display: none; + margin-bottom: 5px; + padding-bottom: 3px; +} + #annotatable-img { margin: 0 auto; max-width: 1125px; @@ -88,6 +94,7 @@ body { background-size: cover; display: block; height: 400px; + width: 400px; margin: 0 auto; } diff --git a/swtr/static/js/img_swtr.js b/swtr/static/js/img_swtr.js index 5c9ded6..1a73bdf 100644 --- a/swtr/static/js/img_swtr.js +++ b/swtr/static/js/img_swtr.js @@ -324,6 +324,7 @@ var self = event.data; //console.log('image loaded', self); swtr.appView.$overlay.hide(); + self.showImgAnnoControls(); // reset the collection swtr.sweets.reset(); anno.makeAnnotatable(swtr.imgAnnoView.img); @@ -337,6 +338,9 @@ swtr.appView.$overlay.hide(); self.helpview.step(8); }, + showImgAnnoControls: function() { + $('#img-anno-controls').show(); + }, initImageAnno: function() { // img is a jquery object which annotorious doesn't accept; instead it // takes the native object returned by a browser API; fortunately, jqeury diff --git a/swtr/static/js/lib/custom-fields-plugin.js b/swtr/static/js/lib/custom-fields-plugin.js index d063ea1..27d0979 100644 --- a/swtr/static/js/lib/custom-fields-plugin.js +++ b/swtr/static/js/lib/custom-fields-plugin.js @@ -3,9 +3,17 @@ annotorious.plugin.CustomFields = function(opt_config_options) { var editorTemplate = _.template($('#customEdit-template').html()); //returns the HTML string for the editor annotorious.plugin.CustomFields.prototype.onInitAnnotator = function(annotorious) { + // add the our editor interface's template to the annotorious editor annotorious.editor.addField(editorTemplate); + // next prepare the fields for the annotation popups.. annotorious.popup.addField(function(annotation) { + // HACK! to get around disabling annotorious' default text box in the + // popup.. + if(!annotation.text) { + $('.annotorious-popup-text').hide(); + } + // this is the title return (annotation.title) ? '

' + annotation.title + '

' : ''; }); annotorious.popup.addField(function(annotation) { diff --git a/swtr/static/js/main.js b/swtr/static/js/main.js index 9bcceb1..c57063a 100644 --- a/swtr/static/js/main.js +++ b/swtr/static/js/main.js @@ -51,7 +51,6 @@ }, render: function() { console.log('sweetsview rendering'); -// debugger; $('#sweet-list').html('

These are your sweet annotations!

'); _.each(this.collection.models, function(swt) { if(swt.has('id')) { @@ -95,7 +94,6 @@ postSweets: function(event) { event.preventDefault(); console.log('posting swts'); -// debugger; var appView = swtr.appView; var self = this; this.helpview.step(5); @@ -107,10 +105,15 @@ anno.reset(); anno.makeAnnotatable($("#annotatable-img")[0]); swtr.imgAnnoView.renderWith(); - // _.each(collection, function(k) { - // anno.removeAnnotation(k['how']); - // }); - swtr.sweets.add(collection, {merge: true}); + swtr.sweets.add(collection); + //HACK! somehow updated models from the server don't get merged + //with existing models, they duplicate. this is probably because of + //some attribute change that backbone is not able to detect the + //models are same. FIX for now is to update the collection with + //updated models from the server and delete the older ones(w/o + //id's).. + self.removeSwtsNotPosted(); + console.log('new swtr coll', swtr.sweets); appView.$overlay.hide(); self.helpview.step(6); @@ -229,11 +232,8 @@ sweet: function(event) { event.preventDefault(); console.log('sweeting'); -// debugger; this.getSweets(); -// debugger; this.showSweets(); -// debugger; return false; }, // function to update the urls in the UI if an image is loaded internally diff --git a/swtr/templates/index.html b/swtr/templates/index.html index e2da5bd..ddc765b 100644 --- a/swtr/templates/index.html +++ b/swtr/templates/index.html @@ -320,8 +320,8 @@
-
@@ -329,7 +329,7 @@ {% if url %} Annotation Workbench {% else %} - Annotation Workbench + {% endif %}
-- 1.7.10.4