From: Scott Baker Date: Sun, 13 Jul 2014 17:37:26 +0000 (-0700) Subject: refactor code organization X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;ds=sidebyside;h=62faabc4870dafc9c9c7c21a55bf48c76da517ee;p=plstackapi.git refactor code organization --- diff --git a/planetstack/core/xoslib/dashboards/gentle.html b/planetstack/core/xoslib/dashboards/gentle.html new file mode 100644 index 0000000..707f10e --- /dev/null +++ b/planetstack/core/xoslib/dashboards/gentle.html @@ -0,0 +1,25 @@ + + +
+

Here is static content in the web page. You'll notice that it gets replaced by our app as soon as we start it.

+
+ + + + + + + + + + + + diff --git a/planetstack/core/xoslib/dashboards/sliverListTest.html b/planetstack/core/xoslib/dashboards/sliverListTest.html index 61c54cf..255cbad 100644 --- a/planetstack/core/xoslib/dashboards/sliverListTest.html +++ b/planetstack/core/xoslib/dashboards/sliverListTest.html @@ -1,11 +1,11 @@ {% load mustache %} {% load straight_include %} - - - + + + - + - - - - + + + + + - +
diff --git a/planetstack/core/xoslib/dashboards/xsh.html b/planetstack/core/xoslib/dashboards/xsh.html index 6e5103a..65a44da 100644 --- a/planetstack/core/xoslib/dashboards/xsh.html +++ b/planetstack/core/xoslib/dashboards/xsh.html @@ -6,16 +6,16 @@
- - - - - - - - - - + + + + + + + + + + diff --git a/planetstack/core/xoslib/static/js/angrycats.js b/planetstack/core/xoslib/static/js/angrycats.js deleted file mode 100644 index a599a83..0000000 --- a/planetstack/core/xoslib/static/js/angrycats.js +++ /dev/null @@ -1,170 +0,0 @@ -MyApp = new Backbone.Marionette.Application(); - -MyApp.addRegions({ - mainRegion: "#content" -}); - -AngryCat = Backbone.Model.extend({ - defaults: { - votes: 0 - }, - - addVote: function(){ - this.set('votes', this.get('votes') + 1); - }, - - rankUp: function() { - this.set({rank: this.get('rank') - 1}); - }, - - rankDown: function() { - this.set({rank: this.get('rank') + 1}); - } -}); - -AngryCats = Backbone.Collection.extend({ - model: AngryCat, - - initialize: function(cats){ - var rank = 1; - _.each(cats, function(cat) { - cat.set('rank', rank); - ++rank; - }); - - this.on('add', function(cat){ - if( ! cat.get('rank') ){ - var error = Error("Cat must have a rank defined before being added to the collection"); - error.name = "NoRankError"; - throw error; - } - }); - - var self = this; - - MyApp.on("rank:up", function(cat){ - if (cat.get('rank') === 1) { - // can't increase rank of top-ranked cat - return true; - } - self.rankUp(cat); - self.sort(); - self.trigger("reset"); - }); - - MyApp.on("rank:down", function(cat){ - if (cat.get('rank') === self.size()) { - // can't decrease rank of lowest ranked cat - return true; - } - self.rankDown(cat); - self.sort(); - self.trigger("reset"); - }); - - MyApp.on("cat:disqualify", function(cat){ - var disqualifiedRank = cat.get('rank'); - var catsToUprank = self.filter( - function(cat){ return cat.get('rank') > disqualifiedRank; } - ); - catsToUprank.forEach(function(cat){ - cat.rankUp(); - }); - self.trigger('reset'); - }); - }, - - comparator: function(cat) { - return cat.get('rank'); - }, - - rankUp: function(cat) { - // find the cat we're going to swap ranks with - var rankToSwap = cat.get('rank') - 1; - var otherCat = this.at(rankToSwap - 1); - - // swap ranks - cat.rankUp(); - otherCat.rankDown(); - }, - - rankDown: function(cat) { - // find the cat we're going to swap ranks with - var rankToSwap = cat.get('rank') + 1; - var otherCat = this.at(rankToSwap - 1); - - // swap ranks - cat.rankDown(); - otherCat.rankUp(); - } -}); - -AngryCatView = Backbone.Marionette.ItemView.extend({ - template: "#angry_cat-template", - tagName: 'tr', - className: 'angry_cat', - - events: { - 'click .rank_up img': 'rankUp', - 'click .rank_down img': 'rankDown', - 'click a.disqualify': 'disqualify' - }, - - initialize: function(){ - this.listenTo(this.model, "change:votes", this.render); - }, - - rankUp: function(){ - this.model.addVote(); - MyApp.trigger("rank:up", this.model); - }, - - rankDown: function(){ - this.model.addVote(); - MyApp.trigger("rank:down", this.model); - }, - - disqualify: function(){ - MyApp.trigger("cat:disqualify", this.model); - this.model.destroy(); - } -}); - -AngryCatsView = Backbone.Marionette.CompositeView.extend({ - tagName: "table", - id: "angry_cats", - className: "table-striped table-bordered", - template: "#angry_cats-template", - itemView: AngryCatView, - - initialize: function(){ - this.listenTo(this.collection, "sort", this.renderCollection); - }, - - appendHtml: function(collectionView, itemView){ - collectionView.$("tbody").append(itemView.el); - } -}); - -MyApp.addInitializer(function(options){ - var angryCatsView = new AngryCatsView({ - collection: options.cats - }); - MyApp.mainRegion.show(angryCatsView); -}); - -$(document).ready(function(){ - var cats = new AngryCats([ - new AngryCat({ name: 'Wet Cat', image_path: 'assets/images/cat2.jpg' }), - new AngryCat({ name: 'Bitey Cat', image_path: 'assets/images/cat1.jpg' }), - new AngryCat({ name: 'Surprised Cat', image_path: 'assets/images/cat3.jpg' }) - ]); - - MyApp.start({cats: cats}); - - cats.add(new AngryCat({ - name: 'Cranky Cat', - image_path: 'assets/images/cat4.jpg', - rank: cats.size() + 1 - })); -}); diff --git a/planetstack/core/xoslib/static/js/gentle2.js b/planetstack/core/xoslib/static/js/gentle2.js deleted file mode 100644 index fde3daf..0000000 --- a/planetstack/core/xoslib/static/js/gentle2.js +++ /dev/null @@ -1,34 +0,0 @@ -DeveloperApp = new Marionette.Application(); - -DeveloperApp.addRegions({ - mainRegion: "#developerView" -}); - -DeveloperApp.SlioeDetailView = Marionette.ItemView.extend({ - template: "#developer-slicedetail-template", - tagName: 'tr', - className: 'developer_slicedetail' -}); - -DeveloperApp.ContactsView = Marionette.CollectionView.extend({ - tagName: "table", - childView: DeveloperApp.ContactItemView -}); - -DeveloperApp.on("start", function(){ - xos.slices.add( { - firstName: "Bob", - lastName: "Brigham", - phoneNumber: "555-0163" - }); - - var contactsView = new DeveloperApp.ContactsView({ - collection: xos.slices - }); - - DeveloperApp.mainRegion.show(contactsView); -}); - -$(document).ready(function(){ - DeveloperApp.start(); -}); diff --git a/planetstack/core/xoslib/static/js/ICanHaz.min.js b/planetstack/core/xoslib/static/js/vendor/ICanHaz.min.js similarity index 100% rename from planetstack/core/xoslib/static/js/ICanHaz.min.js rename to planetstack/core/xoslib/static/js/vendor/ICanHaz.min.js diff --git a/planetstack/core/xoslib/static/js/backbone-min.js b/planetstack/core/xoslib/static/js/vendor/backbone-min.js similarity index 100% rename from planetstack/core/xoslib/static/js/backbone-min.js rename to planetstack/core/xoslib/static/js/vendor/backbone-min.js diff --git a/planetstack/core/xoslib/static/js/backbone-tastypie.js b/planetstack/core/xoslib/static/js/vendor/backbone-tastypie.js similarity index 100% rename from planetstack/core/xoslib/static/js/backbone-tastypie.js rename to planetstack/core/xoslib/static/js/vendor/backbone-tastypie.js diff --git a/planetstack/core/xoslib/static/js/backbone.babysitter.js b/planetstack/core/xoslib/static/js/vendor/backbone.babysitter.js similarity index 100% rename from planetstack/core/xoslib/static/js/backbone.babysitter.js rename to planetstack/core/xoslib/static/js/vendor/backbone.babysitter.js diff --git a/planetstack/core/xoslib/static/js/backbone.js b/planetstack/core/xoslib/static/js/vendor/backbone.js similarity index 100% rename from planetstack/core/xoslib/static/js/backbone.js rename to planetstack/core/xoslib/static/js/vendor/backbone.js diff --git a/planetstack/core/xoslib/static/js/backbone.marionette.js b/planetstack/core/xoslib/static/js/vendor/backbone.marionette.js similarity index 100% rename from planetstack/core/xoslib/static/js/backbone.marionette.js rename to planetstack/core/xoslib/static/js/vendor/backbone.marionette.js diff --git a/planetstack/core/xoslib/static/js/backbone.marionette.min.js b/planetstack/core/xoslib/static/js/vendor/backbone.marionette.min.js similarity index 100% rename from planetstack/core/xoslib/static/js/backbone.marionette.min.js rename to planetstack/core/xoslib/static/js/vendor/backbone.marionette.min.js diff --git a/planetstack/core/xoslib/static/js/backbone.wreqr.js b/planetstack/core/xoslib/static/js/vendor/backbone.wreqr.js similarity index 100% rename from planetstack/core/xoslib/static/js/backbone.wreqr.js rename to planetstack/core/xoslib/static/js/vendor/backbone.wreqr.js diff --git a/planetstack/core/xoslib/static/js/underscore-min.js b/planetstack/core/xoslib/static/js/vendor/underscore-min.js similarity index 100% rename from planetstack/core/xoslib/static/js/underscore-min.js rename to planetstack/core/xoslib/static/js/vendor/underscore-min.js diff --git a/planetstack/core/xoslib/static/js/xos-backbone.js b/planetstack/core/xoslib/static/js/xoslib/xos-backbone.js similarity index 100% rename from planetstack/core/xoslib/static/js/xos-backbone.js rename to planetstack/core/xoslib/static/js/xoslib/xos-backbone.js diff --git a/planetstack/core/xoslib/static/xsh/constants.js b/planetstack/core/xoslib/static/js/xsh/constants.js similarity index 100% rename from planetstack/core/xoslib/static/xsh/constants.js rename to planetstack/core/xoslib/static/js/xsh/constants.js diff --git a/planetstack/core/xoslib/static/xsh/object_id.js b/planetstack/core/xoslib/static/js/xsh/object_id.js similarity index 100% rename from planetstack/core/xoslib/static/xsh/object_id.js rename to planetstack/core/xoslib/static/js/xsh/object_id.js diff --git a/planetstack/core/xoslib/static/xsh/shell_utils.js b/planetstack/core/xoslib/static/js/xsh/shell_utils.js similarity index 100% rename from planetstack/core/xoslib/static/xsh/shell_utils.js rename to planetstack/core/xoslib/static/js/xsh/shell_utils.js diff --git a/planetstack/core/xoslib/static/xsh/tokens.js b/planetstack/core/xoslib/static/js/xsh/tokens.js similarity index 100% rename from planetstack/core/xoslib/static/xsh/tokens.js rename to planetstack/core/xoslib/static/js/xsh/tokens.js diff --git a/planetstack/core/xoslib/static/xsh/utils.js b/planetstack/core/xoslib/static/js/xsh/utils.js similarity index 100% rename from planetstack/core/xoslib/static/xsh/utils.js rename to planetstack/core/xoslib/static/js/xsh/utils.js diff --git a/planetstack/core/xoslib/static/xsh/xsh.js b/planetstack/core/xoslib/static/js/xsh/xsh.js similarity index 100% rename from planetstack/core/xoslib/static/xsh/xsh.js rename to planetstack/core/xoslib/static/js/xsh/xsh.js