Skip to content
Browse files

Refactoring

  • Loading branch information...
1 parent 1393327 commit 667224f587a5728011239c2dd75eb3495f5fb7c4 @ccoenraets committed Jan 30, 2012
View
6 WebContent/WEB-INF/web.xml
@@ -11,18 +11,18 @@
<param-value>org.coenraets</param-value>
</init-param>
-->
-
+
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>org.coenraets;org.codehaus.jackson.jaxrs</param-value>
</init-param>
-
+
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey</servlet-name>
- <url-pattern>/rest/*</url-pattern>
+ <url-pattern>/api/*</url-pattern>
</servlet-mapping>
</web-app>
View
26 WebContent/css/styles.css
@@ -3,11 +3,11 @@
font-size: 18px;
}
-.header {
+#header {
padding-top: 5px;
}
-.leftArea {
+#sidebar {
position: absolute;
left: 10px;
top: 70px;
@@ -17,22 +17,20 @@
overflow-y: scroll;
}
+#content {
+ position: absolute;
+ top: 70px;
+ bottom: 20px;
+ left:300px;
+ right:20px;
+}
+
.form-left-col {
- position: absolute;
- top: 70px;
- bottom: 20px;
- left:300px;
- overflow-y: scroll;
- width:300px;
+ width:310px;
+ float: left;
}
.form-right-col {
- position: absolute;
- top: 70px;
- bottom: 20px;
- left:650px;
- overflow-y: scroll;
- width:270px;
}
ul {
View
65 WebContent/index.html
@@ -7,63 +7,26 @@
<body>
-<div class="header">
-</div>
+<div id="header"></div>
-<div class="leftArea">
- <ul id="wineList"></ul>
-</div>
+<div id="sidebar"></div>
-<div id="mainArea">
+<div id="content">
+ <h1>Welcome to Backbone Wine Cellar</h1>
</div>
-<script type="text/template" id="header">
- <button class="new">New Wine</button>
-</script>
-
-<script type="text/template" id="wine-list-item">
- <li><a href='#wines/<%= id %>'><%= name %></a></li>
-</script>
-
-<script type="text/template" id="wine-details">
-
-<div class="form-left-col">
-
-<label>Id:</label>
-<input id="wineId" name="id" type="text" value="<%= id %>" disabled />
-
-<label>Name:</label>
-<input type="text" id="name" name="name" value="<%= name %>" required/>
-
-<label>Grapes:</label>
-<input type="text" id="grapes" name="grapes" value="<%= grapes %>"/>
-
-<label>Country:</label>
-<input type="text" id="country" name="country" value="<%= country %>"/>
+<script src="lib/jquery-1.7.1.min.js"></script>
+<script src="lib/underscore-min.js"></script>
+<script src="lib/backbone-min.js"></script>
-<label>Region:</label>
-<input type="text" id="region" name="region" value="<%= region %>"/>
-<label>Year:</label>
-<input type="text" id="year" name="year" value="<%= year %>"/>
-
-<button class="save">Save</button>
-<button class="delete">Delete</button>
-
-</div>
-
-<div class="form-right-col">
-<img height="300" src="pics/<%= picture %>"/>
-<label>Notes:</label>
-<textarea id="description" name="description"><%= description %></textarea>
-</div>
-
-</script>
-
-<script src="js/jquery-1.7.1.min.js"></script>
-<script src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
-<script src="http://documentcloud.github.com/backbone/backbone-min.js"></script>
-<script src="js/main.js"></script>
+<script src="js/utils.js"></script>
+<script src="js/models/winemodel.js"></script>
+<script src="js/views/header.js"></script>
+<script src="js/views/winelist.js"></script>
+<script src="js/views/winedetails.js"></script>
+<script src="js/main.js"></script>
</body>
+
</html>
View
218 WebContent/js/main.js
@@ -1,198 +1,64 @@
-window.Wine = Backbone.Model.extend({
- urlRoot: "rest/wines",
- defaults: {
- "id": null,
- "name": "",
- "grapes": "",
- "country": "USA",
- "region": "California",
- "year": "",
- "description": "",
- "picture": ""
- }
-});
-
-window.WineCollection = Backbone.Collection.extend({
- model: Wine,
- url: "rest/wines"
-});
-
-window.WineListView = Backbone.View.extend({
-
- el: $('#wineList'),
-
- initialize: function() {
- this.model.bind("reset", this.render, this);
- this.model.bind("add", function(wine) {
- $('#wineList').append(new WineListItemView({model: wine}).render().el);
- });
- },
-
- render: function(eventName) {
- _.each(this.model.models, function(wine) {
- $(this.el).append(new WineListItemView({model: wine}).render().el);
- }, this);
- return this;
+Backbone.View.prototype.close = function () {
+ console.log('Closing view ' + this);
+ if (this.beforeClose) {
+ this.beforeClose();
}
-});
-
-window.WineListItemView = Backbone.View.extend({
-
- tagName: "li",
-
- template: _.template($('#wine-list-item').html()),
+ this.remove();
+ this.unbind();
+};
- initialize: function() {
- this.model.bind("change", this.render, this);
- this.model.bind("destroy", this.close, this);
- },
-
- render: function(eventName) {
- $(this.el).html(this.template(this.model.toJSON()));
- return this;
- },
-
- close: function() {
- $(this.el).unbind();
- $(this.el).remove();
- }
-});
-
-window.WineView = Backbone.View.extend({
-
- el: $('#mainArea'),
-
- template: _.template($('#wine-details').html()),
-
- initialize: function() {
- this.model.bind("change", this.render, this);
- },
-
- render: function(eventName) {
- $(this.el).html(this.template(this.model.toJSON()));
- return this;
- },
-
- events: {
- "change input": "change",
- "click .save": "saveWine",
- "click .delete": "deleteWine"
- },
-
- change: function(event) {
- var target = event.target;
- console.log('changing ' + target.id + ' from: ' + target.defaultValue + ' to: ' + target.value);
- // You could change your model on the spot, like this:
- // var change = {};
- // change[target.name] = target.value;
- // this.model.set(change);
- },
-
- saveWine: function() {
- this.model.set({
- name: $('#name').val(),
- grapes: $('#grapes').val(),
- country: $('#country').val(),
- region: $('#region').val(),
- year: $('#year').val(),
- description: $('#description').val()
- });
- if (this.model.isNew()) {
- var self = this;
- app.wineList.create(this.model, {
- success: function() {
- app.navigate('wines/'+self.model.id, false);
- }
- });
- } else {
- this.model.save();
- }
-
- return false;
- },
-
- deleteWine: function() {
- this.model.destroy({
- success: function() {
- alert('Wine deleted successfully');
- window.history.back();
- }
- });
- return false;
- },
-
- close: function() {
- $(this.el).unbind();
- $(this.el).empty();
- }
-});
-
-window.HeaderView = Backbone.View.extend({
-
- el: $('.header'),
-
- template: _.template($('#header').html()),
+var AppRouter = Backbone.Router.extend({
initialize: function() {
- this.render();
+ $('#header').html( new HeaderView().render().el );
},
- render: function(eventName) {
- $(this.el).html(this.template());
- return this;
- },
-
- events: {
- "click .new": "newWine"
- },
-
- newWine: function(event) {
- app.navigate("wines/new", true);
- return false;
- }
-});
-
-var AppRouter = Backbone.Router.extend({
-
routes: {
"" : "list",
"wines/new" : "newWine",
"wines/:id" : "wineDetails"
},
list: function() {
- this.wineList = new WineCollection();
- var self = this;
- this.wineList.fetch({
- success: function() {
- self.wineListView = new WineListView({model: self.wineList});
- self.wineListView.render();
- if (self.requestedId) self.wineDetails(self.requestedId);
- }
- });
+ this.before();
},
wineDetails: function(id) {
- if (this.wineList)
- {
- this.wine = this.wineList.get(id);
- if (this.wineView) this.wineView.close();
- this.wineView = new WineView({model: this.wine});
- this.wineView.render();
- } else {
- this.requestedId = id;
- this.list();
- }
+ this.before(function() {
+ var wine = app.wineList.get(id);
+ app.showView( '#content', new WineView({model: wine}) );
+ });
},
newWine: function() {
- if (app.wineView) app.wineView.close();
- app.wineView = new WineView({model: new Wine()});
- app.wineView.render();
- }
+ this.before(function() {
+ app.showView( '#content', new WineView({model: new Wine()}) );
+ });
+ },
+
+ showView: function(selector, view) {
+ if (this.currentView)
+ this.currentView.close();
+ $(selector).html(view.render().el);
+ this.currentView = view;
+ return view;
+ },
+
+ before: function(callback) {
+ if (this.wineList) {
+ if (callback) callback();
+ } else {
+ this.wineList = new WineCollection();
+ this.wineList.fetch({success: function() {
+ $('#sidebar').html( new WineListView({model: app.wineList}).render().el );
+ if (callback) callback();
+ }});
+ }
+ }
});
-var app = new AppRouter();
-Backbone.history.start();
-var header = new HeaderView();
+tpl.loadTemplates(['header', 'wine-details', 'wine-list-item'], function() {
+ app = new AppRouter();
+ Backbone.history.start();
+});
View
18 WebContent/js/models/winemodel.js
@@ -0,0 +1,18 @@
+window.Wine = Backbone.Model.extend({
+ urlRoot: "api/wines",
+ defaults: {
+ "id": null,
+ "name": "",
+ "grapes": "",
+ "country": "USA",
+ "region": "California",
+ "year": "",
+ "description": "",
+ "picture": ""
+ }
+});
+
+window.WineCollection = Backbone.Collection.extend({
+ model: Wine,
+ url: "api/wines"
+});
View
35 WebContent/js/utils.js
@@ -0,0 +1,35 @@
+tpl = {
+
+ // Hash of preloaded templates for the app
+ templates: {},
+
+ // Recursively pre-load all the templates for the app.
+ // This implementation should be changed in a production environment. All the template files should be
+ // concatenated in a single file.
+ loadTemplates: function(names, callback) {
+
+ var that = this;
+
+ var loadTemplate = function(index) {
+ var name = names[index];
+ console.log('Loading template: ' + name);
+ $.get('tpl/' + name + '.html', function(data) {
+ that.templates[name] = data;
+ index++;
+ if (index < names.length) {
+ loadTemplate(index);
+ } else {
+ callback();
+ }
+ });
+ }
+
+ loadTemplate(0);
+ },
+
+ // Get template by name from hash of preloaded templates
+ get: function(name) {
+ return this.templates[name];
+ }
+
+};
View
21 WebContent/js/views/header.js
@@ -0,0 +1,21 @@
+window.HeaderView = Backbone.View.extend({
+
+ initialize: function() {
+ this.template = _.template(tpl.get('header'));
+ },
+
+ render: function(eventName) {
+ $(this.el).html(this.template());
+ return this;
+ },
+
+ events: {
+ "click .new" : "newWine"
+ },
+
+ newWine: function(event) {
+ app.navigate("wines/new", true);
+ return false;
+ }
+
+});
View
63 WebContent/js/views/winedetails.js
@@ -0,0 +1,63 @@
+window.WineView = Backbone.View.extend({
+
+ tagName: "div", // Not required since 'div' is the default if no el or tagName specified
+
+ initialize: function() {
+ this.template = _.template(tpl.get('wine-details'));
+ this.model.bind("change", this.render, this);
+ },
+
+ render: function(eventName) {
+ $(this.el).html(this.template(this.model.toJSON()));
+ return this;
+ },
+
+ events: {
+ "change input": "change",
+ "click .save": "saveWine",
+ "click .delete": "deleteWine"
+ },
+
+ change: function(event) {
+ var target = event.target;
+ console.log('changing ' + target.id + ' from: ' + target.defaultValue + ' to: ' + target.value);
+ // You could change your model on the spot, like this:
+ // var change = {};
+ // change[target.name] = target.value;
+ // this.model.set(change);
+ },
+
+ saveWine: function() {
+ this.model.set({
+ name: $('#name').val(),
+ grapes: $('#grapes').val(),
+ country: $('#country').val(),
+ region: $('#region').val(),
+ year: $('#year').val(),
+ description: $('#description').val()
+ });
+ if (this.model.isNew()) {
+ var self = this;
+ app.wineList.create(this.model, {
+ success: function() {
+ app.navigate('wines/'+self.model.id, false);
+ }
+ });
+ } else {
+ this.model.save();
+ }
+
+ return false;
+ },
+
+ deleteWine: function() {
+ this.model.destroy({
+ success: function() {
+ alert('Wine deleted successfully');
+ window.history.back();
+ }
+ });
+ return false;
+ }
+
+});
View
36 WebContent/js/views/winelist.js
@@ -0,0 +1,36 @@
+window.WineListView = Backbone.View.extend({
+
+ tagName:'ul',
+
+ initialize:function () {
+ this.model.bind("reset", this.render, this);
+ var self = this;
+ this.model.bind("add", function (wine) {
+ $(self.el).append(new WineListItemView({model:wine}).render().el);
+ });
+ },
+
+ render:function (eventName) {
+ _.each(this.model.models, function (wine) {
+ $(this.el).append(new WineListItemView({model:wine}).render().el);
+ }, this);
+ return this;
+ }
+});
+
+window.WineListItemView = Backbone.View.extend({
+
+ tagName:"li",
+
+ initialize:function () {
+ this.template = _.template(tpl.get('wine-list-item'));
+ this.model.bind("change", this.render, this);
+ this.model.bind("destroy", this.close, this);
+ },
+
+ render:function (eventName) {
+ $(this.el).html(this.template(this.model.toJSON()));
+ return this;
+ }
+
+});
View
33 WebContent/lib/backbone-min.js
@@ -0,0 +1,33 @@
+// Backbone.js 0.5.3
+// (c) 2010 Jeremy Ashkenas, DocumentCloud Inc.
+// Backbone may be freely distributed under the MIT license.
+// For all details and documentation:
+// http://documentcloud.github.com/backbone
+(function(){var h=this,p=h.Backbone,e;e=typeof exports!=="undefined"?exports:h.Backbone={};e.VERSION="0.5.3";var f=h._;if(!f&&typeof require!=="undefined")f=require("underscore")._;var g=h.jQuery||h.Zepto;e.noConflict=function(){h.Backbone=p;return this};e.emulateHTTP=!1;e.emulateJSON=!1;e.Events={bind:function(a,b,c){var d=this._callbacks||(this._callbacks={});(d[a]||(d[a]=[])).push([b,c]);return this},unbind:function(a,b){var c;if(a){if(c=this._callbacks)if(b){c=c[a];if(!c)return this;for(var d=
+0,e=c.length;d<e;d++)if(c[d]&&b===c[d][0]){c[d]=null;break}}else c[a]=[]}else this._callbacks={};return this},trigger:function(a){var b,c,d,e,f=2;if(!(c=this._callbacks))return this;for(;f--;)if(b=f?a:"all",b=c[b])for(var g=0,h=b.length;g<h;g++)(d=b[g])?(e=f?Array.prototype.slice.call(arguments,1):arguments,d[0].apply(d[1]||this,e)):(b.splice(g,1),g--,h--);return this}};e.Model=function(a,b){var c;a||(a={});if(c=this.defaults)f.isFunction(c)&&(c=c.call(this)),a=f.extend({},c,a);this.attributes={};
+this._escapedAttributes={};this.cid=f.uniqueId("c");this.set(a,{silent:!0});this._changed=!1;this._previousAttributes=f.clone(this.attributes);if(b&&b.collection)this.collection=b.collection;this.initialize(a,b)};f.extend(e.Model.prototype,e.Events,{_previousAttributes:null,_changed:!1,idAttribute:"id",initialize:function(){},toJSON:function(){return f.clone(this.attributes)},get:function(a){return this.attributes[a]},escape:function(a){var b;if(b=this._escapedAttributes[a])return b;b=this.attributes[a];
+return this._escapedAttributes[a]=(b==null?"":""+b).replace(/&(?!\w+;|#\d+;|#x[\da-f]+;)/gi,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#x27;").replace(/\//g,"&#x2F;")},has:function(a){return this.attributes[a]!=null},set:function(a,b){b||(b={});if(!a)return this;if(a.attributes)a=a.attributes;var c=this.attributes,d=this._escapedAttributes;if(!b.silent&&this.validate&&!this._performValidation(a,b))return!1;if(this.idAttribute in a)this.id=a[this.idAttribute];
+var e=this._changing;this._changing=!0;for(var g in a){var h=a[g];if(!f.isEqual(c[g],h))c[g]=h,delete d[g],this._changed=!0,b.silent||this.trigger("change:"+g,this,h,b)}!e&&!b.silent&&this._changed&&this.change(b);this._changing=!1;return this},unset:function(a,b){if(!(a in this.attributes))return this;b||(b={});var c={};c[a]=void 0;if(!b.silent&&this.validate&&!this._performValidation(c,b))return!1;delete this.attributes[a];delete this._escapedAttributes[a];a==this.idAttribute&&delete this.id;this._changed=
+!0;b.silent||(this.trigger("change:"+a,this,void 0,b),this.change(b));return this},clear:function(a){a||(a={});var b,c=this.attributes,d={};for(b in c)d[b]=void 0;if(!a.silent&&this.validate&&!this._performValidation(d,a))return!1;this.attributes={};this._escapedAttributes={};this._changed=!0;if(!a.silent){for(b in c)this.trigger("change:"+b,this,void 0,a);this.change(a)}return this},fetch:function(a){a||(a={});var b=this,c=a.success;a.success=function(d,e,f){if(!b.set(b.parse(d,f),a))return!1;c&&
+c(b,d)};a.error=i(a.error,b,a);return(this.sync||e.sync).call(this,"read",this,a)},save:function(a,b){b||(b={});if(a&&!this.set(a,b))return!1;var c=this,d=b.success;b.success=function(a,e,f){if(!c.set(c.parse(a,f),b))return!1;d&&d(c,a,f)};b.error=i(b.error,c,b);var f=this.isNew()?"create":"update";return(this.sync||e.sync).call(this,f,this,b)},destroy:function(a){a||(a={});if(this.isNew())return this.trigger("destroy",this,this.collection,a);var b=this,c=a.success;a.success=function(d){b.trigger("destroy",
+b,b.collection,a);c&&c(b,d)};a.error=i(a.error,b,a);return(this.sync||e.sync).call(this,"delete",this,a)},url:function(){var a=k(this.collection)||this.urlRoot||l();if(this.isNew())return a;return a+(a.charAt(a.length-1)=="/"?"":"/")+encodeURIComponent(this.id)},parse:function(a){return a},clone:function(){return new this.constructor(this)},isNew:function(){return this.id==null},change:function(a){this.trigger("change",this,a);this._previousAttributes=f.clone(this.attributes);this._changed=!1},hasChanged:function(a){if(a)return this._previousAttributes[a]!=
+this.attributes[a];return this._changed},changedAttributes:function(a){a||(a=this.attributes);var b=this._previousAttributes,c=!1,d;for(d in a)f.isEqual(b[d],a[d])||(c=c||{},c[d]=a[d]);return c},previous:function(a){if(!a||!this._previousAttributes)return null;return this._previousAttributes[a]},previousAttributes:function(){return f.clone(this._previousAttributes)},_performValidation:function(a,b){var c=this.validate(a);if(c)return b.error?b.error(this,c,b):this.trigger("error",this,c,b),!1;return!0}});
+e.Collection=function(a,b){b||(b={});if(b.comparator)this.comparator=b.comparator;f.bindAll(this,"_onModelEvent","_removeReference");this._reset();a&&this.reset(a,{silent:!0});this.initialize.apply(this,arguments)};f.extend(e.Collection.prototype,e.Events,{model:e.Model,initialize:function(){},toJSON:function(){return this.map(function(a){return a.toJSON()})},add:function(a,b){if(f.isArray(a))for(var c=0,d=a.length;c<d;c++)this._add(a[c],b);else this._add(a,b);return this},remove:function(a,b){if(f.isArray(a))for(var c=
+0,d=a.length;c<d;c++)this._remove(a[c],b);else this._remove(a,b);return this},get:function(a){if(a==null)return null;return this._byId[a.id!=null?a.id:a]},getByCid:function(a){return a&&this._byCid[a.cid||a]},at:function(a){return this.models[a]},sort:function(a){a||(a={});if(!this.comparator)throw Error("Cannot sort a set without a comparator");this.models=this.sortBy(this.comparator);a.silent||this.trigger("reset",this,a);return this},pluck:function(a){return f.map(this.models,function(b){return b.get(a)})},
+reset:function(a,b){a||(a=[]);b||(b={});this.each(this._removeReference);this._reset();this.add(a,{silent:!0});b.silent||this.trigger("reset",this,b);return this},fetch:function(a){a||(a={});var b=this,c=a.success;a.success=function(d,f,e){b[a.add?"add":"reset"](b.parse(d,e),a);c&&c(b,d)};a.error=i(a.error,b,a);return(this.sync||e.sync).call(this,"read",this,a)},create:function(a,b){var c=this;b||(b={});a=this._prepareModel(a,b);if(!a)return!1;var d=b.success;b.success=function(a,e,f){c.add(a,b);
+d&&d(a,e,f)};a.save(null,b);return a},parse:function(a){return a},chain:function(){return f(this.models).chain()},_reset:function(){this.length=0;this.models=[];this._byId={};this._byCid={}},_prepareModel:function(a,b){if(a instanceof e.Model){if(!a.collection)a.collection=this}else{var c=a;a=new this.model(c,{collection:this});a.validate&&!a._performValidation(c,b)&&(a=!1)}return a},_add:function(a,b){b||(b={});a=this._prepareModel(a,b);if(!a)return!1;var c=this.getByCid(a);if(c)throw Error(["Can't add the same model to a set twice",
+c.id]);this._byId[a.id]=a;this._byCid[a.cid]=a;this.models.splice(b.at!=null?b.at:this.comparator?this.sortedIndex(a,this.comparator):this.length,0,a);a.bind("all",this._onModelEvent);this.length++;b.silent||a.trigger("add",a,this,b);return a},_remove:function(a,b){b||(b={});a=this.getByCid(a)||this.get(a);if(!a)return null;delete this._byId[a.id];delete this._byCid[a.cid];this.models.splice(this.indexOf(a),1);this.length--;b.silent||a.trigger("remove",a,this,b);this._removeReference(a);return a},
+_removeReference:function(a){this==a.collection&&delete a.collection;a.unbind("all",this._onModelEvent)},_onModelEvent:function(a,b,c,d){(a=="add"||a=="remove")&&c!=this||(a=="destroy"&&this._remove(b,d),b&&a==="change:"+b.idAttribute&&(delete this._byId[b.previous(b.idAttribute)],this._byId[b.id]=b),this.trigger.apply(this,arguments))}});f.each(["forEach","each","map","reduce","reduceRight","find","detect","filter","select","reject","every","all","some","any","include","contains","invoke","max",
+"min","sortBy","sortedIndex","toArray","size","first","rest","last","without","indexOf","lastIndexOf","isEmpty","groupBy"],function(a){e.Collection.prototype[a]=function(){return f[a].apply(f,[this.models].concat(f.toArray(arguments)))}});e.Router=function(a){a||(a={});if(a.routes)this.routes=a.routes;this._bindRoutes();this.initialize.apply(this,arguments)};var q=/:([\w\d]+)/g,r=/\*([\w\d]+)/g,s=/[-[\]{}()+?.,\\^$|#\s]/g;f.extend(e.Router.prototype,e.Events,{initialize:function(){},route:function(a,
+b,c){e.history||(e.history=new e.History);f.isRegExp(a)||(a=this._routeToRegExp(a));e.history.route(a,f.bind(function(d){d=this._extractParameters(a,d);c.apply(this,d);this.trigger.apply(this,["route:"+b].concat(d))},this))},navigate:function(a,b){e.history.navigate(a,b)},_bindRoutes:function(){if(this.routes){var a=[],b;for(b in this.routes)a.unshift([b,this.routes[b]]);b=0;for(var c=a.length;b<c;b++)this.route(a[b][0],a[b][1],this[a[b][1]])}},_routeToRegExp:function(a){a=a.replace(s,"\\$&").replace(q,
+"([^/]*)").replace(r,"(.*?)");return RegExp("^"+a+"$")},_extractParameters:function(a,b){return a.exec(b).slice(1)}});e.History=function(){this.handlers=[];f.bindAll(this,"checkUrl")};var j=/^#*/,t=/msie [\w.]+/,m=!1;f.extend(e.History.prototype,{interval:50,getFragment:function(a,b){if(a==null)if(this._hasPushState||b){a=window.location.pathname;var c=window.location.search;c&&(a+=c);a.indexOf(this.options.root)==0&&(a=a.substr(this.options.root.length))}else a=window.location.hash;return decodeURIComponent(a.replace(j,
+""))},start:function(a){if(m)throw Error("Backbone.history has already been started");this.options=f.extend({},{root:"/"},this.options,a);this._wantsPushState=!!this.options.pushState;this._hasPushState=!(!this.options.pushState||!window.history||!window.history.pushState);a=this.getFragment();var b=document.documentMode;if(b=t.exec(navigator.userAgent.toLowerCase())&&(!b||b<=7))this.iframe=g('<iframe src="javascript:0" tabindex="-1" />').hide().appendTo("body")[0].contentWindow,this.navigate(a);
+this._hasPushState?g(window).bind("popstate",this.checkUrl):"onhashchange"in window&&!b?g(window).bind("hashchange",this.checkUrl):setInterval(this.checkUrl,this.interval);this.fragment=a;m=!0;a=window.location;b=a.pathname==this.options.root;if(this._wantsPushState&&!this._hasPushState&&!b)return this.fragment=this.getFragment(null,!0),window.location.replace(this.options.root+"#"+this.fragment),!0;else if(this._wantsPushState&&this._hasPushState&&b&&a.hash)this.fragment=a.hash.replace(j,""),window.history.replaceState({},
+document.title,a.protocol+"//"+a.host+this.options.root+this.fragment);if(!this.options.silent)return this.loadUrl()},route:function(a,b){this.handlers.unshift({route:a,callback:b})},checkUrl:function(){var a=this.getFragment();a==this.fragment&&this.iframe&&(a=this.getFragment(this.iframe.location.hash));if(a==this.fragment||a==decodeURIComponent(this.fragment))return!1;this.iframe&&this.navigate(a);this.loadUrl()||this.loadUrl(window.location.hash)},loadUrl:function(a){var b=this.fragment=this.getFragment(a);
+return f.any(this.handlers,function(a){if(a.route.test(b))return a.callback(b),!0})},navigate:function(a,b){var c=(a||"").replace(j,"");if(!(this.fragment==c||this.fragment==decodeURIComponent(c))){if(this._hasPushState){var d=window.location;c.indexOf(this.options.root)!=0&&(c=this.options.root+c);this.fragment=c;window.history.pushState({},document.title,d.protocol+"//"+d.host+c)}else if(window.location.hash=this.fragment=c,this.iframe&&c!=this.getFragment(this.iframe.location.hash))this.iframe.document.open().close(),
+this.iframe.location.hash=c;b&&this.loadUrl(a)}}});e.View=function(a){this.cid=f.uniqueId("view");this._configure(a||{});this._ensureElement();this.delegateEvents();this.initialize.apply(this,arguments)};var u=/^(\S+)\s*(.*)$/,n=["model","collection","el","id","attributes","className","tagName"];f.extend(e.View.prototype,e.Events,{tagName:"div",$:function(a){return g(a,this.el)},initialize:function(){},render:function(){return this},remove:function(){g(this.el).remove();return this},make:function(a,
+b,c){a=document.createElement(a);b&&g(a).attr(b);c&&g(a).html(c);return a},delegateEvents:function(a){if(a||(a=this.events))for(var b in f.isFunction(a)&&(a=a.call(this)),g(this.el).unbind(".delegateEvents"+this.cid),a){var c=this[a[b]];if(!c)throw Error('Event "'+a[b]+'" does not exist');var d=b.match(u),e=d[1];d=d[2];c=f.bind(c,this);e+=".delegateEvents"+this.cid;d===""?g(this.el).bind(e,c):g(this.el).delegate(d,e,c)}},_configure:function(a){this.options&&(a=f.extend({},this.options,a));for(var b=
+0,c=n.length;b<c;b++){var d=n[b];a[d]&&(this[d]=a[d])}this.options=a},_ensureElement:function(){if(this.el){if(f.isString(this.el))this.el=g(this.el).get(0)}else{var a=this.attributes||{};if(this.id)a.id=this.id;if(this.className)a["class"]=this.className;this.el=this.make(this.tagName,a)}}});e.Model.extend=e.Collection.extend=e.Router.extend=e.View.extend=function(a,b){var c=v(this,a,b);c.extend=this.extend;return c};var w={create:"POST",update:"PUT","delete":"DELETE",read:"GET"};e.sync=function(a,
+b,c){var d=w[a];c=f.extend({type:d,dataType:"json"},c);if(!c.url)c.url=k(b)||l();if(!c.data&&b&&(a=="create"||a=="update"))c.contentType="application/json",c.data=JSON.stringify(b.toJSON());if(e.emulateJSON)c.contentType="application/x-www-form-urlencoded",c.data=c.data?{model:c.data}:{};if(e.emulateHTTP&&(d==="PUT"||d==="DELETE")){if(e.emulateJSON)c.data._method=d;c.type="POST";c.beforeSend=function(a){a.setRequestHeader("X-HTTP-Method-Override",d)}}if(c.type!=="GET"&&!e.emulateJSON)c.processData=
+!1;return g.ajax(c)};var o=function(){},v=function(a,b,c){var d;d=b&&b.hasOwnProperty("constructor")?b.constructor:function(){return a.apply(this,arguments)};f.extend(d,a);o.prototype=a.prototype;d.prototype=new o;b&&f.extend(d.prototype,b);c&&f.extend(d,c);d.prototype.constructor=d;d.__super__=a.prototype;return d},k=function(a){if(!a||!a.url)return null;return f.isFunction(a.url)?a.url():a.url},l=function(){throw Error('A "url" property or function must be specified');},i=function(a,b,c){return function(d){a?
+a(b,d,c):b.trigger("error",b,d,c)}}}).call(this);
View
0 WebContent/js/jquery-1.7.1.min.js → WebContent/lib/jquery-1.7.1.min.js
File renamed without changes.
View
31 WebContent/lib/underscore-min.js
@@ -0,0 +1,31 @@
+// Underscore.js 1.2.4
+// (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc.
+// Underscore is freely distributable under the MIT license.
+// Portions of Underscore are inspired or borrowed from Prototype,
+// Oliver Steele's Functional, and John Resig's Micro-Templating.
+// For all details and documentation:
+// http://documentcloud.github.com/underscore
+(function(){function r(a,c,d){if(a===c)return a!==0||1/a==1/c;if(a==null||c==null)return a===c;if(a._chain)a=a._wrapped;if(c._chain)c=c._wrapped;if(a.isEqual&&b.isFunction(a.isEqual))return a.isEqual(c);if(c.isEqual&&b.isFunction(c.isEqual))return c.isEqual(a);var e=l.call(a);if(e!=l.call(c))return false;switch(e){case "[object String]":return a==String(c);case "[object Number]":return a!=+a?c!=+c:a==0?1/a==1/c:a==+c;case "[object Date]":case "[object Boolean]":return+a==+c;case "[object RegExp]":return a.source==
+c.source&&a.global==c.global&&a.multiline==c.multiline&&a.ignoreCase==c.ignoreCase}if(typeof a!="object"||typeof c!="object")return false;for(var f=d.length;f--;)if(d[f]==a)return true;d.push(a);var f=0,g=true;if(e=="[object Array]"){if(f=a.length,g=f==c.length)for(;f--;)if(!(g=f in a==f in c&&r(a[f],c[f],d)))break}else{if("constructor"in a!="constructor"in c||a.constructor!=c.constructor)return false;for(var h in a)if(m.call(a,h)&&(f++,!(g=m.call(c,h)&&r(a[h],c[h],d))))break;if(g){for(h in c)if(m.call(c,
+h)&&!f--)break;g=!f}}d.pop();return g}var s=this,G=s._,o={},k=Array.prototype,p=Object.prototype,i=k.slice,H=k.unshift,l=p.toString,m=p.hasOwnProperty,w=k.forEach,x=k.map,y=k.reduce,z=k.reduceRight,A=k.filter,B=k.every,C=k.some,q=k.indexOf,D=k.lastIndexOf,p=Array.isArray,I=Object.keys,t=Function.prototype.bind,b=function(a){return new n(a)};if(typeof exports!=="undefined"){if(typeof module!=="undefined"&&module.exports)exports=module.exports=b;exports._=b}else typeof define==="function"&&define.amd?
+define("underscore",function(){return b}):s._=b;b.VERSION="1.2.4";var j=b.each=b.forEach=function(a,c,b){if(a!=null)if(w&&a.forEach===w)a.forEach(c,b);else if(a.length===+a.length)for(var e=0,f=a.length;e<f;e++){if(e in a&&c.call(b,a[e],e,a)===o)break}else for(e in a)if(m.call(a,e)&&c.call(b,a[e],e,a)===o)break};b.map=function(a,c,b){var e=[];if(a==null)return e;if(x&&a.map===x)return a.map(c,b);j(a,function(a,g,h){e[e.length]=c.call(b,a,g,h)});if(a.length===+a.length)e.length=a.length;return e};
+b.reduce=b.foldl=b.inject=function(a,c,d,e){var f=arguments.length>2;a==null&&(a=[]);if(y&&a.reduce===y)return e&&(c=b.bind(c,e)),f?a.reduce(c,d):a.reduce(c);j(a,function(a,b,i){f?d=c.call(e,d,a,b,i):(d=a,f=true)});if(!f)throw new TypeError("Reduce of empty array with no initial value");return d};b.reduceRight=b.foldr=function(a,c,d,e){var f=arguments.length>2;a==null&&(a=[]);if(z&&a.reduceRight===z)return e&&(c=b.bind(c,e)),f?a.reduceRight(c,d):a.reduceRight(c);var g=b.toArray(a).reverse();e&&!f&&
+(c=b.bind(c,e));return f?b.reduce(g,c,d,e):b.reduce(g,c)};b.find=b.detect=function(a,c,b){var e;E(a,function(a,g,h){if(c.call(b,a,g,h))return e=a,true});return e};b.filter=b.select=function(a,c,b){var e=[];if(a==null)return e;if(A&&a.filter===A)return a.filter(c,b);j(a,function(a,g,h){c.call(b,a,g,h)&&(e[e.length]=a)});return e};b.reject=function(a,c,b){var e=[];if(a==null)return e;j(a,function(a,g,h){c.call(b,a,g,h)||(e[e.length]=a)});return e};b.every=b.all=function(a,c,b){var e=true;if(a==null)return e;
+if(B&&a.every===B)return a.every(c,b);j(a,function(a,g,h){if(!(e=e&&c.call(b,a,g,h)))return o});return e};var E=b.some=b.any=function(a,c,d){c||(c=b.identity);var e=false;if(a==null)return e;if(C&&a.some===C)return a.some(c,d);j(a,function(a,b,h){if(e||(e=c.call(d,a,b,h)))return o});return!!e};b.include=b.contains=function(a,c){var b=false;if(a==null)return b;return q&&a.indexOf===q?a.indexOf(c)!=-1:b=E(a,function(a){return a===c})};b.invoke=function(a,c){var d=i.call(arguments,2);return b.map(a,
+function(a){return(b.isFunction(c)?c||a:a[c]).apply(a,d)})};b.pluck=function(a,c){return b.map(a,function(a){return a[c]})};b.max=function(a,c,d){if(!c&&b.isArray(a))return Math.max.apply(Math,a);if(!c&&b.isEmpty(a))return-Infinity;var e={computed:-Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;b>=e.computed&&(e={value:a,computed:b})});return e.value};b.min=function(a,c,d){if(!c&&b.isArray(a))return Math.min.apply(Math,a);if(!c&&b.isEmpty(a))return Infinity;var e={computed:Infinity};j(a,function(a,
+b,h){b=c?c.call(d,a,b,h):a;b<e.computed&&(e={value:a,computed:b})});return e.value};b.shuffle=function(a){var c=[],b;j(a,function(a,f){f==0?c[0]=a:(b=Math.floor(Math.random()*(f+1)),c[f]=c[b],c[b]=a)});return c};b.sortBy=function(a,c,d){return b.pluck(b.map(a,function(a,b,g){return{value:a,criteria:c.call(d,a,b,g)}}).sort(function(a,b){var c=a.criteria,d=b.criteria;return c<d?-1:c>d?1:0}),"value")};b.groupBy=function(a,c){var d={},e=b.isFunction(c)?c:function(a){return a[c]};j(a,function(a,b){var c=
+e(a,b);(d[c]||(d[c]=[])).push(a)});return d};b.sortedIndex=function(a,c,d){d||(d=b.identity);for(var e=0,f=a.length;e<f;){var g=e+f>>1;d(a[g])<d(c)?e=g+1:f=g}return e};b.toArray=function(a){return!a?[]:a.toArray?a.toArray():b.isArray(a)?i.call(a):b.isArguments(a)?i.call(a):b.values(a)};b.size=function(a){return b.toArray(a).length};b.first=b.head=function(a,b,d){return b!=null&&!d?i.call(a,0,b):a[0]};b.initial=function(a,b,d){return i.call(a,0,a.length-(b==null||d?1:b))};b.last=function(a,b,d){return b!=
+null&&!d?i.call(a,Math.max(a.length-b,0)):a[a.length-1]};b.rest=b.tail=function(a,b,d){return i.call(a,b==null||d?1:b)};b.compact=function(a){return b.filter(a,function(a){return!!a})};b.flatten=function(a,c){return b.reduce(a,function(a,e){if(b.isArray(e))return a.concat(c?e:b.flatten(e));a[a.length]=e;return a},[])};b.without=function(a){return b.difference(a,i.call(arguments,1))};b.uniq=b.unique=function(a,c,d){var d=d?b.map(a,d):a,e=[];b.reduce(d,function(d,g,h){if(0==h||(c===true?b.last(d)!=
+g:!b.include(d,g)))d[d.length]=g,e[e.length]=a[h];return d},[]);return e};b.union=function(){return b.uniq(b.flatten(arguments,true))};b.intersection=b.intersect=function(a){var c=i.call(arguments,1);return b.filter(b.uniq(a),function(a){return b.every(c,function(c){return b.indexOf(c,a)>=0})})};b.difference=function(a){var c=b.flatten(i.call(arguments,1));return b.filter(a,function(a){return!b.include(c,a)})};b.zip=function(){for(var a=i.call(arguments),c=b.max(b.pluck(a,"length")),d=Array(c),e=
+0;e<c;e++)d[e]=b.pluck(a,""+e);return d};b.indexOf=function(a,c,d){if(a==null)return-1;var e;if(d)return d=b.sortedIndex(a,c),a[d]===c?d:-1;if(q&&a.indexOf===q)return a.indexOf(c);for(d=0,e=a.length;d<e;d++)if(d in a&&a[d]===c)return d;return-1};b.lastIndexOf=function(a,b){if(a==null)return-1;if(D&&a.lastIndexOf===D)return a.lastIndexOf(b);for(var d=a.length;d--;)if(d in a&&a[d]===b)return d;return-1};b.range=function(a,b,d){arguments.length<=1&&(b=a||0,a=0);for(var d=arguments[2]||1,e=Math.max(Math.ceil((b-
+a)/d),0),f=0,g=Array(e);f<e;)g[f++]=a,a+=d;return g};var F=function(){};b.bind=function(a,c){var d,e;if(a.bind===t&&t)return t.apply(a,i.call(arguments,1));if(!b.isFunction(a))throw new TypeError;e=i.call(arguments,2);return d=function(){if(!(this instanceof d))return a.apply(c,e.concat(i.call(arguments)));F.prototype=a.prototype;var b=new F,g=a.apply(b,e.concat(i.call(arguments)));return Object(g)===g?g:b}};b.bindAll=function(a){var c=i.call(arguments,1);c.length==0&&(c=b.functions(a));j(c,function(c){a[c]=
+b.bind(a[c],a)});return a};b.memoize=function(a,c){var d={};c||(c=b.identity);return function(){var b=c.apply(this,arguments);return m.call(d,b)?d[b]:d[b]=a.apply(this,arguments)}};b.delay=function(a,b){var d=i.call(arguments,2);return setTimeout(function(){return a.apply(a,d)},b)};b.defer=function(a){return b.delay.apply(b,[a,1].concat(i.call(arguments,1)))};b.throttle=function(a,c){var d,e,f,g,h,i=b.debounce(function(){h=g=false},c);return function(){d=this;e=arguments;var b;f||(f=setTimeout(function(){f=
+null;h&&a.apply(d,e);i()},c));g?h=true:a.apply(d,e);i();g=true}};b.debounce=function(a,b){var d;return function(){var e=this,f=arguments;clearTimeout(d);d=setTimeout(function(){d=null;a.apply(e,f)},b)}};b.once=function(a){var b=false,d;return function(){if(b)return d;b=true;return d=a.apply(this,arguments)}};b.wrap=function(a,b){return function(){var d=[a].concat(i.call(arguments,0));return b.apply(this,d)}};b.compose=function(){var a=arguments;return function(){for(var b=arguments,d=a.length-1;d>=
+0;d--)b=[a[d].apply(this,b)];return b[0]}};b.after=function(a,b){return a<=0?b():function(){if(--a<1)return b.apply(this,arguments)}};b.keys=I||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var b=[],d;for(d in a)m.call(a,d)&&(b[b.length]=d);return b};b.values=function(a){return b.map(a,b.identity)};b.functions=b.methods=function(a){var c=[],d;for(d in a)b.isFunction(a[d])&&c.push(d);return c.sort()};b.extend=function(a){j(i.call(arguments,1),function(b){for(var d in b)b[d]!==
+void 0&&(a[d]=b[d])});return a};b.defaults=function(a){j(i.call(arguments,1),function(b){for(var d in b)a[d]==null&&(a[d]=b[d])});return a};b.clone=function(a){return!b.isObject(a)?a:b.isArray(a)?a.slice():b.extend({},a)};b.tap=function(a,b){b(a);return a};b.isEqual=function(a,b){return r(a,b,[])};b.isEmpty=function(a){if(b.isArray(a)||b.isString(a))return a.length===0;for(var c in a)if(m.call(a,c))return false;return true};b.isElement=function(a){return!!(a&&a.nodeType==1)};b.isArray=p||function(a){return l.call(a)==
+"[object Array]"};b.isObject=function(a){return a===Object(a)};b.isArguments=function(a){return l.call(a)=="[object Arguments]"};if(!b.isArguments(arguments))b.isArguments=function(a){return!(!a||!m.call(a,"callee"))};b.isFunction=function(a){return l.call(a)=="[object Function]"};b.isString=function(a){return l.call(a)=="[object String]"};b.isNumber=function(a){return l.call(a)=="[object Number]"};b.isNaN=function(a){return a!==a};b.isBoolean=function(a){return a===true||a===false||l.call(a)=="[object Boolean]"};
+b.isDate=function(a){return l.call(a)=="[object Date]"};b.isRegExp=function(a){return l.call(a)=="[object RegExp]"};b.isNull=function(a){return a===null};b.isUndefined=function(a){return a===void 0};b.noConflict=function(){s._=G;return this};b.identity=function(a){return a};b.times=function(a,b,d){for(var e=0;e<a;e++)b.call(d,e)};b.escape=function(a){return(""+a).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#x27;").replace(/\//g,"&#x2F;")};
+b.mixin=function(a){j(b.functions(a),function(c){J(c,b[c]=a[c])})};var K=0;b.uniqueId=function(a){var b=K++;return a?a+b:b};b.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var u=/.^/;b.template=function(a,c){var d=b.templateSettings,d="var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('"+a.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(d.escape||u,function(a,b){return"',_.escape("+b.replace(/\\'/g,"'")+"),'"}).replace(d.interpolate||
+u,function(a,b){return"',"+b.replace(/\\'/g,"'")+",'"}).replace(d.evaluate||u,function(a,b){return"');"+b.replace(/\\'/g,"'").replace(/[\r\n\t]/g," ").replace(/\\\\/g,"\\")+";__p.push('"}).replace(/\r/g,"\\r").replace(/\n/g,"\\n").replace(/\t/g,"\\t")+"');}return __p.join('');",e=new Function("obj","_",d);return c?e(c,b):function(a){return e.call(this,a,b)}};b.chain=function(a){return b(a).chain()};var n=function(a){this._wrapped=a};b.prototype=n.prototype;var v=function(a,c){return c?b(a).chain():
+a},J=function(a,c){n.prototype[a]=function(){var a=i.call(arguments);H.call(a,this._wrapped);return v(c.apply(b,a),this._chain)}};b.mixin(b);j("pop,push,reverse,shift,sort,splice,unshift".split(","),function(a){var b=k[a];n.prototype[a]=function(){var d=this._wrapped;b.apply(d,arguments);var e=d.length;(a=="shift"||a=="splice")&&e===0&&delete d[0];return v(d,this._chain)}});j(["concat","join","slice"],function(a){var b=k[a];n.prototype[a]=function(){return v(b.apply(this._wrapped,arguments),this._chain)}});
+n.prototype.chain=function(){this._chain=true;return this};n.prototype.value=function(){return this._wrapped}}).call(this);
View
1 WebContent/tpl/header.html
@@ -0,0 +1 @@
+<button class="new">New Wine</button>
View
28 WebContent/tpl/wine-details.html
@@ -0,0 +1,28 @@
+<div class="form-left-col">
+ <label>Id:</label>
+ <input id="wineId" name="id" type="text" value="<%= id %>" disabled />
+
+ <label>Name:</label>
+ <input type="text" id="name" name="name" value="<%= name %>" required/>
+
+ <label>Grapes:</label>
+ <input type="text" id="grapes" name="grapes" value="<%= grapes %>"/>
+
+ <label>Country:</label>
+ <input type="text" id="country" name="country" value="<%= country %>"/>
+
+ <label>Region:</label>
+ <input type="text" id="region" name="region" value="<%= region %>"/>
+
+ <label>Year:</label>
+ <input type="text" id="year" name="year" value="<%= year %>"/>
+
+ <button class="save">Save</button>
+ <button class="delete">Delete</button>
+</div>
+
+<div class="form-right-col">
+ <img height="300" src="pics/<%= picture %>"/>
+ <label>Notes:</label>
+ <textarea id="description" name="description"><%= description %></textarea>
+</div>
View
1 WebContent/tpl/wine-list-item.html
@@ -0,0 +1 @@
+<li><a href='#wines/<%= id %>'><%= name %></a></li>

0 comments on commit 667224f

Please sign in to comment.
Something went wrong with that request. Please try again.