/public/js/hackdashApp.js
JavaScript | 4843 lines | 3263 code | 972 blank | 608 comment | 509 complexity | c66b06278711345e4df8055e3fd84ce7 MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- /*!
- * Hackdash - v0.5.1
- * Copyright (c) 2014 Hackdash
- *
- */
- (function (modules) {
- var resolve, getRequire, require, notFoundError, findFile
- , extensions = {".js":[],".json":[],".css":[],".html":[]};
- notFoundError = function (path) {
- var error = new Error("Could not find module '" + path + "'");
- error.code = 'MODULE_NOT_FOUND';
- return error;
- };
- findFile = function (scope, name, extName) {
- var i, ext;
- if (typeof scope[name + extName] === 'function') return name + extName;
- for (i = 0; (ext = extensions[extName][i]); ++i) {
- if (typeof scope[name + ext] === 'function') return name + ext;
- }
- return null;
- };
- resolve = function (scope, tree, path, fullpath, state) {
- var name, dir, exports, module, fn, found, i, ext;
- path = path.split('/');
- name = path.pop();
- if ((name === '.') || (name === '..')) {
- path.push(name);
- name = '';
- }
- while ((dir = path.shift()) != null) {
- if (!dir || (dir === '.')) continue;
- if (dir === '..') {
- scope = tree.pop();
- } else {
- tree.push(scope);
- scope = scope[dir];
- }
- if (!scope) throw notFoundError(fullpath);
- }
- if (name && (typeof scope[name] !== 'function')) {
- found = findFile(scope, name, '.js');
- if (!found) found = findFile(scope, name, '.json');
- if (!found) found = findFile(scope, name, '.css');
- if (!found) found = findFile(scope, name, '.html');
- if (found) {
- name = found;
- } else if ((state !== 2) && (typeof scope[name] === 'object')) {
- tree.push(scope);
- scope = scope[name];
- name = '';
- }
- }
- if (!name) {
- if ((state !== 1) && scope[':mainpath:']) {
- return resolve(scope, tree, scope[':mainpath:'], fullpath, 1);
- }
- return resolve(scope, tree, 'index', fullpath, 2);
- }
- fn = scope[name];
- if (!fn) throw notFoundError(fullpath);
- if (fn.hasOwnProperty('module')) return fn.module.exports;
- exports = {};
- fn.module = module = { exports: exports };
- fn.call(exports, exports, module, getRequire(scope, tree));
- return module.exports;
- };
- require = function (scope, tree, fullpath) {
- var name, path = fullpath, t = fullpath.charAt(0), state = 0;
- if (t === '/') {
- path = path.slice(1);
- scope = modules['/'];
- tree = [];
- } else if (t !== '.') {
- name = path.split('/', 1)[0];
- scope = modules[name];
- if (!scope) throw notFoundError(fullpath);
- tree = [];
- path = path.slice(name.length + 1);
- if (!path) {
- path = scope[':mainpath:'];
- if (path) {
- state = 1;
- } else {
- path = 'index';
- state = 2;
- }
- }
- }
- return resolve(scope, tree, path, fullpath, state);
- };
- getRequire = function (scope, tree) {
- return function (path) { return require(scope, [].concat(tree), path); };
- };
- return getRequire(modules, []);
- })({
- "client": {
- "app": {
- "HackdashApp.js": function (exports, module, require) {
- /**
- * Landing Application
- *
- */
- var HackdashRouter = require('./HackdashRouter')
- , ModalRegion = require('./views/ModalRegion');
- module.exports = function(){
- var app = module.exports = new Backbone.Marionette.Application();
- function initRegions(){
- app.addRegions({
- header: "header",
- main: "#main",
- footer: "footer",
- modals: ModalRegion
- });
- }
- function initRouter(){
- app.router = new HackdashRouter();
- Backbone.history.start({ pushState: true });
- }
- app.addInitializer(initRegions);
- app.addInitializer(initRouter);
- window.hackdash.app = app;
- window.hackdash.app.start();
- // Add navigation for BackboneRouter to all links
- // unless they have attribute "data-bypass"
- $(window.document).on("click", "a:not([data-bypass])", function(evt) {
- var href = { prop: $(this).prop("href"), attr: $(this).attr("href") };
- var root = window.location.protocol + "//" + window.location.host + (app.root || "");
- if (href.prop && href.prop.slice(0, root.length) === root) {
- evt.preventDefault();
- Backbone.history.navigate(href.attr, { trigger: true });
- }
- });
- };
- },
- "HackdashRouter.js": function (exports, module, require) {
- /*
- * Hackdash Router
- */
- var Dashboard = require("./models/Dashboard")
- , Project = require("./models/Project")
- , Projects = require("./models/Projects")
- , Dashboards = require("./models/Dashboards")
- , Collection = require("./models/Collection")
- , Collections = require("./models/Collections")
- , Profile = require("./models/Profile")
- , Header = require("./views/Header")
- , Footer = require("./views/Footer")
- , HomeLayout = require("./views/Home")
- , LoginView = require("./views/Login")
- , ProfileView = require("./views/Profile")
- , ProjectFullView = require("./views/Project/Full")
- , ProjectEditView = require("./views/Project/Edit")
- , ProjectsView = require("./views/Project/Layout")
- , DashboardsView = require("./views/Dashboard/Collection")
- , CollectionsView = require("./views/Collection/Collection");
- module.exports = Backbone.Marionette.AppRouter.extend({
-
- routes : {
- "" : "index"
-
- , "login" : "showLogin"
- , "projects" : "showProjects"
- , "projects/create" : "showProjectCreate"
- , "projects/:pid/edit" : "showProjectEdit"
- , "projects/:pid" : "showProjectFull"
- , "dashboards" : "showDashboards"
-
- , "collections" : "showCollections"
- , "collections/:cid" : "showCollection"
-
- , "users/profile": "showProfile"
- , "users/:user_id" : "showProfile"
- },
- index: function(){
- if (hackdash.subdomain){
- this.showDashboard();
- }
- else {
- this.showHome();
- }
- },
- removeHomeLayout: function(){
- $('body').removeClass("homepage");
- $('header').add('footer').show();
- $('#page').addClass('container');
- },
- showHome: function(){
- $('body').addClass("homepage");
- $('header').add('footer').hide();
- $('#page').removeClass('container');
- var app = window.hackdash.app;
- app.main.show(new HomeLayout());
- },
- getSearchQuery: function(){
- var query = hackdash.getQueryVariable("q");
- var fetchData = {};
- if (query && query.length > 0){
- fetchData = { data: $.param({ q: query }) };
- }
- return fetchData;
- },
- showLogin: function(){
- var providers = window.hackdash.providers;
- var app = window.hackdash.app;
- app.modals.show(new LoginView({
- model: new Backbone.Model({ providers: providers.split(',') })
- }));
- },
- showDashboard: function() {
- this.removeHomeLayout();
- var app = window.hackdash.app;
- app.type = "dashboard";
- app.dashboard = new Dashboard();
- app.projects = new Projects();
- app.header.show(new Header({
- model: app.dashboard,
- collection: app.projects
- }));
- app.main.show(new ProjectsView({
- model: app.dashboard,
- collection: app.projects
- }));
- app.footer.show(new Footer({
- model: app.dashboard
- }));
- var self = this;
- app.dashboard.fetch()
- .done(function(){
- app.projects.fetch(self.getSearchQuery(), { parse: true })
- .done(function(){
- app.projects.buildShowcase(app.dashboard.get("showcase"));
- });
- });
- },
- showProjects: function() {
- this.removeHomeLayout();
-
- var app = window.hackdash.app;
- app.type = "isearch";
- app.projects = new Projects();
-
- app.header.show(new Header({
- collection: app.projects
- }));
- app.main.show(new ProjectsView({
- collection: app.projects
- }));
- app.projects.fetch(this.getSearchQuery());
- },
- showProjectCreate: function(){
- this.removeHomeLayout();
-
- var app = window.hackdash.app;
- app.type = "project";
- app.dashboard = new Dashboard();
- app.project = new Project();
-
- app.header.show(new Header({
- model: app.dashboard
- }));
- app.main.show(new ProjectEditView({
- model: app.project
- }));
- app.dashboard.fetch();
- },
- showProjectEdit: function(pid){
- this.removeHomeLayout();
-
- var app = window.hackdash.app;
- app.type = "project";
- app.dashboard = new Dashboard();
- app.project = new Project({ _id: pid });
-
- app.header.show(new Header({
- model: app.dashboard
- }));
- app.main.show(new ProjectEditView({
- model: app.project
- }));
- app.dashboard.fetch();
- app.project.fetch();
- },
- showProjectFull: function(pid){
- this.removeHomeLayout();
-
- var app = window.hackdash.app;
- app.type = "project";
- app.dashboard = new Dashboard();
- app.project = new Project({ _id: pid });
-
- app.header.show(new Header({
- model: app.dashboard
- }));
- app.main.show(new ProjectFullView({
- model: app.project
- }));
- app.dashboard.fetch();
- app.project.fetch();
- },
- showCollections: function() {
- this.removeHomeLayout();
-
- var app = window.hackdash.app;
- app.type = "collections";
- app.collections = new Collections();
-
- app.header.show(new Header({
- collection: app.collections
- }));
- app.main.show(new CollectionsView({
- collection: app.collections
- }));
- app.collections.fetch(this.getSearchQuery());
- },
- showCollection: function(collectionId) {
- this.removeHomeLayout();
-
- var app = window.hackdash.app;
- app.type = "collection";
- app.collection = new Collection({ _id: collectionId });
-
- app.collection
- .fetch({ parse: true })
- .done(function(){
-
- app.header.show(new Header({
- model: app.collection
- }));
- app.main.show(new DashboardsView({
- hideAdd: true,
- collection: app.collection.get("dashboards")
- }));
- });
- },
- showProfile: function(userId) {
- this.removeHomeLayout();
-
- var app = window.hackdash.app;
- app.type = "profile";
- if (!userId){
- if (hackdash.user){
- userId = hackdash.user._id;
- }
- else {
- window.location = "/";
- }
- }
- app.profile = new Profile({
- _id: userId
- });
- app.profile.fetch({ parse: true });
- app.header.show(new Header());
- app.main.show(new ProfileView({
- model: app.profile
- }));
- },
- showDashboards: function() {
- this.removeHomeLayout();
-
- var app = window.hackdash.app;
- app.type = "dashboards";
- app.dashboards = new Dashboards();
- app.collections = new Collections();
-
- app.header.show(new Header({
- collection: app.dashboards
- }));
- app.main.show(new DashboardsView({
- collection: app.dashboards
- }));
- app.collections.getMines();
- app.dashboards.fetch(this.getSearchQuery());
- }
- });
- },
- "Initializer.js": function (exports, module, require) {
-
- module.exports = function(){
- window.hackdash = window.hackdash || {};
- window.hackdash.getQueryVariable = function(variable){
- var query = window.location.search.substring(1);
- var vars = query.split("&");
- for (var i=0;i<vars.length;i++) {
- var pair = vars[i].split("=");
- if(pair[0] === variable){return decodeURI(pair[1]);}
- }
- return(false);
- };
- if ($.fn.editable){
- // Set global mode for InlineEditor (X-Editable)
- $.fn.editable.defaults.mode = 'inline';
- }
-
- // Init Helpers
- require('./helpers/handlebars');
- require('./helpers/backboneOverrides');
-
- Placeholders.init({ live: true, hideOnFocus: true });
-
- window.hackdash.apiURL = "/api/v2";
- window.hackdash.startApp = require('./HackdashApp');
- };
- },
- "helpers": {
- "backboneOverrides.js": function (exports, module, require) {
- /*
- * Backbone Global Overrides
- *
- */
- // Override Backbone.sync to use the PUT HTTP method for PATCH requests
- // when doing Model#save({...}, { patch: true });
- var originalSync = Backbone.sync;
- Backbone.sync = function(method, model, options) {
- if (method === 'patch') {
- options.type = 'PUT';
- }
- return originalSync(method, model, options);
- };
- },
- "handlebars.js": function (exports, module, require) {
- /**
- * HELPER: Handlebars Template Helpers
- *
- */
-
- Handlebars.registerHelper('embedCode', function() {
- var embedUrl = window.location.protocol + "//" + window.location.host;
- var template = _.template('<iframe src="<%= embedUrl %>" width="100%" height="500" frameborder="0" allowtransparency="true" title="Hackdash"></iframe>');
-
- return template({
- embedUrl: embedUrl
- });
- });
-
- Handlebars.registerHelper('firstUpper', function(text) {
- return text.charAt(0).toUpperCase() + text.slice(1);
- });
-
- Handlebars.registerHelper('markdown', function(md) {
- return markdown.toHTML(md);
- });
-
- Handlebars.registerHelper('disqus_shortname', function() {
- return window.hackdash.disqus_shortname;
- });
-
- Handlebars.registerHelper('user', function(prop) {
- if (window.hackdash.user){
- return window.hackdash.user[prop];
- }
- });
-
- Handlebars.registerHelper('isLoggedIn', function(options) {
- if (window.hackdash.user){
- return options.fn(this);
- } else {
- return options.inverse(this);
- }
- });
-
- Handlebars.registerHelper('isDashboardView', function(options) {
- if (window.hackdash.app.type === "dashboard"){
- return options.fn(this);
- } else {
- return options.inverse(this);
- }
- });
-
- Handlebars.registerHelper('isSearchView', function(options) {
- if (window.hackdash.app.type === "isearch"){
- return options.fn(this);
- } else {
- return options.inverse(this);
- }
- });
-
- Handlebars.registerHelper('timeAgo', function(date) {
- if (date && moment(date).isValid()) {
- return moment(date).fromNow();
- }
-
- return "-";
- });
-
- Handlebars.registerHelper('formatDate', function(date) {
- if (date && moment(date).isValid()) {
- return moment(date).format("DD/MM/YYYY HH:mm");
- }
-
- return "-";
- });
-
- Handlebars.registerHelper('formatDateText', function(date) {
- if (date && moment(date).isValid()) {
- return moment(date).format("DD MMM YYYY, HH:mm");
- }
-
- return "";
- });
-
- Handlebars.registerHelper('formatDateTime', function(date) {
- if (date && moment(date).isValid()) {
- return moment(date).format("HH:mm");
- }
-
- return "";
- });
-
- Handlebars.registerHelper('timeFromSeconds', function(seconds) {
-
- function format(val){
- return (val < 10) ? "0" + val : val;
- }
-
- if (seconds && seconds > 0){
-
- var t = moment.duration(seconds * 1000),
- h = format(t.hours()),
- m = format(t.minutes()),
- s = format(t.seconds());
-
- return h + ":" + m + ":" + s;
- }
-
- return "-";
- });
- }
- },
- "index.js": function (exports, module, require) {
- jQuery(function() {
- require('./Initializer')();
- });
- },
- "models": {
- "Admins.js": function (exports, module, require) {
- /**
- * Collection: Administrators of a Dashboard
- *
- */
- var
- Users = require('./Users'),
- User = require('./User');
- module.exports = Users.extend({
-
- model: User,
- idAttribute: "_id",
- url: function(){
- return hackdash.apiURL + '/admins';
- },
- addAdmin: function(userId){
- $.ajax({
- url: this.url() + '/' + userId,
- type: "POST",
- context: this
- }).done(function(user){
- this.add(user);
- });
- },
- });
- },
- "Collection.js": function (exports, module, require) {
- /**
- * MODEL: Collection (a group of Dashboards)
- *
- */
- var Dashboards = require('./Dashboards');
- module.exports = Backbone.Model.extend({
- idAttribute: "_id",
- urlRoot: function(){
- return hackdash.apiURL + '/collections';
- },
- parse: function(response){
- response.dashboards = new Dashboards(response.dashboards || []);
- return response;
- },
- addDashboard: function(dashId){
- $.ajax({
- url: this.url() + '/dashboards/' + dashId,
- type: "POST",
- context: this
- });
- this.get("dashboards").add({ _id: dashId });
- },
- removeDashboard: function(dashId){
- $.ajax({
- url: this.url() + '/dashboards/' + dashId,
- type: "DELETE",
- context: this
- });
- var result = this.get("dashboards").where({ _id: dashId});
- if (result.length > 0){
- this.get("dashboards").remove(result[0]);
- }
- },
- });
- },
- "Collections.js": function (exports, module, require) {
- /**
- * Collection: Collections (group of Dashboards)
- *
- */
- var
- Collection = require('./Collection');
- module.exports = Backbone.Collection.extend({
- model: Collection,
- idAttribute: "_id",
-
- url: function(){
- return hackdash.apiURL + '/collections';
- },
- getMines: function(){
- $.ajax({
- url: this.url() + '/own',
- context: this
- }).done(function(collections){
- this.reset(collections, { parse: true });
- });
- }
- });
- },
- "Dashboard.js": function (exports, module, require) {
- /**
- * MODEL: Project
- *
- */
- var Admins = require("./Admins");
- module.exports = Backbone.Model.extend({
- defaults: {
- admins: null
- },
- url: function(){
- return hackdash.apiURL + "/";
- },
- idAttribute: "_id",
- initialize: function(){
- this.set("admins", new Admins());
- },
- });
- },
- "Dashboards.js": function (exports, module, require) {
- /**
- * MODEL: Dashboards
- *
- */
- module.exports = Backbone.Collection.extend({
- url: function(){
- return hackdash.apiURL + "/dashboards";
- },
- idAttribute: "_id",
- });
- },
- "Profile.js": function (exports, module, require) {
- /**
- * MODEL: User
- *
- */
- var Projects = require("./Projects");
- module.exports = Backbone.Model.extend({
- idAttribute: "_id",
- defaults: {
- collections: new Backbone.Collection(),
- dashboards: new Backbone.Collection(),
- projects: new Projects(),
- contributions: new Projects(),
- likes: new Projects()
- },
- urlRoot: function(){
- return hackdash.apiURL + '/profiles';
- },
- parse: function(response){
- this.get("collections").reset(response.collections);
- this.get("dashboards").reset(
- _.map(response.admin_in, function(dash){ return { title: dash }; })
- );
-
- this.get("projects").reset(response.projects);
- this.get("contributions").reset(response.contributions);
- this.get("likes").reset(response.likes);
-
- return response;
- }
- });
- },
- "Project.js": function (exports, module, require) {
- /**
- * MODEL: Project
- *
- */
- module.exports = Backbone.Model.extend({
- idAttribute: "_id",
- defaults: {
- active: true
- },
- urlRoot: function(){
- return hackdash.apiURL + '/projects';
- },
- doAction: function(type, res, done){
- $.ajax({
- url: this.url() + '/' + res,
- type: type,
- context: this
- }).done(done);
- },
- updateList: function(type, add){
- var list = this.get(type);
- var uid = hackdash.user._id;
- function exists(){
- return _.find(list, function(usr){
- return (usr._id === uid);
- }) ? true : false;
- }
- if (add && !exists()){
- list.push(hackdash.user);
- }
- else if (!add && exists()){
- var idx = 0;
- _.each(list, function(usr, i){
- if (usr._id === uid) {
- idx = i;
- }
- });
- list.splice(idx, 1);
- }
- this.set(type, list);
- this.trigger("change");
- },
- join: function(){
- this.doAction("POST", "contributors", function(){
- this.updateList("contributors", true);
- });
- },
- leave: function(){
- this.doAction("DELETE", "contributors", function(){
- this.updateList("contributors", false);
- });
- },
- follow: function(){
- this.doAction("POST", "followers", function(){
- this.updateList("followers", true);
- });
- },
- unfollow: function(){
- this.doAction("DELETE", "followers", function(){
- this.updateList("followers", false);
- });
- },
- });
- },
- "Projects.js": function (exports, module, require) {
- /**
- * Collection: Projectss
- *
- */
- var
- Project = require('./Project');
- var Projects = module.exports = Backbone.Collection.extend({
- model: Project,
- idAttribute: "_id",
-
- url: function(){
- return hackdash.apiURL + '/projects';
- },
- parse: function(response){
- if (hackdash.app.type !== "dashboard"){
- //it is not a dashboard so all projects active
- return response;
- }
- var dashboard = hackdash.app.dashboard;
- var showcase = (dashboard && dashboard.get("showcase")) || [];
- if (showcase.length === 0){
- //no showcase defined: all projects are active
- return response;
- }
- // set active property of a project from showcase mode
- // (only projects at showcase array are active ones)
- _.each(response, function(project){
-
- if (showcase.indexOf(project._id) >= 0){
- project.active = true;
- }
- else {
- project.active = false;
- }
- });
- return response;
- },
- buildShowcase: function(showcase){
- _.each(showcase, function(id, i){
- var found = this.where({ _id: id, active: true });
- if (found.length > 0){
- found[0].set("showcase", i);
- }
- }, this);
- this.trigger("reset");
- },
- getActives: function(){
- return new Projects(
- this.filter(function(project){
- return project.get("active");
- })
- );
- },
- getInactives: function(){
- return new Projects(
- this.filter(function(project){
- return !project.get("active");
- })
- );
- }
- });
- },
- "User.js": function (exports, module, require) {
- /**
- * MODEL: User
- *
- */
- module.exports = Backbone.Model.extend({
- idAttribute: "_id",
- });
- },
- "Users.js": function (exports, module, require) {
- /**
- * Collection: Users
- *
- */
- var
- User = require('./User');
- module.exports = Backbone.Collection.extend({
-
- model: User,
-
- idAttribute: "_id",
- url: function(){
- return hackdash.apiURL + '/users';
- },
- });
- }
- },
- "views": {
- "Collection": {
- "Collection.js": function (exports, module, require) {
- /**
- * VIEW: Collections
- *
- */
- var Collection = require('./index');
- module.exports = Backbone.Marionette.CollectionView.extend({
- //--------------------------------------
- //+ PUBLIC PROPERTIES / CONSTANTS
- //--------------------------------------
- id: "collections",
- className: "row collections",
- itemView: Collection,
-
- collectionEvents: {
- "remove": "render"
- },
- //--------------------------------------
- //+ INHERITED / OVERRIDES
- //--------------------------------------
-
- onRender: function(){
- var self = this;
- _.defer(function(){
- self.updateIsotope();
- });
- },
- //--------------------------------------
- //+ PUBLIC METHODS / GETTERS / SETTERS
- //--------------------------------------
- //--------------------------------------
- //+ EVENT HANDLERS
- //--------------------------------------
- //--------------------------------------
- //+ PRIVATE AND PROTECTED METHODS
- //--------------------------------------
- isotopeInitialized: false,
- updateIsotope: function(){
- var $collections = this.$el;
- if (this.isotopeInitialized){
- $collections.isotope("destroy");
- }
- $collections.isotope({
- itemSelector: ".collection"
- , animationEngine: "jquery"
- , resizable: true
- });
-
- this.isotopeInitialized = true;
- }
- });
- },
- "List.js": function (exports, module, require) {
- /**
- * VIEW: User Collections
- *
- */
- var template = require('./templates/list.hbs')
- , Collection = require('./ListItem');
- module.exports = Backbone.Marionette.CompositeView.extend({
- //--------------------------------------
- //+ PUBLIC PROPERTIES / CONSTANTS
- //--------------------------------------
- className: "modal my-collections-modal",
- template: template,
- itemView: Collection,
- itemViewContainer: ".collections",
- ui: {
- "title": "input[name=title]",
- "description": "input[name=description]",
- "events": ".events"
- },
- events: {
- "click .close": "close",
- "click .btn-add": "add"
- },
- itemViewOptions: function(){
- return {
- dashboardId: this.model.get("_id")
- };
- },
- //--------------------------------------
- //+ INHERITED / OVERRIDES
- //--------------------------------------
- //--------------------------------------
- //+ PUBLIC METHODS / GETTERS / SETTERS
- //--------------------------------------
- addedCollection: function(title){
- this.showAction("add", title);
- },
- removedCollection: function(title){
- this.showAction("remove", title);
- },
- //--------------------------------------
- //+ EVENT HANDLERS
- //--------------------------------------
- add: function(){
- if (this.ui.title.val()){
- this.collection.create({
- title: this.ui.title.val(),
- description: this.ui.description.val()
- }, { wait: true });
- this.ui.title.val("");
- this.ui.description.val("");
- }
- },
- //--------------------------------------
- //+ PRIVATE AND PROTECTED METHODS
- //--------------------------------------
- timer: null,
- showAction: function(type, title){
- var msg = (type === 'add' ? ' has been added to ' : ' has been removed from ');
- var dash = this.model.get("domain");
- this.ui.events.empty();
- window.clearTimeout(this.timer);
-
- var li = $('<li><span>' + dash + '</span>' + msg + '<span>' + title + '</span></li>');
- li.appendTo(this.ui.events);
- var self = this;
- this.timer = window.setTimeout(function(){
- self.ui.events.empty();
- }, 50000);
- }
- });
- },
- "ListItem.js": function (exports, module, require) {
- /**
- * VIEW: A User Collection
- *
- */
-
- var template = require('./templates/listItem.hbs');
- module.exports = Backbone.Marionette.ItemView.extend({
- //--------------------------------------
- //+ PUBLIC PROPERTIES / CONSTANTS
- //--------------------------------------
- tagName: "li",
- template: template,
- //--------------------------------------
- //+ INHERITED / OVERRIDES
- //--------------------------------------
- initialize: function(options){
- this.dashboardId = options.dashboardId;
- },
- onRender: function(){
- if (this.hasDashboard()){
- this.$el.addClass('active');
- }
- else {
- this.$el.removeClass('active');
- }
- this.$el.off("click").on("click", this.toggleDashboard.bind(this));
- },
- serializeData: function(){
- return _.extend({
- hasDash: this.hasDashboard()
- }, this.model.toJSON());
- },
- //--------------------------------------
- //+ PUBLIC METHODS / GETTERS / SETTERS
- //--------------------------------------
- //--------------------------------------
- //+ EVENT HANDLERS
- //--------------------------------------
- viewCollection: function(){
- this.$el.off("click");
- hackdash.app.modals.close();
- },
- toggleDashboard: function(e){
- if ($(e.target).hasClass("view-collection")){
- this.viewCollection();
- return;
- }
- if (this.hasDashboard()){
- this.model.removeDashboard(this.dashboardId);
- hackdash.app.modals.currentView.removedCollection(this.model.get("title"));
- }
- else {
- this.model.addDashboard(this.dashboardId);
- hackdash.app.modals.currentView.addedCollection(this.model.get("title"));
- }
- this.render();
- },
- //--------------------------------------
- //+ PRIVATE AND PROTECTED METHODS
- //--------------------------------------
- hasDashboard: function(){
- return this.model.get("dashboards").where({ _id: this.dashboardId}).length > 0;
- }
- });
- },
- "index.js": function (exports, module, require) {
- /**
- * VIEW: Collection
- *
- */
-
- var template = require('./templates/collection.hbs');
- module.exports = Backbone.Marionette.ItemView.extend({
- //--------------------------------------
- //+ PUBLIC PROPERTIES / CONSTANTS
- //--------------------------------------
- id: function(){
- return this.model.get("_id");
- },
- className: "collection span4",
- template: template,
- //--------------------------------------
- //+ INHERITED / OVERRIDES
- //--------------------------------------
- onRender: function(){
- var url = "http://" + hackdash.baseURL + "/collections/" + this.model.get("_id");
- this.$el.on("click", function(e){
- if (!$(e.target).hasClass("add")){
- window.location = url;
- }
- });
- },
- //--------------------------------------
- //+ PUBLIC METHODS / GETTERS / SETTERS
- //--------------------------------------
- //--------------------------------------
- //+ EVENT HANDLERS
- //--------------------------------------
- //--------------------------------------
- //+ PRIVATE AND PROTECTED METHODS
- //--------------------------------------
- });
- },
- "templates": {
- "collection.hbs.js": function (exports, module, require) {
- module.exports = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
- this.compilerInfo = [4,'>= 1.0.0'];
- helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
- var buffer = "", stack1, options, functionType="function", escapeExpression=this.escapeExpression, helperMissing=helpers.helperMissing;
- buffer += "<div class=\"well\">\n <div class=\"well-content\">\n <h4>";
- if (stack1 = helpers.title) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
- else { stack1 = depth0.title; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
- buffer += escapeExpression(stack1)
- + "</h4>\n ";
- if (stack1 = helpers.description) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
- else { stack1 = depth0.description; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
- buffer += escapeExpression(stack1)
- + "\n </div>\n <div class=\"row-fluid footer-box\">\n <div class=\"aging activity created_at\">\n <i rel=\"tooltip\" title=\"";
- options = {hash:{},data:data};
- buffer += escapeExpression(((stack1 = helpers.timeAgo || depth0.timeAgo),stack1 ? stack1.call(depth0, depth0.created_at, options) : helperMissing.call(depth0, "timeAgo", depth0.created_at, options)))
- + "\" class=\"tooltips icon-time icon-1\"></i>\n </div>\n </div>\n</div>\n";
- return buffer;
- })
- ;
- },
- "list.hbs.js": function (exports, module, require) {
- module.exports = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
- this.compilerInfo = [4,'>= 1.0.0'];
- helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
- var buffer = "", stack1, functionType="function", escapeExpression=this.escapeExpression;
- buffer += "<div class=\"modal-header\">\n <button type=\"button\" data-dismiss=\"modal\" aria-hidden=\"true\" class=\"close\">Ă—</button>\n <h3>My Collections: adding ";
- if (stack1 = helpers.domain) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
- else { stack1 = depth0.domain; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
- buffer += escapeExpression(stack1)
- + "</h3>\n <ul class=\"events\"></ul>\n</div>\n<div class=\"modal-body\">\n <ul class=\"collections\"></ul>\n</div>\n<div class=\"modal-footer\">\n <div class=\"row-fluid\">\n <div class=\"span12\">\n <div class=\"span10\">\n <input type=\"text\" name=\"title\" placeholder=\"Enter Title\" class=\"input-medium pull-left\" style=\"margin-right: 10px;\">\n <input type=\"text\" name=\"description\" placeholder=\"Enter Description\" class=\"input-medium pull-left\">\n <input type=\"button\" class=\"btn primary btn-success pull-left btn-add\" value=\"Add\">\n </div>\n <div class=\"span2\">\n <input type=\"button\" class=\"btn primary pull-right\" data-dismiss=\"modal\" value=\"Close\">\n </div>\n </div>\n </div>\n</div>";
- return buffer;
- })
- ;
- },
- "listItem.hbs.js": function (exports, module, require) {
- module.exports = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
- this.compilerInfo = [4,'>= 1.0.0'];
- helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
- var buffer = "", stack1, functionType="function", escapeExpression=this.escapeExpression;
- buffer += "<label class=\"pull-left\">\n ";
- if (stack1 = helpers.title) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
- else { stack1 = depth0.title; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
- buffer += escapeExpression(stack1)
- + "\n</label>\n\n<a class=\"pull-right view-collection\" href=\"/collections/";
- if (stack1 = helpers._id) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
- else { stack1 = depth0._id; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
- buffer += escapeExpression(stack1)
- + "\">View</a>";
- return buffer;
- })
- ;
- }
- }
- },
- "Dashboard": {
- "Collection.js": function (exports, module, require) {
- /**
- * VIEW: Dashboards
- *
- */
- var Dashboard = require('./index');
- module.exports = Backbone.Marionette.CollectionView.extend({
- //--------------------------------------
- //+ PUBLIC PROPERTIES / CONSTANTS
- //--------------------------------------
- id: "dashboards",
- className: "row dashboards",
- itemView: Dashboard,
-
- itemViewOptions: function(){
- return {
- hideAdd: this.hideAdd
- };
- },
- //--------------------------------------
- //+ INHERITED / OVERRIDES
- //--------------------------------------
-
- initialize: function(options){
- this.hideAdd = (options && options.hideAdd) || false;
- },
- onRender: function(){
- var self = this;
- _.defer(function(){
- self.updateIsotope();
- });
- },
- //--------------------------------------
- //+ PUBLIC METHODS / GETTERS / SETTERS
- //--------------------------------------
- //--------------------------------------
- //+ EVENT HANDLERS
- //--------------------------------------
- //--------------------------------------
- //+ PRIVATE AND PROTECTED METHODS
- //--------------------------------------
- isotopeInitialized: false,
- updateIsotope: function(){
- var $dashboards = this.$el;
- if (this.isotopeInitialized){
- $dashboards.isotope("destroy");
- }
- $dashboards.isotope({
- itemSelector: ".dashboard"
- , animationEngine: "jquery"
- , resizable: true
- });
-
- this.isotopeInitialized = true;
- }
- });
- },
- "index.js": function (exports, module, require) {
- /**
- * VIEW: Dashboard
- *
- */
-
- var template = require('./templates/dashboard.hbs')
- , UserCollectionsView = require('../Collection/List');
- module.exports = Backbone.Marionette.ItemView.extend({
- //--------------------------------------
- //+ PUBLIC PROPERTIES / CONSTANTS
- //--------------------------------------
- id: function(){
- return this.model.get("_id");
- },
- className: "dashboard span4",
- template: template,
- events: {
- "click .demo a": "stopPropagation",
- "click .add a": "onAddToCollection"
- },
- //--------------------------------------
- //+ INHERITED / OVERRIDES
- //--------------------------------------
- initialize: function(options){
- this.hideAdd = (options && options.hideAdd) || false;
- },
- onRender: function(){
- this.$el
- .attr({
- "title": this.model.get("status")
- , "data-name": this.model.get("domain")
- , "data-date": this.model.get("created_at")
- })
- .tooltip({});
- $('.tooltips', this.$el).tooltip({});
- var url = "http://" + this.model.get("domain") + "." + hackdash.baseURL;
- this.$el.on("click", function(e){
- if (!$(e.target).hasClass("add")){
- window.location = url;
- }
- });
- },
- serializeData: function(){
- return _.extend({
- hideAdd: this.hideAdd
- }, this.model.toJSON());
- },
- //--------------------------------------
- //+ PUBLIC METHODS / GETTERS / SETTERS
- //--------------------------------------
- //--------------------------------------
- //+ EVENT HANDLERS
- //--------------------------------------
- stopPropagation: function(e){
- e.stopPropagation();
- },
- onAddToCollection: function(){
- hackdash.app.modals.show(new UserCollectionsView({
- model: this.model,
- collection: hackdash.app.collections
- }));
- },
- //--------------------------------------
- //+ PRIVATE AND PROTECTED METHODS
- //--------------------------------------
- });
- },
- "templates": {
- "dashboard.hbs.js": function (exports, module, require) {
- module.exports = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
- this.compilerInfo = [4,'>= 1.0.0'];
- helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
- var buffer = "", stack1, stack2, options, functionType="function", escapeExpression=this.escapeExpression, self=this, blockHelperMissing=helpers.blockHelperMissing, helperMissing=helpers.helperMissing;
- function program1(depth0,data) {
-
- var buffer = "", stack1;
- buffer += "\n <div class=\"pull-right demo\">\n <a href=\"";
- if (stack1 = helpers.link) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
- else { stack1 = depth0.link; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
- buffer += escapeExpression(stack1)
- + "\" target=\"_blank\" class=\"btn btn-link\">Site</a>\n </div>\n ";
- return buffer;
- }
- function program3(depth0,data) {
-
- var buffer = "", stack1, options;
- buffer += "\n ";
- options = {hash:{},inverse:self.noop,fn:self.program(4, program4, data),data:data};
- if (stack1 = helpers.isLoggedIn) { stack1 = stack1.call(depth0, options); }
- else { stack1 = depth0.isLoggedIn; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
- if (!helpers.isLoggedIn) { stack1 = blockHelperMissing.call(depth0, stack1, options); }
- if(stack1 || stack1 === 0) { buffer += stack1; }
- buffer += "\n ";
- return buffer;
- }
- function program4(depth0,data) {
-
-
- return "\n <div class=\"pull-right add\">\n <a class=\"btn btn-link add\">Add to Collections</a>\n </div>\n ";
- }
- buffer += "<div class=\"well\">\n <div class=\"well-content\">\n <h4>";
- if (stack1 = helpers.domain) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
- else { stack1 = depth0.domain; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
- buffer += escapeExpression(stack1)
- + "</h4>\n <h4>";
- if (stack1 = helpers.title) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
- else { stack1 = depth0.title; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
- buffer += escapeExpression(stack1)
- + "</h4>\n ";
- if (stack1 = helpers.description) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
- else { stack1 = depth0.description; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
- buffer += escapeExpression(stack1)
- + "\n <br/>\n </div>\n <div class=\"row-fluid footer-box\">\n <div class=\"aging activity created_at\">\n <i rel=\"tooltip\" title=\"";
- options = {hash:{},data:data};
- buffer += escapeExpression(((stack1 = helpers.timeAgo || depth0.timeAgo),stack1 ? stack1.call(depth0, depth0.created_at, options) : helperMissing.call(depth0, "timeAgo", depth0.created_at, options)))
- + "\" class=\"tooltips icon-time icon-1\"></i>\n </div>\n\n ";
- stack2 = helpers['if'].call(depth0, depth0.link, {hash:{},inverse:self.noop,fn:self.program(1, program1, data),data:data});
- if(stack2 || stack2 === 0) { buffer += stack2; }
- buffer += "\n\n ";
- stack2 = helpers.unless.call(depth0, depth0.hideAdd, {hash:{},inverse:self.noop,fn:self.program(3, program3, data),data:data});
- if(stack2 || stack2 === 0) { buffer += stack2; }
- buffer += "\n \n </div>\n</div>\n";
- return buffer;
- })
- ;
- }
- }
- },
- "Footer": {
- "AddAdmin.js": function (exports, module, require) {
- /**
- * VIEW: A User Collection
- *
- */
-
- var template = require('./templates/addAdmin.hbs')
- , Users = require('../../models/Users');
- module.exports = Backbone.Marionette.ItemView.extend({
- //--------------------------------------
- //+ PUBLIC PROPERTIES / CONSTANTS
- //--------------------------------------
- className: "modal add-admins-modal",
- template: template,
- ui: {
- "txtUser": "#txtUser",
- "addOn": ".add-on"
- },
- events: {
- "click #save": "saveAdmin"
- },
- //--------------------------------------
- //+ INHERITED / OVERRIDES
- //--------------------------------------
- initialize: function(){
- this.users = new Users();
- },
- onRender: function(){
- this.initTypehead();
- },
- //--------------------------------------
- //+ PUBLIC METHODS / GETTERS / SETTERS
- //--------------------------------------
- //--------------------------------------
- //+ EVENT HANDLERS
- //--------------------------------------
- saveAdmin: function(){
- var selected = this.users.find(function(user){
- return user.get('selected');
- });
- if (selected){
- this.collection.addAdmin(selected.get("_id"));
- this.close();
- }
- },
- //--------------------------------------
- //+ PRIVATE AND PROTECTED METHODS
- //--------------------------------------
- initTypehead: function(){
- var users = this.users,
- self = this,
- MIN_CHARS_FOR_SERVER_SEARCH = 3;
- this.ui.txtUser.typeahead({
- source: function(query, process){
- if (query.length >= MIN_CHARS_FOR_SERVER_SEARCH){
- users.fetch({
- data: $.param({ q: query }),
- success: function(){
- var usersIds = users.map(function(user){ return user.get('_id').toString(); });
- process(usersIds);
- }
- });
- }
- else {
- process([]);
- }
- },
- matcher: function(){
- return true;
- },
- highlighter: function(uid){
- var user = users.get(uid),
- template = _.template('<img class="avatar" src="<%= picture %>" /> <%= name %>');
- return template({
- picture: user.get('picture'),
- name: user.get('name')
- });
- },
- updater: function(uid) {
- var selectedUser = users.get(uid);
- selectedUser.set('selected', true);
- self.ui.addOn.empty().append('<img class="avatar" src="' + selectedUser.get("picture") + '" />');
- return selectedUser.get('name');
- }
- });
- }
- });
- },
- "Embed.js": function (exports, module, require) {
- /**
- * VIEW: A Embed code
- *
- */
-
- var template = require('./templates/embed.hbs');
- module.exports = Backbone.Marionette.ItemView.extend({
- //--------------------------------------
- //+ PUBLIC PROPERTIES / CONSTANTS
- //--------------------------------------
- className: "modal",
- template: template,
- ui: {
- embedCode: "textarea"
- },
- //--------------------------------------
- //+ INHERITED / OVERRIDES
- //--------------------------------------
- onRender: function(){
- var self = this;
- _.defer(function(){
- self.ui.embedCode.select();
- });
- },
- //--------------------------------------
- //+ PUBLIC METHODS / GETTERS / SETTERS
- //--------------------------------------
- //--------------------------------------
- //+ EVENT HANDLERS
- //--------------------------------------
- //--------------------------------------
- //+ PRIVATE AND PROTECTED METHODS
- //--------------------------------------
- });
- },
- "User.js": function (exports, module, require) {
- /**
- * VIEW: User
- *
- */
-
- var template = require('./templates/user.hbs');
- module.exports = Backbone.Marionette.ItemView.extend({
- //--------------------------------------
- //+ PUBLIC PROPERTIES / CON…
Large files files are truncated, but you can click here to view the full file