From 58d60aedee380501181be56eb76083cc0e325bc1 Mon Sep 17 00:00:00 2001 From: Rufus Pollock Date: Tue, 5 Jun 2012 20:30:33 +0100 Subject: [PATCH] [build][xs]: build ckanjs.js. --- pkg/ckanjs.js | 61 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 52 insertions(+), 9 deletions(-) diff --git a/pkg/ckanjs.js b/pkg/ckanjs.js index 0559aea..c2d2ebc 100644 --- a/pkg/ckanjs.js +++ b/pkg/ckanjs.js @@ -264,7 +264,9 @@ this.CKAN.Client = (function (CKAN, $, _, Backbone, undefined) { }); // TODO: exclude the group we filtered by ... var groupObjs = _.map(groups, function(groupInfo) { - return self.getGroupById(groupInfo.id); + var group = self.getGroupById(groupInfo.id); + group.set({filtered_dataset_count: groupInfo.count}); + return group; }); return groupObjs; } @@ -629,6 +631,7 @@ CKAN.Model = function ($, _, Backbone, undefined) { var showdown = new Showdown.converter(); out.descriptionHTML = showdown.makeHtml(description ? description : ''); out.snippet = this.makeSnippet(out.descriptionHTML); + out.dataset_count = this.get('filtered_dataset_count') || this.get('packages').length; return out; }, @@ -641,6 +644,12 @@ CKAN.Model = function ($, _, Backbone, undefined) { } }); + Model.GroupCollection = Backbone.Collection.extend({ + constructor: function GroupCollection(models, options) { + Backbone.Collection.prototype.constructor.apply(this, arguments); + } + }); + // Collection for managing results from the CKAN search API. An additional // `options.total` parameter can be provided on initialisation to // indicate how many models there are on the server in total. This can @@ -683,8 +692,8 @@ CKAN.UI = function($) { apiKey: '' }; - var config = options.config || defaultConfig; - this.client = new CKAN.Client(config); + this.config = options.config || defaultConfig; + this.client = new CKAN.Client(this.config); if (options.fixtures && options.fixtures.datasets) { $.each(options.fixtures.datasets, function(idx, obj) { var collection = self.client.cache.dataset; @@ -718,7 +727,7 @@ CKAN.UI = function($) { var configView = new CKAN.View.ConfigView({ el: $('#config-page'), - config: config + config: this.config }); $(document).bind('config:update', function(e, cfg) { self.client.configure(cfg); @@ -822,11 +831,6 @@ CKAN.UI = function($) { } }); - my.initialize = function(options) { - my.workspace = new my.Workspace(options); - Backbone.history.start() - }; - return my; }(jQuery); @@ -1477,6 +1481,45 @@ Handlebars.registerHelper('eachkeys', function(context, options) { var CKAN = CKAN || {}; CKAN.View = CKAN.View || {}; +(function(my, $) { + +my.GroupSummaryList = Backbone.View.extend({ + className: 'groups list', + + template: '\ + {{#groups}} \ +
\ +
\ +

\ + {{title}} \ +

\ +

{{snippet}}

\ + Datasets {{dataset_count}} \ +
\ +
\ + {{/groups}} \ + ', + + initialize: function() { + this.el = $(this.el); + _.bindAll(this, 'render'); + this.collection.bind('change', this.render); + }, + + render: function() { + var tmplData = { + groups: this.collection.map(function(x) { return x.toTemplateJSON()}) + }; + var html = Mustache.render(this.template, tmplData); + this.el.html(html); + } +}); + +}(CKAN.View, jQuery)); + +var CKAN = CKAN || {}; +CKAN.View = CKAN.View || {}; + (function(my, $) { // Flash a notification message //