From 696d1d9e680bfb287e5347134768f5d0e8c10567 Mon Sep 17 00:00:00 2001 From: Jason Skomorowski Date: Fri, 22 Aug 2014 20:36:05 -0400 Subject: [PATCH] Details widget --- src/mkws-team.js | 8 ++++++++ src/mkws-widget-main.js | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/mkws-team.js b/src/mkws-team.js index 4dccde4..ead2f03 100644 --- a/src/mkws-team.js +++ b/src/mkws-team.js @@ -46,6 +46,7 @@ function team($, teamName) { that.currentRecordId = function() { return m_currentRecordId; }; that.currentRecordData = function() { return m_currentRecordData; }; that.filters = function() { return m_filterSet; }; + that.gotRecords = function() { return m_gotRecords; }; // Accessor methods for individual widgets: writers that.set_sortOrder = function(val) { m_sortOrder = val }; @@ -149,6 +150,7 @@ function team($, teamName) { log("record"); // FIXME: record is async!! clearTimeout(m_paz.recordTimer); + queue("record").publish(data); var detRecordDiv = findnode(recordDetailsId(data.recid[0])); if (detRecordDiv.length) { // in case on_show was faster to redraw element @@ -303,6 +305,12 @@ function team($, teamName) { m_paz.search(m_query, m_perpage, m_sortOrder, pp2filter, undefined, params); } + // fetch record details to be retrieved from the record queue + that.fetchDetails = function(recId) { + log("fetchDetails() requesting record '" + recId + "'"); + m_paz.record(recId); + }; + // switching view between targets and records function switchView(view) { diff --git a/src/mkws-widget-main.js b/src/mkws-widget-main.js index 1ea1835..fce4779 100644 --- a/src/mkws-widget-main.js +++ b/src/mkws-widget-main.js @@ -86,6 +86,25 @@ mkws.registerWidgetType('Pager', function() { }); }); +mkws.registerWidgetType('Details', function() { + var that = this; + var recid = that.node.attr("data-mkws-recid"); + if (this.team.gotRecords()) { + that.team.fetchDetails(recid); + } else { + this.team.queue("firstrecords").subscribe(function() { + that.team.fetchDetails(recid); + }); + } + this.team.queue("record").subscribe(function(data) { + console.log(data); + if ($.inArray(recid, data.recid) > -1) { + var template = that.team.loadTemplate(that.config.template || "Record"); + that.node.html(template(data)); + } + }); + that.autosearch(); +}); mkws.registerWidgetType('Records', function() { var that = this; -- 1.7.10.4