Skip to content

Instantly share code, notes, and snippets.

@svvitale
Created April 16, 2014 03:17
Show Gist options
  • Save svvitale/5462fa15dacb043db43f to your computer and use it in GitHub Desktop.
Save svvitale/5462fa15dacb043db43f to your computer and use it in GitHub Desktop.
Backbone View implementing "Engage" console for Spigot Labs
define([
'jquery',
'jqueryui',
'jquery_cookie',
'underscore',
'backbone',
'app/views/tapEngage.view',
// Using the Require.js text! plugin, we are loaded raw text
// which will be used as our views primary template
'text!app/views/engage.html',
], function($, jqueryUI, jqueryCookie, _, Backbone, TapView, HtmlTemplate){
return Backbone.View.extend({
el: $('.contentBlock'),
template: _.template( HtmlTemplate ),
initialize: function() {
var that = this;
this._tapViews = [];
// Load up all the tap views for the current company
this.collection.each(function(tapModel) {
that._company = tapModel.get("name");
that._tapViews.push(new TapView({
model : tapModel.get("event"),
}));
});
},
render: function() {
var that = this;
// Render our template
this.$el.html( this.template( _.extend( this.options, {companyName: this._company } ) ) );
// Add a helpful message to the accordion if we don't have any events to show.
if (this._tapViews.length == 0) {
$(".accordion", this.$el).append("No events found.");
return;
}
// Render each sub-view and append it to our the parent view's element.
_(this._tapViews).each(function(view, viewIdx) {
view.render($(".accordion:eq(" + viewIdx + ")", that.$el));
});
// Fire up the accordions
$( ".accordion" ).accordion({
//active: 0,
collapsible: true,
heightStyle: "content",
});
// Prevent keyboard interaction with the accordion
$(".accordion h3 .edit").on('keydown', function (e) {
e.stopPropagation();
});
$(".accordion h3 .edit_date").on('keydown', function (e) {
e.stopPropagation();
});
// Show the welcome message
if ( ! $.cookie("spigot_engage") ) {
// show the welcome message
$(".welcome").show();
}
// Handle hiding the welcome message permanently.
$(".welcome a").click(function(e) {
e.preventDefault();
$(".welcome").hide();
$.cookie("spigot_engage", 1);
});
},
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment