Skip to content

Instantly share code, notes, and snippets.

@brjadams
Created October 28, 2015 14:43
Show Gist options
  • Save brjadams/aa18f9da912341ea115f to your computer and use it in GitHub Desktop.
Save brjadams/aa18f9da912341ea115f to your computer and use it in GitHub Desktop.
I have a form in new_video that upon submitting, I want it to add the video to the videocollection, and update just that section(region?) of the page.
function($, _, Backbone, app, global_bindings, VideoModel, VideosCollection, VideoCollectionView, VideoForm) {
"use strict";
var data_items = app.setting("bootstrapped_videos");
var video_collection_items = new VideosCollection();
video_collection_items.reset(data_items);
var video_collection_view = new VideoCollectionView({
collection: video_collection_items
});
var video_region = new Backbone.Marionette.Region({
el: "#videos_container"
});
video_region.show(video_collection_view);
//var video_model = new VideoModel();
var video_form = new VideoForm({
el: "#generic_upload"
});
video_form.render();
});
function($, _, Backbone, Marionette, rivets, app, dateutils, Video,
VideosCollection, VideosCollectionView, tmpl) {
var VideoForm = Marionette.Layout.extend({
template: tmpl,
regions: {
videos_region: "#generic_upload"
},
events: {
},
modelEvents: {
},
onRender: function() {
var self = this;
var path = window.location.pathname.split("/");
path = path.slice(1, path.length - 1);
this.$el.find("input[name='v_session']").val(path[3]);
this.$el.find("select[name='v_category']").val(path[2]).prop("disabled", "disabled");
this.$el.find("select[name='v_chamber']").val(path[0]).prop("disabled", "disabled");
this.$el.find(".date_input").datepicker();
this.$el.find("#fileupload").fileupload({
url: app.setting("video_file_api"),
dataType: "json",
formData: function(form) {
data = form.serializeArray();
console.log("date: ", data);
return data;
},
done: function(e, data) {
// self.$el.find(".fileupload_container").html($('<h2/>').text(data.result.name + " added successfully"));
self.$el.find("[name='v_name']").val("");
var video = new Video(data.result);
video_collection.add(video);
},
always: function(e, data) {
console.log("this always gets called");
self.$el.find(".fileupload_progress .bar").css("width", "0%");
},
progressall: function(e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
self.$el.find(".fileupload_progress .bar").css(
"width",
progress + "%"
);
}
});
}
});
return VideoForm;
});
function($, _, Backbone, Marionette, app, VideoView, video_collection_tmpl) {
var VideoCollectionView = Marionette.CompositeView.extend({
template: video_collection_tmpl,
itemViewContainer: "tbody",
itemView: VideoView
});
return VideoCollectionView;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment