X-Git-Url: http://mmka.chem.univ.gda.pl/gitweb/?a=blobdiff_plain;f=filex%2Fstatic%2Ffilex%2Ffilex.js;h=9f34b5ede6deeaab84120142fbd4005efcbea1d5;hb=bc6c1b10265d2c52e9f592cafacf0ae54fa033b0;hp=26bec82553fd4182fe75b679f377482818201fb2;hpb=0be92069d46130aad675fa715184e9c209140ce9;p=qcg-portal.git diff --git a/filex/static/filex/filex.js b/filex/static/filex/filex.js index 26bec82..9f34b5e 100644 --- a/filex/static/filex/filex.js +++ b/filex/static/filex/filex.js @@ -94,25 +94,28 @@ $(function(){ Filex.Path = Backbone.Collection.extend({ model: Filex.PathBit, - initialize: function() { - this.listenTo(this, 'reset add', this.setActive); - }, - - setActive: function() { - _.each(this.initial(), function(bit) { - bit.set('active', false); - }); - - this.last().set('active', true); - }, - full: function() { return this.pluck('name').join('/').replace(/^\/+/, '/'); + }, + + append: function(name) { + return this.pluck('name').concat(name).join('/').replace(/^\/+/, '/'); } }); // ------------------------------------------------------------------------ + // Routers + // ------------------------------------------------------------------------ + + Filex.Router = Backbone.Router.extend({ + routes: { + '*url': 'load' + } + }); + + + // ------------------------------------------------------------------------ // Views // ------------------------------------------------------------------------ @@ -139,10 +142,16 @@ $(function(){ render: function() { var data = this.model.toJSON(); - data['url_params'] = $.param({ - host: this.view.host, - path: this.view.path.full() + '/' + this.model.get('name') - }); + + if (this.model.isDir()) { + data['url'] = this.view.host + '/' + this.view.path.append(this.model.get('name')) + } + else { + data['params'] = $.param({ + host: this.view.host, + path: this.view.path.append(this.model.get('name')) + }); + } data['cid'] = this.model.cid; this.$el.html(this.template()(data)); @@ -165,26 +174,14 @@ $(function(){ }, click: function(e) { - if (e.target.className == 'link') { - if (this.model.isDir()) { - e.preventDefault(); - this.model.trigger('selected:dir', this.model); - } - - return; - } - - this.model.toggle(); + if (e.target.className != 'link') + this.model.toggle(); } }); Filex.Breadcrumb = Backbone.View.extend({ tagName: 'li', - events: { - 'click a': 'selected' - }, - initialize: function() { this.listenTo(this.model, 'change:active', this.render); this.listenTo(this.model, 'remove', this.remove); @@ -192,22 +189,17 @@ $(function(){ render: function() { if (this.model.get('active')) { + this.$el.addClass('active'); this.$el.text(this.model.get('name')); } else { this.$el.html($('', { - href: '#', + href: '#' + this.model.get('url'), text: this.model.get('name') })); } - this.$el.toggleClass('active', this.model.get('active')); return this; - }, - - selected: function(e) { - e.preventDefault(); - this.model.trigger('selected', this.model); } }); @@ -232,18 +224,17 @@ $(function(){ this.path = new Filex.Path(); this.files = new Filex.FileList(); + this.router = new Filex.Router(); - this.listenTo(this.path, 'reset', this.resetPath); this.listenTo(this.path, 'add', this.addPath); - this.listenTo(this.path, 'add reset', this.changedPath); - this.listenTo(this.path, 'selected', this.selectedPath); + this.listenTo(this.path, 'reset', this.resetPath); this.listenTo(this.files, 'reset', this.resetFiles); - this.listenTo(this.files, 'selected:dir', this.selectedDir); this.listenTo(this.files, 'change:checked', this.updateSelectAll); + this.listenTo(this.router, 'route:load', this.load); // used in selectize callbacks var view = this, - optionTemplate = _.template('