Commit 7f993292916475595ce2e6f9656a1b288f5b355b

Fix problems with breaking the annotation into its component parts
  
77}
88#img-annotation-wrapper {
99 margin: 30px auto 0 auto;
10 /*border: 1px solid black;*/
11 /*min-height: 500px;*/
1210}
1311#annotatable-img {
12 margin: 0 auto;
1413}
1514#sweet-list-wrapper {
1615 width: 500px;
  
11annotorious.plugin.CustomFields = function(opt_config_options) {
22
3annotorious.plugin.CustomFields.prototype.onInitAnnotator = function(annotorious) {
4 var dropDownTemplate= _.template($('#dropdown-template').html()); // creates the HTML element for dropdown - from template in index.html
5 annotorious.editor.addField(dropDownTemplate); // add dropdown to editor UI widget
6 annotorious.popup.addField( function(annotation){
7 var popupTemplate = _.template($('#popup-template').html()); //created a popup template - yet to find how to bind it to newanno
8 if(annotation.text1 != undefined) {
9 //console.log(annotation.text1.Comment); annotation.text is Obj - can
10 //access each element Comment, tags, links..
11 return popupTemplate(annotation.text1);
3 annotorious.plugin.CustomFields.prototype.onInitAnnotator = function(annotorious) {
4
5 // creates the HTML element for dropdown - from template in index.html
6 var dropDownTemplate= _.template($('#dropdown-template').html());
7
8 // add dropdown to editor UI widget
9 annotorious.editor.addField(dropDownTemplate);
10
11 annotorious.popup.addField(function(annotation) {
12 // created a popup template - yet to find how to bind it to newanno
13 var popupTemplate = _.template($('#popup-template').html());
14
15 if(annotation.text1 != undefined) {
16 //console.log(annotation.text1.Comment); annotation.text is Obj - can
17 //access each element Comment, tags, links..
18 return popupTemplate(annotation.text1);
1219 }
1320 else {
14 return '';
21 return '';
1522 }
16 });
17 }
23 });
24 }
1825}
  
44 //Find a better way to do closure
55 //Remove script code from the HTML page
66 swtr.init = function() {
7 swtr.sweets = new ImgAnnoSwts();
8 swtr.appView = new AppView();
9 swtr.who = 'Guest';
7 this.sweets = new ImgAnnoSwts();
8 this.appView = new AppView();
9 this.who = 'Guest';
1010
1111 $.ajaxSetup({
1212 xhrFields: {
1616 //some browsers won't make cross-domain ajax until it is explicitly set
1717 crossDomain: true
1818 });
19 swtr.handleOAuth();
19 this.handleOAuth();
2020 };
2121
2222 swtr.handleOAuth = function() {
158158 who: swt.get('who'),
159159 what: swt.get('what'),
160160 where: swt.get('where'),
161 how: JSON.stringify(swt.get('how').text)
161 how: JSON.stringify(this.getHumanReadableParts(swt.get('how')))
162162 }));
163163 }, this);
164164 $(this.el).fadeIn(300);
165165 },
166 getHumanReadableParts: function(how) {
167 var human_readable_json = {};
168 if(how.comment) {
169 human_readable_json['comment'] = how.comment;
170 }
171 if(how.title) {
172 human_readable_json['title'] = how.title;
173 }
174 if(how.tags) {
175 human_readable_json['tags'] = how.tags;
176 }
177 if(how.link) {
178 human_readable_json['link'] = how.link;
179 }
180 return human_readable_json;
181 },
166182 cancelSweeting: function() {
167183 this.removeSwtsNotPosted();
168184 this.cleanUp();
204204 if(!_.has(swt.get('how'), 'editable')) {
205205 swt.get('how')['editable'] = false;
206206 //console.log(swt.get('how').text.Comment);
207 swt.get('how').text = appView.createPopupText(swt.get('how'));
208 //console.log(swt.get('how'));
207209 swt.get('how').text += '\n - by ' + swt.get('who');
208210 }
209211 //console.log(swt.get('how'));
210212 anno.addAnnotation(swt.get('how'));
211213 });
212214 //console.log(swtr.sweets.toJSON());
213 appView.overlay.hide();
214 appView.helpview.step(6);
215 swtr.appView.$overlay.hide();
216 swtr.appView.helpview.step(6);
215217 },
216218 error: function(jqxhr, error, text) {
217219 console.log(jqxhr, error, text);
242242 'click #sweet': 'sweet',
243243 'click #sign-in': 'signIn',
244244 'click #setbox': 'showHide',
245 'change #custom-dropdown ': 'getFormValue',
246 'mouseup .annotorious-editor-button-save': 'addNewAnno'
245 'change #custom-dropdown ': 'getFormValue'
246 //'mouseup .annotorious-editor-button-save': 'addnew_anno'
247247 },
248248 initialize: function() {
249249 // initialize components
252252
253253 //register handlers for annotorious events
254254 anno.addHandler('onAnnotationCreated', this.showSwtHelp);
255 anno.addHandler('onAnnotationCreated', this.updateNewAnno);
255256 anno.addHandler('onAnnotationUpdated', this.showSwtHelp);
256257 anno.addHandler('onSelectionStarted', function(annotation) {
257 anno.hideAnnotations();});
258 anno.hideAnnotations();
259 });
258260 anno.addHandler('onSelectionCompleted', function(annotation) {
259261 anno.showAnnotations();
260262 });
261263 anno.addPlugin('CustomFields', {});
262 anno.addHandler('onSelectionCompleted', this.getShape);
264 anno.addHandler('onSelectionCompleted', this.hideOriginalEditor);
263265
264266 // cache jquery selected elements which are used frequently
265267 this.$overlay = $('#app-overlay');
296296 if(!this.imgURL) {
297297 return false;
298298 }
299 if(this.$img.attr('src') === this.imgURL) {
300 return;
301 }
299302 anno.reset();
300303 var self = this;
301304 this.$overlay.show();
341341 swtr.sweets.add(data);
342342 _.each(data, function(swt) {
343343 swt.how['editable'] = false;
344 if(typeof swt.how.text === 'object') {
345 swt.how.text1 = swt.how.text;
346 swt.how.text = '\n - by ' + swt.who;
344 /*if(typeof swt.how.text === 'object') {
345 swt.how.text1 = swt.how.text;
346 swt.how.text = '\n - by ' + swt.who;
347347 } else {
348348 swt.how.text1 = undefined;
349349 swt.how.text += '\n -by ' + swt.who;
350 }
351
350 }*/
351 swt.how.text = self.createPopupText(swt.how);
352 swt.how.text += '\n - by ' + swt.who;
353 //console.log(swt.how);
352354 anno.addAnnotation(swt.how);
353355 });
354356 self.$overlay.hide();
380380 swtr.sweets.add({
381381 who: swtr.who,
382382 where: anno.src,
383 how: anno //mysterious link to create the sweet with new anno attributes, tags, links, labels
383 // remove the text field; we don't want to store that in the sweets
384 how: _.omit(anno, 'text')
384385 });
385386 });
386387 },
401401 $('.annotorious-item-unfocus').css("opacity", "0");
402402 }
403403 },
404 //annotorious editor widget - custom with options
405 //to obtain shapes object, declaring annotation in global scope - TODO refactor
406 //code to find better way to do this.
407 getShape: function(annotation) {
408 $('.annotorious-editor-text').slideUp();
409 $('.annotorious-editor').css('width', '100%');
410 window.annotation=annotation; // to use annotation.shape in newanno
411 annotation.text = {}; // creating new text object - to contain comments, labels, links and tags
404 // hide the original editor window, when user has completed selecting part
405 // of the image to annotate..
406 hideOriginalEditor: function(annotation) {
407 console.log('hideOriginalEditor()');
408 var self = swtr.appView;
409 self.new_anno = {};
410 $('.annotorious-editor-text').hide();
411 //$('.annotorious-editor').css('width', '100%');
412 //window.annotation = annotation; // to use annotation.shape in new_anno
413 //annotation.text = {}; // creating new text object - to contain comments, labels, links and tags
412414 },
413 //to create new annotation object
414 annoTemplate: function(opt) {
415 var annoText = opt;
416 var src = $('#img-url-input').val();
417 this.newanno = {
418 'src': src,
419 'text': annoText,
420 'shapes': [{
421 'type': annotation.shape.type,
422 'geometry': {
423 'x':annotation.shape.geometry.x,
424 'y': annotation.shape.geometry.y,
425 'width': annotation.shape.geometry.width,
426 'height': annotation.shape.geometry.height
427 }
428 }],
429 'context': window.location.origin
430 };
431 },
432 //to add the final annotation
433 //save button - event bind
434 addNewAnno: function(event) {
435 var $selected = $('select option:selected').text();
436 var textInput = $('.annotorious-editor textarea').val();
437 this.newanno.text[$selected] = textInput;
438 var newanno = this.newanno;
439 anno.addAnnotation(newanno);
440 },
441 /*addNewAnno: function(event){ // function for form input UI
442 var tags = $('#tags').val();
443 var label = $('#label').val();
444 var link = $('#links').val();
445 var text = $('.annotorious-editor textarea').val();
446 var finalInput = ' Label: '+label+' Comment: '+text+' Tags: '+tags+' Links: '+link;
447 //this.annoTemplate(label, text, tags, link);
448 // this.annoTemplate(label, text, tags, link);
449 var src = $('#img-url-input').val();
450 var newanno = {'src':src, 'text':finalInput, 'shapes': [{'type':annotation.shape.type, 'geometry':{'x':annotation.shape.geometry.x, 'y':annotation.shape.geometry.y, 'width':annotation.shape.geometry.width, 'height':annotation.shape.geometry.height}},], 'context':window.location.origin};
451 console.log(newanno);
452 anno.addAnnotation(newanno);
453 },*/
454415 //dropdown event
455416 getFormValue: function(event) {
456 var annoForm = $('.annotorious-editor-text');
457 annoForm.slideDown();
417 console.log('getFormValue()');
418 var self = swtr.appView;
419 // show the editor field to input text
420 var $anno_form = $('.annotorious-editor-text');
421 $anno_form.slideDown();
422 // get the previous item entered
458423 var $selected = $('select option:selected');
459 var textInput = annoForm.val();
460 if(textInput) {
461 annotation.text[$selected.prev().text()] = textInput;
424 var text_input = $anno_form.val();
425 if(text_input) {
426 var field = $selected.prev().text().toLowerCase();
427 // update it in our annotation object
428 self.new_anno[field] = text_input;
462429 }
463 this.annoTemplate(annotation.text);
464 annoForm.val('');
465 annoForm.attr('placeholder', 'Add '+$selected.text());
430 if($selected.text() === 'Tags') {
431 //TODO: open up the tag sprayer component
432 }
433 $anno_form.val('');
434 $anno_form.attr('placeholder', 'Add ' + $selected.text());
435 console.log(self.new_anno);
436 },
437 //to add the final annotation
438 //save button - event bind
439 updateNewAnno: function(annotation) {
440 console.log('updateNewAnno()');
441 var self = swtr.appView;
442 // get the final value/input from the editor
443 var selected = $('select option:selected').text().toLowerCase();
444 var text_input = $('.annotorious-editor-text').val();
445 // update it in our annotation object
446 self.new_anno[selected] = text_input;
447 // prepare the text field
448 self.new_anno.text = self.createPopupText(self.new_anno);
449 // update the annotorious annotation object with the new values
450 if(self.new_anno.comment) {
451 annotation.comment = self.new_anno.comment;
452 }
453 if(self.new_anno.link) {
454 annotation.link = self.new_anno.link;
455 }
456 if(self.new_anno.tags) {
457 annotation.tags= self.new_anno.tags;
458 }
459 if(self.new_anno.title) {
460 annotation.title = self.new_anno.title;
461 }
462 annotation.text = self.new_anno.text;
463 console.log(self.new_anno, annotation);
464 },
465 // create the text to displayed for each annotation from the other
466 // attributes of the sweet/annotation
467 createPopupText: function(annotation) {
468 var text = (annotation.title) ? '<h4>' + annotation.title + '</h4>' : '';
469 text += (annotation.comment) ? '<p>' + annotation.comment + '</p>' : '';
470 text += (annotation.link) ? '<p>' + annotation.link + '</p>' : '';
471 text += (annotation.tags) ? '<p>' + annotation.tags + '</p>' : '';
472 return text;
466473 },
467474 // to sign in the user to swtstore..just make a call to the oauth endpoint
468475 signIn: function(event) {
  
101101 <script src="{{ url_for('static', filename='js/lib/backbone-1.0.0.min.js') }}"></script>
102102 <script src="{{ url_for('static', filename='js/lib/annotorious.debug.js') }}"></script>
103103 <script src="{{ url_for('static', filename='js/lib/custom-fields-plugin.js') }}"></script>
104 <script src="{{ url_for('static', filename='js/lib/label.js') }}"></script>
105104 <script src="{{ url_for('static', filename='js/oauth.js') }}"></script>
106105 <script src="{{ url_for('static', filename='js/swtmaker.js') }}"></script>
107106
108108 <li class="sweet">
109109 <a href="#">@<%= who %></a> <strong>#<%= what %></strong>
110110 /<a href="<%= where %>"><%= where.substr(0, 30) + '...' %></a>
111 <%= how %>
111 <p><%= how %></p>
112112 </li>
113113 </script>
114114 <script type="text/template" id="dropdown-template">
117117 <option id="comment" >Comment</option>
118118 <option id="title" >Title</option>
119119 <option id="tags">Tags</option>
120 <option id="links">Links</option>
120 <option id="link">Link</option>
121121 </select>
122122 </script>
123123 <!-- script type="text/template" id="dropdown-template">