From 47dfdee1afa4549901c01b4fbbdb765f5740dfda Mon Sep 17 00:00:00 2001 From: Zachary Jones Date: Tue, 29 Jan 2013 16:03:23 -0600 Subject: [PATCH] Add time to Add Asset form. The start and end date/time of the Asset is now saved to the database. --- server.py | 14 ++++++++++++-- static/coffee/screenly-ose.coffee | 31 +++++++++++++++++++++++++++++-- static/js/screenly-ose.js | 2 +- views/index.haml | 13 ++++++++++--- 4 files changed, 52 insertions(+), 8 deletions(-) diff --git a/server.py b/server.py index adb75ae4..60b2a8c1 100644 --- a/server.py +++ b/server.py @@ -223,8 +223,18 @@ def prepare_asset(request): if "video" in asset['mimetype']: asset['duration'] = "N/A" - asset['start_date'] = "" - asset['end_date'] = "" + if get('duration'): + asset['duration'] = get('duration') + + if get('start_date'): + asset['start_date'] = datetime.strptime(get('start_date'), '%m/%d/%Y %H:%M') + else: + asset['start_date'] = "" + + if get('end_date'): + asset['end_date'] = datetime.strptime(get('end_date'), '%m/%d/%Y %H:%M') + else: + asset['end_date'] = "" return asset else: diff --git a/static/coffee/screenly-ose.coffee b/static/coffee/screenly-ose.coffee index 1cc6b7b2..e1648a9a 100644 --- a/static/coffee/screenly-ose.coffee +++ b/static/coffee/screenly-ose.coffee @@ -55,15 +55,42 @@ screenly.InactiveAssets = new InactiveAssets() ################################ class AddAssetModalView extends Backbone.View + + events: + 'click #add-button': 'addButtonWasClicked' + initialize: (options) -> @template = _.template($('#add-asset-modal-template').html()) render: -> $(@el).html(@template()) - # setTimeout (=> @$(".date").datepicker()), 1000 - @$("input.date").datepicker() + + @$("input.date").datepicker({autoclose: true}) + @$("input.date").datepicker('setValue', new Date()) + + @$('input.time').timepicker({ + minuteStep: 5, + showInputs: false, + disableFocus: true, + defaultTime: 'current', + showMeridian: false + }) + @ + addButtonWasClicked: (event) -> + event.preventDefault() + console.log "You tried to add Asset" + + start_date = $("input[name='start_date_date']").val() + " " + $("input[name='start_date_time']").val() + end_date = $("input[name='end_date_date']").val() + " " + $("input[name='end_date_time']").val() + $("input[name='start_date']").val(start_date) + $("input[name='end_date']").val(end_date) + + @$("form").submit() + + + screenly.views.AddAssetModalView = AddAssetModalView class EditAssetModalView extends Backbone.View diff --git a/static/js/screenly-ose.js b/static/js/screenly-ose.js index 631ca931..8356ba18 100644 --- a/static/js/screenly-ose.js +++ b/static/js/screenly-ose.js @@ -1,2 +1,2 @@ // Generated by CoffeeScript 1.4.0 -(function(){var e,t,n,r,i,s,o,u,a,f,l,c,h,p={}.hasOwnProperty,d=function(e,t){function r(){this.constructor=e}for(var n in t)p.call(t,n)&&(e[n]=t[n]);r.prototype=t.prototype;e.prototype=new r;e.__super__=t.prototype;return e},v=[].indexOf||function(e){for(var t=0,n=this.length;t=0)&&console.log("You need to specify the template name for this AssetsView.");(n=!1,v.call(e,n)>=0)&&console.log("You must specify the child view class for this AssetsView.");this.template=_.template($("#"+e.templateName).html());this.collection.bind("reset",this.render,this);this.collection.bind("remove",this.render,this);return this.collection.bind("add",this.render,this)};t.prototype.render=function(){var e=this;$(this.el).html(this.template());this.$("tbody").empty();this.collection.each(function(t){return e.$("tbody").append((new e.options.childViewClass({model:t})).render().el)});return this};return t}(Backbone.View);e=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}d(t,e);t.prototype.initialize=function(e){return this.template=_.template($("#active-asset-row-template").html())};t.prototype.events={"click #deactivate":"deactivateAsset"};t.prototype.tagName="tr";t.prototype.render=function(){$(this.el).html(this.template(this.model.toJSON()));return this};t.prototype.deactivateAsset=function(e){e.preventDefault();screenly.ActiveAssets.remove(this.model);return screenly.InactiveAssets.add(this.model)};return t}(Backbone.View);u=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}d(t,e);t.prototype.initialize=function(e){return this.template=_.template($("#inactive-asset-row-template").html())};t.prototype.events={"click #activate":"activateAsset"};t.prototype.tagName="tr";t.prototype.render=function(){$(this.el).html(this.template(this.model.toJSON()));return this};t.prototype.activateAsset=function(e){e.preventDefault();screenly.InactiveAssets.remove(this.model);return screenly.ActiveAssets.add(this.model)};return t}(Backbone.View);screenly.views.AssetsView=s;screenly.views.ActiveAssetRowView=e;jQuery(function(){var t,r;screenly.Assets.fetch();t=new s({collection:screenly.ActiveAssets,templateName:"active-assets-template",childViewClass:e});r=new s({collection:screenly.InactiveAssets,templateName:"inactive-assets-template",childViewClass:u});$("#active-assets-container").append(t.render().el);$("#inactive-assets-container").append(r.render().el);return $("#add-asset-button").click(function(e){var t;e.preventDefault();t=new n;$("body").append(t.render().el);return $(t.el).children(":first").modal()})})}).call(this); \ No newline at end of file +(function(){var e,t,n,r,i,s,o,u,a,f,l,c,h,p={}.hasOwnProperty,d=function(e,t){function r(){this.constructor=e}for(var n in t)p.call(t,n)&&(e[n]=t[n]);r.prototype=t.prototype;e.prototype=new r;e.__super__=t.prototype;return e},v=[].indexOf||function(e){for(var t=0,n=this.length;t=0)&&console.log("You need to specify the template name for this AssetsView.");(n=!1,v.call(e,n)>=0)&&console.log("You must specify the child view class for this AssetsView.");this.template=_.template($("#"+e.templateName).html());this.collection.bind("reset",this.render,this);this.collection.bind("remove",this.render,this);return this.collection.bind("add",this.render,this)};t.prototype.render=function(){var e=this;$(this.el).html(this.template());this.$("tbody").empty();this.collection.each(function(t){return e.$("tbody").append((new e.options.childViewClass({model:t})).render().el)});return this};return t}(Backbone.View);e=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}d(t,e);t.prototype.initialize=function(e){return this.template=_.template($("#active-asset-row-template").html())};t.prototype.events={"click #deactivate":"deactivateAsset"};t.prototype.tagName="tr";t.prototype.render=function(){$(this.el).html(this.template(this.model.toJSON()));return this};t.prototype.deactivateAsset=function(e){e.preventDefault();screenly.ActiveAssets.remove(this.model);return screenly.InactiveAssets.add(this.model)};return t}(Backbone.View);u=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}d(t,e);t.prototype.initialize=function(e){return this.template=_.template($("#inactive-asset-row-template").html())};t.prototype.events={"click #activate":"activateAsset"};t.prototype.tagName="tr";t.prototype.render=function(){$(this.el).html(this.template(this.model.toJSON()));return this};t.prototype.activateAsset=function(e){e.preventDefault();screenly.InactiveAssets.remove(this.model);return screenly.ActiveAssets.add(this.model)};return t}(Backbone.View);screenly.views.AssetsView=s;screenly.views.ActiveAssetRowView=e;jQuery(function(){var t,r;screenly.Assets.fetch();t=new s({collection:screenly.ActiveAssets,templateName:"active-assets-template",childViewClass:e});r=new s({collection:screenly.InactiveAssets,templateName:"inactive-assets-template",childViewClass:u});$("#active-assets-container").append(t.render().el);$("#inactive-assets-container").append(r.render().el);return $("#add-asset-button").click(function(e){var t;e.preventDefault();t=new n;$("body").append(t.render().el);return $(t.el).children(":first").modal()})})}).call(this); \ No newline at end of file diff --git a/views/index.haml b/views/index.haml index b564b1f2..0b6e01be 100644 --- a/views/index.haml +++ b/views/index.haml @@ -8,6 +8,7 @@ %link(href="/static/css/bootstrap.css", rel="stylesheet") %link(href="/static/css/screenly.css", rel="stylesheet") %link(href="/static/css/datepicker.css", rel="stylesheet") + %link(href="/static/css/timepicker.css", rel="stylesheet") %script(src="/static/js/jquery-1.8.0.min.js") / %script(src="/static/js/bootstrap-dropdown.js") @@ -16,6 +17,7 @@ %script(src="/static/js/bootstrap-transition.js") %script(src="/static/js/bootstrap-modal.js") %script(src="/static/js/bootstrap-datepicker.js") + %script(src="/static/js/bootstrap-timepicker.js") %script(src="/static/js/screenly-ose.js") %script(type="text/template", id="active-assets-template") @@ -64,7 +66,7 @@ %script(type="text/template", id="add-asset-modal-template") .modal.hide.fade(tabindex="-1", role="dialog", ariaLabelledby="myModalLabel", ariaHidden="true") - %form.form-horizontal(method="POST", action="/api/assets") + %form.form-horizontal#add-form(method="POST", action="/api/assets") .modal-header %button.close(type="button", dataDismiss="modal", ariaHidden="true") x %h3#myModalLabel Add Asset @@ -99,19 +101,24 @@ %label.control-label Start Date .controls %input.span2.date(type="text", name="start_date_date") + %input.span2.time(type="text", name="start_date_time") + %input(type="hidden", name="start_date") .control-group %label.control-label End Date .controls %input.span2.date(type="text", name="end_date_date") + %input.span2.time(type="text", name="end_date_time") + %input(type="hidden", name="end_date") .control-group %label.control-label Duration .controls - %input.span5(type="text", name="duration", placeholder="Duration in seconds") + %input.span1(type="text", name="duration") + seconds .modal-footer %a.btn(href="#", dataDismiss="modal") Close - %input.btn.btn-primary(type="submit", value="Add Asset") + %input.btn.btn-primary#add-button(type="button", value="Add Asset")