From c8bee03f8c0ca82c3981724e5bc661f630d9ab7e Mon Sep 17 00:00:00 2001 From: RaNaN Date: Tue, 19 Feb 2013 22:13:10 +0100 Subject: integrated new package view --- module/web/static/js/utils/animations.js | 69 ++++++++++++++++++--------- module/web/static/js/views/fileView.js | 11 ++++- module/web/static/js/views/headerView.js | 7 ++- module/web/static/js/views/packageTreeView.js | 67 ++++++++++++++++---------- module/web/static/js/views/packageView.js | 64 ++++++++++--------------- module/web/static/js/views/selectionView.js | 49 +++++++++++++++++++ 6 files changed, 179 insertions(+), 88 deletions(-) create mode 100644 module/web/static/js/views/selectionView.js (limited to 'module/web/static/js') diff --git a/module/web/static/js/utils/animations.js b/module/web/static/js/utils/animations.js index 657bd2bec..245614ea7 100644 --- a/module/web/static/js/utils/animations.js +++ b/module/web/static/js/utils/animations.js @@ -4,6 +4,7 @@ define(['jquery', 'underscore', 'transit'], function(jQuery, _) { // Important function to have slide animations jQuery.fn.appendWithHeight = function(element, hide) { var o = jQuery(this[0]); + element = jQuery(element); // TODO: additionally it could be placed out of viewport first // The real height can only be retrieved when element is on DOM and display:true @@ -24,6 +25,50 @@ define(['jquery', 'underscore', 'transit'], function(jQuery, _) { return this; }; + // Shortcut to have a animation when element is added + jQuery.fn.appendWithAnimation = function(element, animation) { + var o = jQuery(this[0]); + if (animation === true) + o.hide(); + + o.append(element); + + if (animation === true) + o.fadeIn(); + + return this; + }; + + // calculate the height and write it to data, better used on invisible elements + jQuery.fn.calculateHeight = function() { + var o = jQuery(this[0]); + var height = o.height(); + if (!height) { + var display = o.css('display'); + o.css('visibility', 'hidden'); + o.show(); + height = o.height(); + + o.css('display', display); + o.css('visibility', ''); + } + + o.data('height', height); + return this; + }; + + jQuery.fn.slideOut = function() { + var o = jQuery(this[0]); + o.animate({height: o.data('height'), opacity: 'show'}); + return this; + }; + + jQuery.fn.slideIn = function() { + var o = jQuery(this[0]); + o.animate({height: 0, opacity: 'hide'}); + return this; + }; + // TODO: sloppy chaining // // in functions not possible without previous out @@ -42,7 +87,7 @@ define(['jquery', 'underscore', 'transit'], function(jQuery, _) { if (!this.data('height')) { var height = this.height(); this.css({height: height}); - this.data('height', height) + this.data('height', height); } this.transition({ height: '0px', @@ -52,28 +97,6 @@ define(['jquery', 'underscore', 'transit'], function(jQuery, _) { }; - jQuery.fn.slideIn = function(speed, easing, callback) { - var height = this.data('height') || '100%'; - this.transition({ - height: height, - opacity: 'show' - }, speed, easing, callback); - - }; - - jQuery.fn.slideOut = function(speed, easing, callback) { - if (!this.data('height')) { - var height = this.height(); - this.css({height: height, overflow: 'hidden'}); - this.data('height', height) - } - this.transition({ - height: '0px', - opacity: 'hide' - }, speed, easing, callback); - - }; - jQuery.fn._transit = jQuery.fn.transit; // Overriding transit plugin to support hide and show diff --git a/module/web/static/js/views/fileView.js b/module/web/static/js/views/fileView.js index 7e8f899a9..86f7b33d2 100644 --- a/module/web/static/js/views/fileView.js +++ b/module/web/static/js/views/fileView.js @@ -9,7 +9,7 @@ define(['jquery', 'backbone', 'underscore', 'app', 'views/abstract/itemView'], // template: _.template($("#template-file").html()), template: _.compile($("#template-file").html()), events: { - + 'click .checkbox': 'select' }, initialize: function() { @@ -25,6 +25,15 @@ define(['jquery', 'backbone', 'underscore', 'app', 'views/abstract/itemView'], render: function() { this.$el.html(this.template(this.model.toJSON())); return this; + }, + + select: function(e) { + e.preventDefault(); + var checked = this.$('.checkbox').hasClass('checked'); + // toggle class immediately, so no re-render needed + this.model.set('selected', !checked, {silent: true}); + this.$('.checkbox').toggleClass('checked'); + App.vent.trigger('file:selection'); } }); diff --git a/module/web/static/js/views/headerView.js b/module/web/static/js/views/headerView.js index 7effcf79d..43c66b99f 100644 --- a/module/web/static/js/views/headerView.js +++ b/module/web/static/js/views/headerView.js @@ -1,4 +1,4 @@ -define(['jquery', 'backbone', 'flot'], function($, Backbone) { +define(['jquery', 'underscore', 'backbone', 'flot'], function($, _, Backbone) { // Renders the header with all information return Backbone.View.extend({ @@ -12,9 +12,14 @@ define(['jquery', 'backbone', 'flot'], function($, Backbone) { // Will hold the link grabber grabber: null, + notifications: null, + selections: null, initialize: function() { + this.notifications = this.$('#notification-area').calculateHeight(); + this.selections = this.$('#selection-area').calculateHeight(); + var totalPoints = 100; var data = []; diff --git a/module/web/static/js/views/packageTreeView.js b/module/web/static/js/views/packageTreeView.js index 8791a93f2..41db0dc2c 100644 --- a/module/web/static/js/views/packageTreeView.js +++ b/module/web/static/js/views/packageTreeView.js @@ -1,5 +1,6 @@ -define(['jquery', 'backbone', 'underscore', 'app', 'models/TreeCollection', 'views/packageView', 'views/fileView'], - function($, Backbone, _, App, TreeCollection, packageView, fileView) { +define(['jquery', 'backbone', 'underscore', 'app', 'models/TreeCollection', + 'views/packageView', 'views/fileView', 'views/selectionView'], + function($, Backbone, _, App, TreeCollection, packageView, fileView, selectionView) { // Renders whole PackageView return Backbone.View.extend({ @@ -12,17 +13,27 @@ define(['jquery', 'backbone', 'underscore', 'app', 'models/TreeCollection', 'vie //