From 3a6d5f33e100d7f9a4248603fd22eaeb6f8dfd75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rton=20Boros?= Date: Tue, 12 Feb 2013 20:36:19 +0100 Subject: [PATCH] show file upload button only when relevant --- static/coffee/screenly-ose.coffee | 24 ++++++++++++++-------- static/js/screenly-ose.js | 34 ++++++++++++++++++------------- views/index.haml | 4 ++-- 3 files changed, 37 insertions(+), 25 deletions(-) diff --git a/static/coffee/screenly-ose.coffee b/static/coffee/screenly-ose.coffee index c490376a..079baa72 100644 --- a/static/coffee/screenly-ose.coffee +++ b/static/coffee/screenly-ose.coffee @@ -14,7 +14,6 @@ year2ts = (years) -> (years * 365 * 24 * 60 * 60000) years_from_now = (years) -> D (year2ts years) + d2ts now() _tpl = (name) -> _.template ($ "##{name}-template").html() -_pd = (e) -> e.preventDefault(); false # Models @@ -67,9 +66,12 @@ class AssetModalView extends Backbone.View else (@$ "input.date").datepicker 'update', new Date() + @changeMimetype() this - events: {'click #submit-button': 'submit'} + events: + 'click #submit-button': 'submit' + 'change select[name=mimetype]': 'changeMimetype' submit: (e) => for which in ['start', 'end'] @@ -77,6 +79,11 @@ class AssetModalView extends Backbone.View d2iso (@$fv "#{which}_date_date") + " " + (@$fv "#{which}_date_time") (@$ "form").submit() + changeMimetype: => + console.log 'chaneg' + (@$ '.file_upload').toggle ((@$fv 'mimetype') != 'webpage') + + class AssetRowView extends Backbone.View tagName: "tr" @@ -97,7 +104,6 @@ class AssetRowView extends Backbone.View 'click #confirm-delete': 'delete' toggleActive: (e) => - console.log 'toggleactive', e if @model.get 'is_active' @model.set is_active: no @@ -110,16 +116,17 @@ class AssetRowView extends Backbone.View @model.save() (@$ ".toggle input").prop "checked", @model.get 'is_active' setTimeout (=> @remove()), 300 - _pd e + e.preventDefault(); false edit: (e) => new AssetModalView model: @model - _pd e + e.preventDefault(); false delete: (e) => (@$ "#delete-asset-button").popover 'hide' @model.destroy().done => @remove() - _pd e + e.preventDefault(); false + class AssetsView extends Backbone.View initialize: (options) => @@ -127,10 +134,9 @@ class AssetsView extends Backbone.View @collection.bind event, @render @collection.bind 'change', (model) => - setTimeout (=> @render _ [model]), 300 + setTimeout (=> @render _ [model]), 320 render: (models = @collection) => - console.log models models.each (model) => which = if model.get 'is_active' then 'active' else 'inactive' (@$ "##{which}-assets").append (new AssetRowView model: model).render().el @@ -151,7 +157,7 @@ API.app = class App extends Backbone.View add: (e) => new AssetModalView() - _pd e + e.preventDefault(); false jQuery -> new App el: $ 'body' diff --git a/static/js/screenly-ose.js b/static/js/screenly-ose.js index 2786424e..7f18fa30 100644 --- a/static/js/screenly-ose.js +++ b/static/js/screenly-ose.js @@ -5,7 +5,7 @@ (function() { - var API, App, Asset, AssetModalView, AssetRowView, Assets, AssetsView, D, d2iso, d2s, d2time, d2ts, now, year2ts, years_from_now, _pd, _tpl, + var API, App, Asset, AssetModalView, AssetRowView, Assets, AssetsView, D, d2iso, d2s, d2time, d2ts, now, year2ts, years_from_now, _tpl, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, @@ -49,11 +49,6 @@ return _.template(($("#" + name + "-template")).html()); }; - _pd = function(e) { - e.preventDefault(); - return false; - }; - Backbone.emulateJSON = true; Asset = (function(_super) { @@ -91,6 +86,8 @@ __extends(AssetModalView, _super); function AssetModalView() { + this.changeMimetype = __bind(this.changeMimetype, this); + this.submit = __bind(this.submit, this); this.render = __bind(this.render, this); @@ -149,11 +146,13 @@ } else { (this.$("input.date")).datepicker('update', new Date()); } + this.changeMimetype(); return this; }; AssetModalView.prototype.events = { - 'click #submit-button': 'submit' + 'click #submit-button': 'submit', + 'change select[name=mimetype]': 'changeMimetype' }; AssetModalView.prototype.submit = function(e) { @@ -166,6 +165,11 @@ return (this.$("form")).submit(); }; + AssetModalView.prototype.changeMimetype = function() { + console.log('chaneg'); + return (this.$('.file_upload')).toggle((this.$fv('mimetype')) !== 'webpage'); + }; + return AssetModalView; })(Backbone.View); @@ -213,7 +217,6 @@ AssetRowView.prototype.toggleActive = function(e) { var _this = this; - console.log('toggleactive', e); if (this.model.get('is_active')) { this.model.set({ is_active: false, @@ -231,14 +234,16 @@ setTimeout((function() { return _this.remove(); }), 300); - return _pd(e); + e.preventDefault(); + return false; }; AssetRowView.prototype.edit = function(e) { new AssetModalView({ model: this.model }); - return _pd(e); + e.preventDefault(); + return false; }; AssetRowView.prototype["delete"] = function(e) { @@ -247,7 +252,8 @@ this.model.destroy().done(function() { return _this.remove(); }); - return _pd(e); + e.preventDefault(); + return false; }; return AssetRowView; @@ -276,7 +282,7 @@ return this.collection.bind('change', function(model) { return setTimeout((function() { return _this.render(_([model])); - }), 300); + }), 320); }); }; @@ -285,7 +291,6 @@ if (models == null) { models = this.collection; } - console.log(models); models.each(function(model) { var which; which = model.get('is_active') ? 'active' : 'inactive'; @@ -326,7 +331,8 @@ App.prototype.add = function(e) { new AssetModalView(); - return _pd(e); + e.preventDefault(); + return false; }; return App; diff --git a/views/index.haml b/views/index.haml index 8ae4b138..a9d96a7b 100644 --- a/views/index.haml +++ b/views/index.haml @@ -74,9 +74,9 @@ %label.control-label Asset URL .controls %input.span5(type="text", name="uri", placeholder="Public URL to this asset's location") - %div(style="line-height: 27px; font-weight: bold; color: #888") + .file_upload(style="line-height: 27px; font-weight: bold; color: #888") — or — - .control-group + .control-group.file_upload %label.control-label Upload Asset .controls %input(type="file", name="file_upload")