-function team($, teamName) {
- var that = {};
- var m_teamName = teamName;
- var m_submitted = false;
- var m_query; // initially undefined
- var m_sortOrder; // will be set below
- var m_perpage; // will be set below
- var m_filterSet = filterSet(that);
- var m_totalRecordCount = 0;
- var m_currentPage = 1;
- var m_currentRecordId = '';
- var m_currentRecordData = null;
- var m_logTime = {
- // Timestamps for logging
- "start": $.now(),
- "last": $.now()
- };
- var m_paz; // will be initialised below
- var m_tempateText = {}; // widgets can register tempates to be compiled
- var m_template = {}; // compiled templates, from any source
- var m_config = mkws.objectInheritingFrom(mkws.config);
- var m_widgets = {}; // Maps widget-type to object
-
- that.toString = function() { return '[Team ' + teamName + ']'; };
-
- // Accessor methods for individual widgets: readers
- that.name = function() { return m_teamName; };
- that.submitted = function() { return m_submitted; };
- that.sortOrder = function() { return m_sortOrder; };
- that.perpage = function() { return m_perpage; };
- that.totalRecordCount = function() { return m_totalRecordCount; };
- that.currentPage = function() { return m_currentPage; };
- that.currentRecordId = function() { return m_currentRecordId; };
- that.currentRecordData = function() { return m_currentRecordData; };
- that.filters = function() { return m_filterSet; };
- that.config = function() { return m_config; };
-
- // Accessor methods for individual widgets: writers
- that.set_sortOrder = function(val) { m_sortOrder = val };
- that.set_perpage = function(val) { m_perpage = val };
-
-
- // The following PubSub code is modified from the jQuery manual:
- // http://api.jquery.com/jQuery.Callbacks/
- //
- // Use as:
- // team.queue("eventName").subscribe(function(param1, param2 ...) { ... });
- // team.queue("eventName").publish(arg1, arg2, ...);
- //
- var queues = {};
- function queue(id) {
- if (!queues[id]) {
- var callbacks = $.Callbacks();
- queues[id] = {
- publish: callbacks.fire,
- subscribe: callbacks.add,
- unsubscribe: callbacks.remove
- };
- }
- return queues[id];
- };
- that.queue = queue;
-
+// Before the team can be used for searching and related operations,
+// its pz2 object must be created by calling team.makePz2().
+//
+mkws.makeTeam = function($, teamName) {
+ var that = {};
+
+ // Member variables are separated into two categories
+
+ // 1. Persistent state (to be coded in URL fragment)
+ var m_state = {
+ query: null, // initially undefined
+ sort: null, // will be set below
+ size: null, // will be set below
+ page: 1,
+ recid: '',
+ filters: filterSet(that)
+ }
+
+ // 2. Internal state (not to be coded)
+ var m_teamName = teamName;
+ var m_paz; // will be initialised below
+ var m_submitted = false;
+ var m_totalRecordCount = 0;
+ var m_currentRecordData = null;
+ var m_logTime = {
+ // Timestamps for logging
+ "start": $.now(),
+ "last": $.now()
+ };
+ var m_templateText = {}; // widgets can register templates to be compiled
+ var m_template = {}; // compiled templates, from any source
+ var m_widgets = {}; // Maps widget-type to array of widget objects
+ var m_gotRecords = false;
+
+ var config = mkws.objectInheritingFrom(mkws.config);
+ that.config = config;
+
+ that.toString = function() { return '[Team ' + teamName + ']'; };
+
+ // Accessor methods for individual widgets: readers
+ that.name = function() { return m_teamName; };
+ that.submitted = function() { return m_submitted; };
+ that.sortOrder = function() { return m_state.sort; };
+ that.perpage = function() { return m_state.size; };
+ that.query = function() { return m_state.query; };
+ that.totalRecordCount = function() { return m_totalRecordCount; };
+ that.currentPage = function() { return m_state.page; };
+ that.currentRecordId = function() { return m_state.recid; };
+ that.currentRecordData = function() { return m_currentRecordData; };
+ that.filters = function() { return m_state.filters; };
+ that.gotRecords = function() { return m_gotRecords; };
+
+ // Accessor methods for individual widgets: writers
+ that.set_sortOrder = function(val) { m_state.sort = val };
+ that.set_perpage = function(val) { m_state.size = val };
+
+ m_state.sort = config.sort_default;
+ m_state.size = config.perpage_default;
+
+ var m_default = $.extend(true, {}, m_state);
+ var tmp = m_default.filters;
+ delete m_default.filters;
+ $.extend(m_default, tmp.fragmentItems());
+
+ that.urlFragment = function() {
+ var s;
+
+ // Expand the filterSet into a set of key=value properties
+ var state = $.extend(true, {}, m_state);
+ var tmp = state.filters;
+ delete state.filters;
+ $.extend(state, tmp.fragmentItems());
+
+ for (var key in state) {
+ if (state.hasOwnProperty(key) &&
+ state[key] != m_default[key]) {
+ if (!s) {
+ var s = 'mkws';
+ if (m_teamName !== 'AUTO') s += m_teamName;
+ s += '=';
+ } else {
+ s += "@";
+ }