Index: main/webapp/application/engageConfig.json =================================================================== --- main/webapp/application/engageConfig.json (revision 8931) +++ main/webapp/application/engageConfig.json (working copy) @@ -5,6 +5,8 @@ includesPrefix: "kettle/", loaderFunction: "fluid.engage.initEngageApp", queryURLTemplate: "http://titan.atrc.utoronto.ca:5984/%dbName/_fti/lucene/%view?include_docs=true&q=%query", +viewURLTemplate: "http://titan.atrc.utoronto.ca:5984/%dbName/%view", +viewURLTemplateWithKey: "http://titan.atrc.utoronto.ca:5984/%dbName/%view?key=\"%key\"", initServices: [ "fluid.artifactView.initMarkupFeed", "fluid.artifactView.initDataFeed", @@ -12,11 +14,17 @@ "fluid.browseDemo.initBrowseDataFeed", "fluid.engageDemo.initEngageDemo", "fluid.kettleDemo.initCherryDemo", - "fluid.kettleDemo.initJSGIHandlerDemo" + "fluid.kettleDemo.initJSGIHandlerDemo", + "fluid.exhibitionService.initExhibitionsService", + "fluid.exhibitionService.initExhibitionsDataFeed", + "fluid.exhibitionService.initExhibitionViewService", + "fluid.exhibitionService.initExhibitionViewDataFeed" ], views: { all: "all", - byCollectionCategory: "by_collection_category" + byCollectionCategory: "by_collection_category", + exhibitionByTitle: "_design/exhibitions/_view/view", + exhibitions: "_design/exhibitions/_view/browse" }, mount: { infusion: { Index: main/webapp/kettle/KettleIncludes.json =================================================================== --- main/webapp/kettle/KettleIncludes.json (revision 8931) +++ main/webapp/kettle/KettleIncludes.json (working copy) @@ -14,6 +14,8 @@ "js/servletJSGI.js", "../application/js/EngageApp.js", "../services/artifactView/js/artifactView.js", + "../services/exhibition/js/exhibition.js", + "../services/exhibitionView/js/exhibitionView.js", "../services/browse/js/browse.js", "../services/engageDemo/js/engageDemo.js", "$engage/framework/js/Engage.js", Index: main/webapp/services/exhibition/js/exhibition.js =================================================================== --- main/webapp/services/exhibition/js/exhibition.js (revision 0) +++ main/webapp/services/exhibition/js/exhibition.js (revision 0) @@ -0,0 +1,130 @@ +/* +Copyright 2009 University of Toronto + +Licensed under the Educational Community License (ECL), Version 2.0 or the New +BSD license. You may not use this file except in compliance with one these +Licenses. + +You may obtain a copy of the ECL 2.0 License and BSD License at +https://source.fluidproject.org/svn/LICENSE.txt +*/ + +// Declare dependencies. +/*global jQuery, fluid*/ + +fluid = fluid || {}; +fluid.exhibitionService = fluid.exhibitionService || {}; + +(function ($) { + + var errorCallback = function (XMLHttpRequest, textStatus, errorThrown) { + fluid.log("XMLHttpRequest: " + XMLHttpRequest); + fluid.log("Status: " + textStatus); + fluid.log("Error: " + errorThrown); + return [500, {"Content-Type": "text/plain"}, errorThrown]; + }; + + var ajaxCall = function (url, success, error) { + $.ajax({ + url: url, + dataType: "json", + asyn: false, + success: success, + error: error + }); + }; + + var getAjax = function (url, error) { + var data; + var success = function (returnedData, status) { + data = JSON.parse(returnedData.substring(0, returnedData.length - 1)); //BUG - Doesn't parse with last \n. + }; + ajaxCall(url, success, error); + return data; + }; + + var buildCategory = function (categoryName, categoryList) { + return { + category: fluid.stringTemplate(categoryName + " (%num)", {num: categoryList.length}), + listOptions: { + links: categoryList + } + }; + }; + + var compileDatabaseURL = function (params, config) { + return fluid.stringTemplate(config.viewURLTemplate, + {dbName: params.db + "_exhibitions" || "", view: config.views.exhibitions}); + }; + + var compileTargetURL = function (URLBase, params) { + return URLBase + "?" + $.param(params); + }; + + var getData = function (errorCallback, params, config) { + var url = compileDatabaseURL(params, config); + var rawData = getAjax(url, errorCallback); + var dbName = params.db + "_exhibitions"; + var baseExhibitionURL = "view.html"; + var data = fluid.transform(rawData.rows, function (value) { + return fluid.engage.mapModel(value, dbName); + }); + var currentExhibitions = $.map(data, function (value) { + return value.isCurrent === "yes" ? { + target: compileTargetURL(baseExhibitionURL, { + db: dbName, + title: value.title + }), + image: value.image, + title: value.title, + description: value.displayDate === "Permanent exhibition" ? "Permanent" : "Through " + value.endDate + } : null; + }); + var upcomingExhibitions = $.map(data, function (value) { + return value.isCurrent === "no" ? { + target: compileTargetURL(baseExhibitionURL, { + db: dbName, + title: value.title + }), + image: value.image, + title: value.title, + description: value.displayDate + } : null; + }); + var model = { + strings: { + title: "Exhibitions" + }, + useCabinet: true, + lists: [ + buildCategory("Current Exhibitions", currentExhibitions), + buildCategory("Upcoming Exhibitions", upcomingExhibitions) + ] + }; + return JSON.stringify(model); + }; + + fluid.exhibitionService.initExhibitionsDataFeed = function (config, app) { + var exhibitionsDataHandler = function (env) { + return [200, {"Content-Type": "text/plain"}, getData(errorCallback, env.urlState.params, config)]; + }; + + var acceptor = fluid.engage.makeAcceptorForResource("browse", "json", exhibitionsDataHandler); + fluid.engage.mountAcceptor(app, "exhibitions", acceptor); + }; + + fluid.exhibitionService.initExhibitionsService = function (config, app) { + var handler = fluid.engage.mountRenderHandler({ + config: config, + app: app, + target: "exhibitions/", + source: "components/browse/html/", + sourceMountRelative: "engage" + }); + + handler.registerProducer("browse", function (context, env) { + return {}; + }); + + }; +})(jQuery); \ No newline at end of file Index: main/webapp/services/exhibitionView/js/exhibitionView.js =================================================================== --- main/webapp/services/exhibitionView/js/exhibitionView.js (revision 0) +++ main/webapp/services/exhibitionView/js/exhibitionView.js (revision 0) @@ -0,0 +1,98 @@ +/* +Copyright 2009 University of Toronto + +Licensed under the Educational Community License (ECL), Version 2.0 or the New +BSD license. You may not use this file except in compliance with one these +Licenses. + +You may obtain a copy of the ECL 2.0 License and BSD License at +https://source.fluidproject.org/svn/LICENSE.txt +*/ + +// Declare dependencies. +/*global jQuery, fluid*/ + +fluid = fluid || {}; +fluid.exhibitionService = fluid.exhibitionService || {}; + +(function ($) { + + var errorCallback = function (XMLHttpRequest, textStatus, errorThrown) { + fluid.log("XMLHttpRequest: " + XMLHttpRequest); + fluid.log("Status: " + textStatus); + fluid.log("Error: " + errorThrown); + return [500, {"Content-Type": "text/plain"}, errorThrown]; + }; + + var compileDatabaseURL = function (params, config) { + return fluid.stringTemplate(config.viewURLTemplateWithKey, + {dbName: params.db || "", view: config.views.exhibitionByTitle, key: params.title.replace(/\+/g, "%20")}); + }; + + var ajaxCall = function (url, success, error) { + $.ajax({ + url: url, + dataType: "json", + asyn: false, + success: success, + error: error + }); + }; + + var getAjax = function (url, error) { + var data; + var success = function (returnedData, status) { + data = JSON.parse(returnedData.substring(0, returnedData.length - 1)); + }; + ajaxCall(url, success, error); + return data; + }; + + var getData = function (errorCallback, params, config) { + var url = compileDatabaseURL(params, config); + var rawData = getAjax(url, errorCallback); + var exhibitionData = fluid.engage.mapModel(rawData.rows[0], params.db + "_view"); + return JSON.stringify({ + model: exhibitionData, + exhibitionCabinet: { + lists: [ + { + category: fluid.stringTemplate("Show Guest's book (%num comments)", {num: 5}), + listOptions: { + links: {} + } + }, { + category: fluid.stringTemplate("Show Audio and View (%num)", {num: 3}), + listOptions: { + links: {} + } + } + ] + } + }); + }; + + fluid.exhibitionService.initExhibitionViewDataFeed = function (config, app) { + var exhibitionViewDataHandler = function (env) { + return [200, {"Content-Type": "text/plain"}, getData(errorCallback, env.urlState.params, config)]; + }; + + var acceptor = fluid.engage.makeAcceptorForResource("view", "json", exhibitionViewDataHandler); + fluid.engage.mountAcceptor(app, "exhibitions", acceptor); + }; + + fluid.exhibitionService.initExhibitionViewService = function (config, app) { + var handler = fluid.engage.mountRenderHandler({ + config: config, + app: app, + target: "exhibitions/", + source: "components/exhibition/html/", + sourceMountRelative: "engage" + }); + + handler.registerProducer("view", function (context, env) { + return {}; + }); + + }; +})(jQuery); \ No newline at end of file