X-Git-Url: http://mmka.chem.univ.gda.pl/gitweb/?a=blobdiff_plain;f=filex%2Fstatic%2Ffilex%2Ffilex.js;h=ac71ea549224049788ed7575b13ea3ab48430b88;hb=5e547a8cc20ef2bd450b3b839564e56e99099cee;hp=396064ef1d194ce0b511a7810fd6946f6e5c0264;hpb=f317cc676041b8b1358f3fee73ee2d703963f0c6;p=qcg-portal.git diff --git a/filex/static/filex/filex.js b/filex/static/filex/filex.js index 396064e..ac71ea5 100644 --- a/filex/static/filex/filex.js +++ b/filex/static/filex/filex.js @@ -107,7 +107,7 @@ $(function(){ }, full: function() { - return this.pluck('path').join('/') || '/'; + return this.pluck('name').join('/').replace(/^\/+/, '/'); } }); @@ -126,7 +126,7 @@ $(function(){ initialize: function(options) { this.view = options.view; - this.listenTo(this.model, 'change', this.render); + this.listenTo(this.model, 'change:checked', this.toggleChecked); this.listenTo(this.model, 'remove', this.remove); this.listenTo(this.model, 'hidden', this.toggleHidden); }, @@ -141,8 +141,7 @@ $(function(){ var data = this.model.toJSON(); data['url_params'] = $.param({ host: this.view.host, - path: this.view.path.full(), - name: this.model.get('name') + path: this.view.path.full() + '/' + this.model.get('name') }); data['cid'] = this.model.cid; @@ -153,7 +152,16 @@ $(function(){ }, toggleHidden: function() { - this.$el.toggleClass('hidden', this.model.isHidden() && !this.view.showHidden()); + var isHidden = this.model.isHidden() && !this.view.showHidden(); + this.$el.toggleClass('hidden', isHidden); + + if (isHidden && this.model.get('checked')) + this.model.toggle(); + }, + + toggleChecked: function(obj, value) { + this.$el.toggleClass('active', value); + this.$el.find('input[type="checkbox"]').prop('checked', value); }, click: function(e) { @@ -184,12 +192,12 @@ $(function(){ render: function() { if (this.model.get('active')) { - this.$el.text(this.model.get('text')); + this.$el.text(this.model.get('name')); } else { this.$el.html($('', { href: '#', - text: this.model.get('text') + text: this.model.get('name') })); } this.$el.toggleClass('active', this.model.get('active')); @@ -253,20 +261,24 @@ $(function(){ lockOptgroupOrder: true, create: function(input, callback) { var $form = $('#favorite-form'), - parts = input.split('/', 1), + parts = input.split('/'), callback_called = false; - $form.find('#id_host').val(parts[0]); + $form[0].reset(); + $form.find('.alert-danger').remove(); + $form.find('#id_host').val(parts.shift()); - if (parts.length > 1) - $form.find('#id_path').val(parts[1]); + if (parts.length) + $form.find('#id_path').val(parts.join('/')); + $form.off(); $form.on('submit', function(e) { var $this = $(this), $btn = $this.find('[type="submit"]'); e.preventDefault(); $btn.button('loading'); + $this.find('.alert-danger').remove(); $.post($this.attr('action'), $this.serialize(), function(data) { callback(data); @@ -274,9 +286,27 @@ $(function(){ $this.modal('hide'); $btn.button('reset'); - }, 'json').fail(function() { + }, 'json').fail(function(xhr) { console.error(arguments); - $btn.button('error'); + var error = (xhr.responseJSON || {}).error || undefined; + + if (error.__all__) { + error = 'Podana lokalizacja jest już zapisana' + } + else if (xhr.status == 400) { + error = 'Niepoprawna nazwa hosta lub Åcieżka' + } + + if (typeof error === 'string') { + $('