--- a/swtr/static/css/swtmaker.css +++ b/swtr/static/css/swtmaker.css @@ -18,13 +18,6 @@ margin-left: 0; } -#signinview { - margin 0 20px; - padding: 10px; - text-align: center; - z-index: 100001; -} - #img-annotation-wrapper, #ocd-results { margin: 30px auto 0 auto; } @@ -100,7 +93,8 @@ background-color: rgba(255, 255, 255, 0.7); } -#user-input-row .form-inline .form-control { +#user-input-row .form-inline .form-control, +#search-user-input-row .form-inline .form-control { width: 100%; } --- a/swtr/static/js/img_swtr.js +++ b/swtr/static/js/img_swtr.js @@ -1,4 +1,105 @@ (function(swtr) { + + /* Model for Image Annotation Sweets */ + var ImgAnnoSwt = Backbone.Model.extend({ + defaults: { + 'who': '', + 'what': 'img-anno', + 'where': '', + 'how': {} + }, + initialize: function() { + } + }); + + /* Collection to hold all multiple ImgAnnoSwt */ + swtr.ImgAnnoSwts = Backbone.Collection.extend({ + model: ImgAnnoSwt, + url: function() { + return swtr.swtstoreURL() + '/sweets'; + }, + // get all sweets/annotations of type #img-anno for a particular URI + // (where) + // @options is a javascript object, + // @options.where : URI of the resource for which swts to be fetched + // @options.who: optional username to filter sweets + // @options.success: success callback to call + // @options.error: error callback to call + getAll: function(options) { + // error checking + if(!options.where) { + throw Error('"where" option must be passed to get sweets of a URI'); + return false; + } + // setting up params + var where = options.where, + who = options.who || null; + url = swtr.swtstoreURL() + swtr.endpoints.get + '?where=' + + encodeURIComponent(where) + '&access_token=' + swtr.access_token; + if(who) { + url += '&who=' + who; + } + // get them! + this.sync('read', this, { + url: url, + success: function() { + if(typeof options.success === 'function') { + options.success.apply(this, arguments); + } + }, + error: function() { + if(typeof options.error === 'function') { + options.error.apply(this, arguments); + } + } + }); + }, + // post newly created sweets to a sweet store + // @options is a javascript object, + // @options.where : URI of the resource for which swts to be fetched + // @options.who: optional username to filter sweets + // @options.success: success callback to call + // @options.error: error callback to call, + post: function(options) { + var new_sweets = this.getNew(); + var dummy_collection = new Backbone.Collection(new_sweets); + + if(!swtr.access_token) { + throw new Error('Access Token is required to sweet'); + return; + } + + var url = swtr.swtstoreURL() + swtr.endpoints.post + + '?access_token=' + swtr.access_token; + + this.sync('create', dummy_collection, { + url: url, + success: function() { + if(typeof options.success === 'function') { + options.success.apply(this, arguments); + } + }, + error: function() { + if(typeof options.error === 'function') { + options.error.apply(this, arguments); + } + } + }); + }, + // return newly created models from the collection + getNew: function() { + var new_models = []; + this.each(function(model) { + if(model.isNew()) { + new_models.push(model); + } + }); + return new_models; + }, + // update part of the collection after a save on the server + update: function() { + } + }); swtr.ImgAnnoView = Backbone.View.extend({ el: $("#img-annotation-wrapper"), events: { --- a/swtr/static/js/main.js +++ b/swtr/static/js/main.js @@ -4,13 +4,13 @@ //Find a better way to do closure //Remove script code from the HTML page swtr.init = function() { - this.sweets = new ImgAnnoSwts(); + this.sweets = new swtr.ImgAnnoSwts(); this.appView = new AppView(); this.who = 'Guest'; this.app_router = new AppRouter(); Backbone.history.start(); - this.app_router.navigate('home'); + this.app_router.start(); $.ajaxSetup({ xhrFields: { @@ -39,107 +39,6 @@ } }; - /* Model for Image Annotation Sweets */ - var ImgAnnoSwt = Backbone.Model.extend({ - defaults: { - 'who': '', - 'what': 'img-anno', - 'where': '', - 'how': {} - }, - initialize: function() { - } - }); - - /* Collection to hold all multiple ImgAnnoSwt */ - var ImgAnnoSwts = Backbone.Collection.extend({ - model: ImgAnnoSwt, - url: function() { - return swtr.swtstoreURL() + '/sweets'; - }, - // get all sweets/annotations of type #img-anno for a particular URI - // (where) - // @options is a javascript object, - // @options.where : URI of the resource for which swts to be fetched - // @options.who: optional username to filter sweets - // @options.success: success callback to call - // @options.error: error callback to call - getAll: function(options) { - // error checking - if(!options.where) { - throw Error('"where" option must be passed to get sweets of a URI'); - return false; - } - // setting up params - var where = options.where, - who = options.who || null; - url = swtr.swtstoreURL() + swtr.endpoints.get + '?where=' + - encodeURIComponent(where) + '&access_token=' + swtr.access_token; - if(who) { - url += '&who=' + who; - } - // get them! - this.sync('read', this, { - url: url, - success: function() { - if(typeof options.success === 'function') { - options.success.apply(this, arguments); - } - }, - error: function() { - if(typeof options.error === 'function') { - options.error.apply(this, arguments); - } - } - }); - }, - // post newly created sweets to a sweet store - // @options is a javascript object, - // @options.where : URI of the resource for which swts to be fetched - // @options.who: optional username to filter sweets - // @options.success: success callback to call - // @options.error: error callback to call, - post: function(options) { - var new_sweets = this.getNew(); - var dummy_collection = new Backbone.Collection(new_sweets); - - if(!swtr.access_token) { - throw new Error('Access Token is required to sweet'); - return; - } - - var url = swtr.swtstoreURL() + swtr.endpoints.post + - '?access_token=' + swtr.access_token; - - this.sync('create', dummy_collection, { - url: url, - success: function() { - if(typeof options.success === 'function') { - options.success.apply(this, arguments); - } - }, - error: function() { - if(typeof options.error === 'function') { - options.error.apply(this, arguments); - } - } - }); - }, - // return newly created models from the collection - getNew: function() { - var new_models = []; - this.each(function(model) { - if(model.isNew()) { - new_models.push(model); - } - }); - return new_models; - }, - // update part of the collection after a save on the server - update: function() { - } - }); - var SweetsView = Backbone.View.extend({ el: $('#sweet-list-wrapper'), events: { @@ -370,20 +269,19 @@ 'click #user-input-submit': 'submitUserInput', 'click #sweet': 'sweet', 'click #sign-in': 'signIn', - 'click #ocd-source': 'sourceChanged' //'mouseup .annotorious-editor-button-save': 'addnew_anno' }, initialize: function() { // initialize components this.source = 'none'; - this.helpview = new HelpView(); + //this.helpview = new HelpView(); this.sweetsview = new SweetsView({collection: swtr.sweets}); // cache jquery selected elements which are used frequently this.$overlay = $('#app-overlay'); this.$img = $('#annotatable-img'); - this.helpview.step(1); + //this.helpview.step(1); // initialize the oauth stuff this.oauth = new Oauth({ app_id: swtr.app_id, @@ -419,10 +317,12 @@ swtr.imgAnnoView.setImage(url); } else { - swtr.imgAnnoView = new swtr.ImgAnnoView({collection:swtr.sweets, - img: this.$img[0], - $img: this.$img, - url: url}); + swtr.imgAnnoView = new swtr.ImgAnnoView({ + collection:swtr.sweets, + img: this.$img[0], + $img: this.$img, + url: url + }); } return false; } @@ -496,61 +396,70 @@ }, userLoggedIn: function(username) { swtr.who = username; - var text = 'Signed in as ' + swtr.who + ''; + var text = 'Signed in as ' + swtr.who + ''; $('#signinview').html(text); }, userLoggedOut: function() { swtr.who = 'Guest'; $('#signinview').html('Logged out'); + } + }); + + + var PlayAreaView = Backbone.View.extend({ + el: $('#play-page'), + events: { }, - changeURLInputPlaceholder: function(source) { - switch (source) { - case 'ocd' : $('#user-input').attr('placeholder', 'Enter search query'); - break; - case 'none' : $('#user-input').attr('placeholder', 'Enter URL of image or web page'); - break; - } + initialize: function() { + this.render(); }, - // function to change the source in the application and update the UI - changeSource: function(source) { - switch (source) { - case 'ocd' : this.source = 'ocd'; - this.helpview.step(11); - this.changeURLInputPlaceholder('ocd'); - break; - case 'none' : this.source = 'none'; - this.helpview.step(1); - this.changeURLInputPlaceholder('none'); - break; - } + render: function() { + } + }); + + var SearchView = Backbone.View.extend({ + id: 'search-page-container', + events: { + 'click #search-user-input-submit': 'userInputSubmit' }, - // event handler to capture control panel UI change of source - sourceChanged: function(event) { - if($('#ocd-source').is(':checked')) { - this.changeSource('ocd'); - } - else { - this.changeSource('none'); - } + initialize: function() { + this.template = _.template($('#search-page-template').html()); + this.helpview = new HelpView(); + this.render(); + this.helpview.step(11); }, - loadOCDSearch: function(input) { + render: function() { + this.$el.html(this.template()); + $('#search-page').html(this.$el); + }, + userInputSubmit: function(event) { + event.preventDefault(); + var input = $('#search-user-input').val(); + this.loadSearch(input); + return false; + }, + loadSearch: function(input) { var self = this; - $('#img-annotation-wrapper').hide(); - $('#ocd-results').show(); - $('#ocd-results').html('