diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 549dcd06b247012c6a1c2d4c78dae595742d72bc..0000000000000000000000000000000000000000 --- a/.gitignore +++ /dev/null @@ -1,11 +0,0 @@ -components -.idea -.settings -.classpath -.project -tags -*.swp -*.iml -*.sublime-project -*.sublime-workspace -config/config.js diff --git a/README.md b/README.md deleted file mode 100644 index 7c85db9fa92abab0d370b09b460d58888a18b91d..0000000000000000000000000000000000000000 --- a/README.md +++ /dev/null @@ -1,19 +0,0 @@ -Nesstar Touch -============= - -This is the front end part of a mobile web app for accessing Nesstar -repositories. It depends on the NesstarDrop project as the backend. - -To get it up and running ------------------------- - - $ Install bower (With NPM: `npm install -g bower`) - $ Install dependencies: `bower install` - $ rename `config/config.js.example` to `config.js` and edit to suit your setup - $ open index.html in you favourite broser (preferrably Chrome ;) - -If your REST server expects a namespace on the URL path (such as -`/api/study/list` instead of `/study/list`), add it to the -`config/config.js`file. You can specify either a namespace (`/api`) or a URL -(`http://my-host:8080/api`). - diff --git a/bower.json b/bower.json deleted file mode 100644 index a3b8cf6a61fd99bd9a208e7132cc6dbfb08545fc..0000000000000000000000000000000000000000 --- a/bower.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "name": "NesstarTouch", - "version": "0.0.1", - "ignore": [ - "**/.*", - "node_modules", - "components" - ], - "dependencies": { - "dojo": "1.9.0rc2", - "dojox": "1.9.0rc2", - "dijit": "1.9.0rc2" - } -} diff --git a/config/config.js.example b/config/config.js.example deleted file mode 100644 index 1b19d924d41df17d4fa505986d4c309ca64b0306..0000000000000000000000000000000000000000 --- a/config/config.js.example +++ /dev/null @@ -1,5 +0,0 @@ -window.config = { - baseUrl: 'http://129.177.92.208/api/', - useAlternativeConsole: false -} - diff --git a/css/overlay.css b/css/overlay.css deleted file mode 100644 index d4e9b936d5ac80f6a0e54fe0646a0f008fff732b..0000000000000000000000000000000000000000 --- a/css/overlay.css +++ /dev/null @@ -1,21 +0,0 @@ -@charset 'UTF-8'; -.pageOverlay { - position: absolute; - width: 100%; - z-index: 1001; - display: block; - top: 0; left: 0; right: 0; bottom: 0; -} - -#splash { - background: #fff url('../components/dijit/themes/claro/images/loadingAnimation.gif') no-repeat 50% 50%; -} - -#splash p { - position: absolute; - bottom: 40%; - font-family: Helvetica, Arial, verdana, sans-serif; - width: 100%; - text-align: center; - color: #999; -} diff --git a/css/style.css b/css/style.css deleted file mode 100644 index a211338405052b5e74219e4019aa61921537c557..0000000000000000000000000000000000000000 --- a/css/style.css +++ /dev/null @@ -1,233 +0,0 @@ -@charset 'UTF-8'; -.scrollable-view { - overflow: auto; - -webkit-overflow-scrolling: touch; -} - -.search-enabled-list { - display: block; - float: none; - margin-top: 2.5em; -} - -.text-view { - padding: 0 0.25em; -} - -#table { - margin: 18px; -} - -#table table, #table td { - border: 1px solid #333; - border-collapse: collapse; -} - -#table .stub { - text-align: left; -} - -#table .header { - text-align: center; -} - -#table .cell { - text-align: right; -} - -#table td { - padding: 4px; -} - -.dragging-avatar { - position: fixed; - height: 43px; - line-height: 43px; - font-weight: bold; - padding-left: 1em; - background-color: #fff; - border: 1px solid #adaaad; - border-radius: 8px; - box-shadow: 4px 4px 4px #888; -} - -.droppable { - border-color: blue; -} - -.hovered { - border-color: #51cbee; -} - -.disabled { - color: #ddd; -} - -.positionIndicator { - height: 1px; - background-color: #51cbee; - list-style-type: none; - @include box-shadow(0 0 2px #51cbee); - @include transition(all, 0.30s, ease-in-out); -} - -.search-box { - font-size: 1.2em; - width: 100%; -} - -.search-box-pane { - position: relative; - padding: 0.6em; - display: block; -} - -.moreButton { - display: block; - width: 12em; - margin: 1em auto; -} - -.variableMetadataText { - width: 100%; - table-layout: fixed; -} - -.variableMetadataText th { - font-weight: normal; - text-align: left; -} - -.variableMetadataText, .variableMetadataText td { - border: none; -} - -.variableMetadataText td { - text-overflow: ellipsis; - overflow: hidden; -} - -.variableMetadataText th, .variableMetadataText td { - padding: .1em .5em .1em 0; -} - -.variableMetadataText td { - white-space: nowrap; -} - -.variableMetadataText .catValu { - width: 15%; -} - -.variableMetadataText .catStat { - width: 15%; - text-align: right; -} - -.variableMetadataText .labl { - max-width: 60%; -} - -.variableMetadataText .bars { - width: 40%; -} - -.variableMetadataText .bar-wrapper { - font-size: 80%; -} - -.variableMetadataText .bar { - display: block; - float: left; - margin-right: .1em; - background-color: rgb(40,130,190); - border-bottom: 1px solid #555; - border-right: 1px solid #555; - border-top: 1px solid #eee; - border-left: 1px solid #eee; - border-top-right-radius: 5px; - border-bottom-right-radius: 5px; - height: 1em; -} - - -table.metadataText, table.metadataText th{ - border: 1px solid grey; - border-collapse: collapse; - text-align: center; -} - -table.metadataText td { - border: 1px solid grey; - border-collapse: collapse; - text-align: left; - padding: .1em; -} - -table.metadataText th { - background-color: #dedede; - padding: .1em; -} - - -img.mblListItemRightIcon { - border-left: 1px solid grey; - margin: 0; -} - -.mblRoundRectCategory { - white-space : normal; - margin-left: 2px; -} - -.text-view .mblRoundRectCategory { - margin-left: 0; -} - -.mblAccordionTitle { - height: 2.7em; - line-height: 2.7em; -} - -#studyListData .mblVariableHeight { - padding: 0 0 0 8px; -} - -#variables .mblListItem { - padding: 0 0 0 8px; -} - -#gototop { - visibility: hidden; - z-index: 1; - position: fixed; - left: 10px; - bottom: 10px; - text-decoration: none; - color: #bbb; - - /* transition */ - -webkit-transition: 1s; - -moz-transition: 1s; - transition: 1s; - padding: 10px; -} - -/* arrow icon (span tag) */ -#gototop span { - width: 70px; - height: 70px; - display: block; - margin-bottom: 7px; - background: #ddd url(../images/up-arrow.png) no-repeat center center; - - /* rounded corners */ - -webkit-border-radius: 15px; - -moz-border-radius: 15px; - border-radius: 15px; - - /* transition */ - -webkit-transition: 1s; - -moz-transition: 1s; - transition: 1s; -} \ No newline at end of file diff --git a/images/apple-touch-icon.png b/images/apple-touch-icon.png deleted file mode 100644 index 46334adb73f7484335f241bc81f6edda6077b88a..0000000000000000000000000000000000000000 Binary files a/images/apple-touch-icon.png and /dev/null differ diff --git a/images/detail.png b/images/detail.png deleted file mode 100644 index 2ad94bfaa5d7018958ac35dfe656c95d60f03e7f..0000000000000000000000000000000000000000 Binary files a/images/detail.png and /dev/null differ diff --git a/images/smalln1.ico b/images/smalln1.ico deleted file mode 100644 index a498999323da2556acff489c869b3148b99d6d68..0000000000000000000000000000000000000000 Binary files a/images/smalln1.ico and /dev/null differ diff --git a/images/up-arrow.png b/images/up-arrow.png deleted file mode 100644 index 9519f72972d90928c6e60cfdf1281e13f4c422d3..0000000000000000000000000000000000000000 Binary files a/images/up-arrow.png and /dev/null differ diff --git a/index.html b/index.html index 93fa28b7d5d2b0bb22b81586b75cd47699db7fc5..7884283ed3180e37146c0d3b683f960c3d0e08cb 100644 --- a/index.html +++ b/index.html @@ -1,262 +1,41 @@ - - - - - - - - Nesstar Touch: - - - - - - - -

Loading...

-
- - - - - - - -
-

- - Select Study -

- -
- -
- - - -
- - -
-

- - Study Metadata -

-
-
- - -
-

- Settings - -

-

-
-
-
- - -
-

- - Variable Metadata -

-
-
- - -
-

- Tabulation -

- -
- - - -
-
-

Tabulation Data Type

-
    -
  • Tabulation Data type
  • -
-
- -

Row Variables

-
    - -

    Column Variables

    -
      - -

      Measure Variable

      -
        -
        - - -
        -

        Correlation Variables

        -
          -
          - - -
          -

          Dependent Variable

          -
            - -

            Independent Variables

            -
              -
              -
              -
              - - -
              -

              - Select Analysis Type -

              - -
              - - -
              -

              - Select Tabulation Data Type -

              - -
              - - -
              -

              - Back - Select Display Options -

              - -
              - - -
              -

              - Select Measure Type -

              - -
              - - -
              -

              - Cancel -

              - -
              - -
              - -
              - -
              - - -
              - -
              -
              Alert
              -
              - -
              - - + + + + Nesstar Touch Testing + + + + + +
              + +
              + +
              + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/js/AnalysisTypeList.js b/js/AnalysisTypeList.js deleted file mode 100644 index 6d6cb08caba6a8a684cd4dabf1d351e1c58a0d74..0000000000000000000000000000000000000000 --- a/js/AnalysisTypeList.js +++ /dev/null @@ -1,53 +0,0 @@ -/*global define */ -define(['dojo/_base/declare', - 'dojo/_base/array', - 'dojo/topic', - 'dojox/mobile/ListItem', - 'dojox/mobile/RoundRectList'], function (declare, arrayUtils, topic, ListItem, RoundRectList) { - return declare('nesstartouch.AnalysisTypeList', [RoundRectList], { - startup: function () { - this.inherited(arguments); - - arrayUtils.forEach(this._types, function (someType, index) { - var checked = index === this._defaultType, - item = { - 'label': someType, - 'moveTo': '#settings', - 'transitionDir': -1, - 'noArrow': true, - 'checked': checked, - 'analysisType': someType, - onClick: function (obj) { - obj.checked = true; - window.nesstartouch.analysisType = this.analysisType; - } - }; - this.addChild(new ListItem(item)); - }, this); - }, - - markSelectedAnalysisType: function () { - console.log("marking analysis type"); - var selectedType = window.nesstartouch.analysisType; - if (selectedType === undefined) { - return; - } - - arrayUtils.forEach(this.getChildren(), function (child) { - if (child.analysisType === selectedType) { - console.log("marked", child); - child.checked = true; - } - }); - }, - - getDefaultAnalysisType: function () { - return this._types[this._defaultType]; - }, - - - _defaultType : 0, // tabulation - - _types : ['Tabulation', 'Regression', 'Correlation'] - }); -}); diff --git a/js/CorrelationBuilder.js b/js/CorrelationBuilder.js deleted file mode 100644 index dab56560d4536476f9d22846b573168b41b64197..0000000000000000000000000000000000000000 --- a/js/CorrelationBuilder.js +++ /dev/null @@ -1,123 +0,0 @@ -/*global define */ -define(['dojo/_base/declare', - 'dojo/_base/array', - 'dojox/lang/functional', - 'dojox/mobile/RoundRectCategory', - 'dojo/dom-construct', - 'nesstartouch/_RestMixin', - "dojox/charting/axis2d/Default"], function (declare, arrayUtil, functional, RoundRectCategory, domConstruct, _RestMixin) { - "use strict"; - return declare('nesstartouch.CorrelationBuilder', [_RestMixin], { - html: "", - rowVariables: [], - columnVariables: [], - idLabelMaps: [], - displayOptions: [], - - constructor: function (correlationData, idLabelMaps, displayOptions) { - var table = domConstruct.create("table"); - this.idLabelMaps = idLabelMaps; - this.displayOptions = displayOptions; - this.rowVariables = []; - this.columnVariables = []; - this._extractRowColumnVariables(correlationData.resultValuesMap); - this._createCorrelationTable(correlationData.resultValuesMap, table); - this.html = table.outerHTML; - }, - - _extractRowColumnVariables: function (data) { - var self = this; - functional.forIn(data, function (value, key) { - self._divideVariablesInKey(key); - }); - }, - - _divideVariablesInKey: function (key) { - var variable = key.split("|"); - if (-1 === this.rowVariables.indexOf(variable[0])) { - this.rowVariables.push(variable[0]); - } - - if (-1 === this.columnVariables.indexOf(variable[1])) { - this.columnVariables.push(variable[1]); - } - }, - - _createCorrelationTable: function (correlationData, table) { - this._createCorrelationTableHead(table); - this._createCorrelationTableBody(correlationData, table); - }, - - _createCorrelationTableHead: function (table) { - var tr = domConstruct.create("tr", null, table), - self = this; - - domConstruct.create("td", null, tr); - if (0 !== this.displayOptions.length) { - domConstruct.create("td", null, tr); - } - arrayUtil.forEach(this.rowVariables, function (variableId) { - domConstruct.create("td", {innerHTML: self.idLabelMaps[variableId], 'class': 'header label'}, tr); - }); - }, - - _createCorrelationTableBody: function (correlationData, table) { - var self = this; - - arrayUtil.forEach(this.columnVariables, function (variableId) { - self._createOneColumnTable(correlationData, variableId, table); - }); - }, - - _createOneColumnTable: function (correlationData, variableId, table) { - var tr = domConstruct.create("tr", null, table), - self = this; - - domConstruct.create("td", {innerHTML: this.idLabelMaps[variableId], rowspan: this.displayOptions.length + 1, 'class': 'stub label'}, tr); - - if (0 !== this.displayOptions.length) { - domConstruct.create("td", {innerHTML: "Correlation", 'class': 'stub label'}, tr); - } - this._createOneOptionColumn(correlationData, variableId, "Correlation", tr); - - arrayUtil.forEach(this.displayOptions, function (option) { - var extraTr = domConstruct.create("tr", null, table); - domConstruct.create("td", {innerHTML: option, 'class': 'stub label'}, extraTr); - self._createOneOptionColumn(correlationData, variableId, option, extraTr); - }); - }, - - _createOneOptionColumn: function (correlationData, variableId, option, tr) { - var self = this; - arrayUtil.forEach(this.rowVariables, function (rowVariableId) { - var temp = correlationData[rowVariableId + "|" + variableId]; - if (undefined !== temp) { - domConstruct.create("td", {innerHTML: self._showFourDigits(temp[self._types[option]]), 'class': 'cell'}, tr); - } else { - domConstruct.create("td", {innerHTML: "-", 'class': 'cell'}, tr); - } - }); - }, - - _showFourDigits: function (value) { - var res; - if (!this.isIntAndString(value)) { - res = value.toFixed(4); - } else { - res = value; - } - - return res; - }, - - isIntAndString: function (n) { - return (typeof n === 'number' && n % 1 === 0) || (typeof n === 'string'); - }, - - _types: { - "Correlation": "correlationCoefficient", - "Significance": "significance", - "Count": "caseCount", - }, - }); -}); diff --git a/js/CorrelationDisplayOptions.js b/js/CorrelationDisplayOptions.js deleted file mode 100644 index f331602e2b16296921d657e0e4f315f54003548b..0000000000000000000000000000000000000000 --- a/js/CorrelationDisplayOptions.js +++ /dev/null @@ -1,60 +0,0 @@ -/*global define */ -define(['dojo/_base/declare', - 'dojo/_base/array', - 'dijit/registry', - 'dojox/mobile/ListItem', - 'dojox/mobile/RoundRectList'], function (declare, arrayUtils, registry, ListItem, RoundRectList) { - return declare('nesstartouch.correlationDisplayOptions', [RoundRectList], { - startup: function () { - var self = this, - parent = this.getParent(); - - this.inherited(arguments); - - arrayUtils.forEach(this._types, function (someType, index) { - var item = { - 'label': someType, - 'noArrow': true, - 'displayOption': someType, - onClick: function (obj) { - obj.checked = true; - if (!window.nesstartouch.correlation) { - window.nesstartouch.correlation = {}; - } - } - }; - this.addChild(new ListItem(item)); - }, this); - - parent.onBeforeTransitionIn = function () { - self.markSelectedAnalysisType(); - }; - - parent.onBeforeTransitionOut = function () { - window.nesstartouch.correlation.displayOptions = []; - var displayOptions = window.nesstartouch.correlation.displayOptions; - - arrayUtils.forEach(self.getChildren(), function (child) { - if (child.checked) { - displayOptions.push(child.label); - } - }); - }; - }, - - markSelectedAnalysisType: function () { - var displayOptions = window.nesstartouch.correlation.displayOptions; - if (displayOptions === undefined) { - return; - } - - arrayUtils.forEach(this.getChildren(), function (child) { - if (-1 !== displayOptions.indexOf(child.displayOption)) { - child.checked = true; - } - }); - }, - - _types : ['Significance', 'Count'], - }); -}); diff --git a/js/DragAndDrop.js b/js/DragAndDrop.js deleted file mode 100644 index 983001489634da517a97526e2bf09c4fc33a9e32..0000000000000000000000000000000000000000 --- a/js/DragAndDrop.js +++ /dev/null @@ -1,409 +0,0 @@ -/*global define, settings */ -define(['dojo/_base/declare', - 'dojo/_base/lang', - 'dojo/on', - 'dojo/dom', - 'dojo/dom-style', - 'dijit/registry', - 'dojo/_base/array', - 'dojo/touch', - 'dojox/gesture/tap', - 'dojo/dom-geometry', - 'dojo/dom-style', - 'dojo/dom-class', - 'dojo/dom-construct', - 'dojo/query', - 'nesstartouch/_VariableMixin', - 'nesstartouch/DragAndDropAvatar', - 'dojo/_base/window'], function (declare, lang, on, dom, domStyle, registry, arrayUtils, touch, tap, geometry, style, domClass, domConstruct, query, _VariableMixin, Avatar, win) { - "use strict"; - return declare('nestartouch.DragAndDrop', [_VariableMixin], { - _draggables: [], - _droppables: [], - - constructor: function () { - if (window.nesstartouch.drag === undefined) { - window.nesstartouch.drag = {}; - } - this._registerGlobalHandlers(); - }, - - registerDraggable: function (arg) { - this._populateList(this._draggables, arg, this._registerDragEvents); - return this; - }, - - registerDroppable: function (arg) { - this._populateList(this._droppables, arg, function () {}); - return this; - }, - - _registerGlobalHandlers: function () { - var moveHandlerWithContext = lang.hitch(this, this._moveHandler), - releaseHandlerWithContext = lang.hitch(this, this._releaseHandler); - - document.addEventListener('touchmove', moveHandlerWithContext, false); - document.addEventListener('touchend', releaseHandlerWithContext); - }, - - _populateList: function (listToPopulate, fromList, registerEventsCallback) { - var nodeList, node; - if (this._objectIsArray(fromList)) { - nodeList = this._ensureListContainsNodes(fromList); - registerEventsCallback(nodeList, this); - listToPopulate = listToPopulate.concat(nodeList); - } else { - node = (typeof fromList === 'object') ? fromList : registry.byId(fromList); - registerEventsCallback([node], this); - listToPopulate.push(node); - } - }, - - _ensureListContainsNodes: function (someList) { - return arrayUtils.map(someList, function (draggable) { - if (typeof draggable === 'String') { - return dom.byId(draggable); - } - return draggable; - }); - }, - - _objectIsArray: function (obj) { - return Object.prototype.toString.call(obj) === '[object Array]'; - }, - - _registerDragEvents: function (list, context) { - arrayUtils.forEach(list, function (draggable, index) { - this._registerSingleEvent(draggable, tap.hold, this._tapHoldHandler); - }, context); - }, - - _registerSingleEvent: function (node, eventName, callback) { - var callbackWithContext = lang.hitch(this, callback); - node.on(eventName, callbackWithContext); - }, - - _tapHoldHandler: function (holdEvent) { - var someNode = holdEvent.srcElement, - dragNode, - avatar; - - if (window.nesstartouch.drag.isDragging) { - return false; - } - - window.nesstartouch.drag.isDragging = true; - do { - if (someNode.getAttribute('data-nesstar-type') === 'addVariableList') { - console.log("Trying to drag the Add variable button, cancel drag."); - return; - } - - dragNode = someNode; - someNode = someNode.parentElement; - } while (someNode.tagName !== 'LI'); - - dragNode = someNode; - - holdEvent.stopPropagation(); - holdEvent.preventDefault(); - - avatar = new Avatar(dragNode); - window.nesstartouch.drag.draggedElement = registry.byNode(dragNode); - window.nesstartouch.drag.avatar = avatar; - this._highLightDroppables(); - }, - - _moveHandler: function (moveEvent) { - var coordinate, - avatarPosition, - droppableAreaUnderCursor; - - if (!window.nesstartouch.drag.isDragging) { - return; - } - try { - moveEvent.stopPropagation(); - moveEvent.preventDefault(); - window.nesstartouch.drag.handlingMove = true; - - coordinate = this._getCoordinateFromEvent(moveEvent); - window.nesstartouch.drag.avatar.move(coordinate); - avatarPosition = window.nesstartouch.drag.avatar.getPosition(); - - droppableAreaUnderCursor = this._getDroppableUnderCursor(avatarPosition); - if (droppableAreaUnderCursor) { - this._movePositionMarker(droppableAreaUnderCursor, coordinate); - } - } catch (err) { - console.log('An error occurred while dragging', err); - window.nesstartouch.drag.isDragging = false; - } - window.nesstartouch.drag.handlingMove = false; - }, - - _releaseHandler: function (releaseEvent) { - if (window.nesstartouch.drag.isDragging) { - try { - this._handleReleaseAfterDrag(releaseEvent); - } catch (err) { - console.log('An error occurred handling release event', err); - } - } - }, - - _handleReleaseAfterDag: function (releaseEvent) { - var touch = releaseEvent.changedTouches[0], - coordinate = this._getCoordinateFromEvent(releaseEvent), - droppable = this._getDroppableUnderCursor(coordinate); - - this._removePositionMarkersFromDroppables(); - - if (droppable) { - this._updateListsAfterDrop(droppable, coordinate); - } else { - domClass.remove(window.nesstartouch.drag.draggedElement, 'disabled'); - } - this._cleanUpAfterRelease(); - window.nesstartouch.drag.isDragging = false; - window.nesstartouch.stores.setVariableStore = true; - }, - - _updateListsAfterDrop: function (droppable, releaseEvent) { - var itemToInsertAfter = this._getItemBeforeCurrentPosition(droppable.getChildren(), releaseEvent), - oldPosition = window.nesstartouch.drag.draggedElement.listorder, - newPosition = 0, - dimensionDroppedOn, - variablesOnDroppedDimension; - - if (itemToInsertAfter.listorder !== undefined) { - newPosition = itemToInsertAfter.listorder + 1; - } - - dimensionDroppedOn = this._getDimensionItemWasDroppedOn(itemToInsertAfter); - variablesOnDroppedDimension = window.nesstartouch.stores.variableStore.query({'onDimension': dimensionDroppedOn}); - - if (window.nesstartouch.drag.draggedElement.onDimension === dimensionDroppedOn) { - this._reorderListAfterDrop(newPosition, oldPosition, variablesOnDroppedDimension); - } else { - this._reorderSourceList(); - this._reorderDestinationList(variablesOnDroppedDimension, newPosition); - window.nesstartouch.drag.draggedElement.onDimension = dimensionDroppedOn; - } - - this._writeReorderedVariablesToStore(newPosition); - this._reflectNewOrderInView(itemToInsertAfter); - }, - - _reorderListAfterDrop: function (newPosition, oldPosition, variablesOnDroppedDimension) { - this._updateIndexesOnVariableList(oldPosition, newPosition, variablesOnDroppedDimension); - window.nesstartouch.drag.draggedElement.listorder = newPosition; - }, - - - _reorderSourceList: function (oldPosition) { - var variablesOnSourceDimension = window.nesstartouch.stores.variableStore.query({'onDimension': window.nesstartouch.drag.draggedElement.onDimension}), - largestIndex = this._getLargestIndexFromList(variablesOnSourceDimension); - - this._updateIndexesOnVariableList(oldPosition, largestIndex, variablesOnSourceDimension); - }, - - _reorderDestinationList: function (variablesOnDroppedDimension, newPosition) { - var largestIndex = this._getLargestIndexFromList(variablesOnDroppedDimension); - this._updateIndexesOnVariableList(largestIndex, newPosition, variablesOnDroppedDimension); - }, - - _getLargestIndexFromList: function (list) { - var largestIndexOnDestinationDimension = -1; - list.forEach(function (item) { - largestIndexOnDestinationDimension = Math.max(largestIndexOnDestinationDimension, item.listorder); - }); - return largestIndexOnDestinationDimension; - }, - - _updateIndexesOnVariableList: function (oldPosition, newPosition, list) { - var callback, - from, - to; - - if (newPosition === oldPosition || newPosition < oldPosition) { - callback = function (variable) { - variable.listorder = variable.listorder + 1; - }; - } else { - callback = function (variable) { - variable.listorder = variable.listorder - 1; - }; - } - - from = Math.min(oldPosition, newPosition); - to = Math.max(oldPosition, newPosition); - - arrayUtils.forEach(list, function (item, index) { - if (item.listorder >= from && item.listorder <= to) { - this._updateSingleIndex(item, callback); - } - }, this); - }, - - _updateSingleIndex: function (item, callback) { - var opts = { - id: item.id, - overwrite: true - }; - - callback(item); - window.nesstartouch.stores.variableStore.put(item, opts); - }, - - _getDimensionItemWasDroppedOn: function (item) { - if (item.onDimension) { - return item.onDimension; - } - - if (item.getParent() === settings.rowVariables) { - return 'row'; - } - - return 'column'; - }, - - _highLightDroppables: function () { - arrayUtils.forEach(this._droppables, function (ul) { - domClass.add(ul.domNode, 'droppable'); - }, this); - }, - - _movePositionMarker: function (droppable, coordinate) { - this._removeHighlightingFromAllDroppables(); - domClass.add(droppable.domNode, "hovered"); - this._setPositionMarkerInList(droppable, coordinate); - }, - - _getDroppableUnderCursor: function (coordinate) { - var droppableUnderCursor; - arrayUtils.forEach(this._droppables, function (droppable) { - var geometricInfo = geometry.position(droppable.domNode); - if (this._coordinatesInsideBox(geometricInfo, coordinate)) { - droppableUnderCursor = droppable; - } - }, this); - return droppableUnderCursor; - }, - - _coordinatesInsideBox: function (box, coordinate) { - return box.x < coordinate.x && - box.y < coordinate.y && - (box.x + box.w) > coordinate.x && - (box.y + box.h) > coordinate.y; - }, - - _coordinatesInUpperHalf: function (box, coordinate) { - var halfBox = { - x: box.x, - y: box.y, - w: box.w, - h: box.h / 2 - }; - return this._coordinatesInsideBox(halfBox, coordinate); - }, - - _setPositionMarkerInList: function (droppable, coordinate) { - var itemBeforeCurrentPosition = this._getItemBeforeCurrentPosition(droppable.getChildren(), coordinate), - fauxListItem; - - if (itemBeforeCurrentPosition !== undefined) { - fauxListItem = this._getPositionMarker(droppable); - domConstruct.place(fauxListItem, itemBeforeCurrentPosition.domNode, 'after'); - } - }, - - _getItemBeforeCurrentPosition: function (items, coordinate) { - var item; - - arrayUtils.forEach(items, function (someItem, index) { - var positionInfo = geometry.position(someItem.domNode); - if (this._coordinatesInsideBox(positionInfo, coordinate)) { - if (this._coordinatesInUpperHalf(positionInfo, coordinate)) { - //Get the item before the current - but not before the very first since it's the add button - if (index <= 1) { - item = items[0]; - } else { - item = items[index - 1]; - } - } else { - //the current item is the one before - item = someItem; - } - } - }, this); - return item; - }, - - _getPositionMarker: function (droppable) { - this._removePositionMarkerFromSingleDroppable(droppable); - return domConstruct.create('li', {'class': 'positionIndicator'}); - }, - - _removePositionMarkersFromDroppables: function () { - arrayUtils.forEach(this._droppables, function (droppable) { - this._removePositionMarkerFromSingleDroppable(droppable); - }, this); - }, - - _removePositionMarkerFromSingleDroppable: function (droppable) { - var marker = query(".positionIndicator", droppable.domNode); - if (marker && marker.length > 0) { - domConstruct.destroy(marker[0]); - } - }, - - _removeHighlightingFromAllDroppables: function () { - arrayUtils.forEach(this._droppables, function (unusedDroppable) { - this._cleanUpDroppableAfterHover(unusedDroppable); - }, this); - }, - - _cleanUpDroppableAfterHover: function (droppable) { - domClass.remove(droppable.domNode, "hovered"); - this._removePositionMarkerFromSingleDroppable(droppable); - }, - - _writeReorderedVariablesToStore: function (newPosition) { - var item = this.setVariableListItemProperties(window.nesstartouch.drag.draggedElement.variable, undefined); - item.listorder = newPosition; - item.rightIcon = undefined; - item.deleteIcon = "mblDomButtonRedCircleMinus"; - item.onDimension = window.nesstartouch.drag.draggedElement.onDimension; - window.nesstartouch.stores.variableStore.put(item, { - id: window.nesstartouch.drag.draggedElement.id, - overwrite: true - }); - }, - - _reflectNewOrderInView: function (itemToInsertAfter) { - var listNode = window.nesstartouch.drag.draggedElement.domNode; - domConstruct.place(listNode, itemToInsertAfter.domNode, 'after'); - domClass.remove(listNode, "disabled"); - }, - - _cleanUpAfterRelease: function () { - query('ul', settings.studyItemsContainer.domNode).forEach(function (ul) { - domClass.remove(ul, 'droppable hovered'); - }); - window.nesstartouch.drag.avatar.destroy(); - }, - - _getCoordinateFromEvent: function (evt) { - var coordinate = {}, - touch; - - if (evt.changedTouches.length > 0) { - touch = evt.changedTouches[0]; - coordinate.x = touch.clientX; - coordinate.y = touch.clientY; - } - return coordinate; - }, - }); -}); diff --git a/js/DragAndDropAvatar.js b/js/DragAndDropAvatar.js deleted file mode 100644 index e42ddca6a1e36b23856e96de14d73aec376e5658..0000000000000000000000000000000000000000 --- a/js/DragAndDropAvatar.js +++ /dev/null @@ -1,51 +0,0 @@ -/*global define */ -define(['dojo/_base/declare', - 'dojo/dom-geometry', - 'dojo/dom', - 'dojo/dom-construct', - 'dojo/dom-style', - 'dojo/dom-class', - 'dojo/query', - 'dojo/_base/window'], function (declare, geometry, dom, domConstruct, style, domClass, query, win) { - "use strict"; - return declare('nesstartouch.Avatar', null, { - constructor: function (node) { - var nodeInfo = geometry.position(node), - label = this._createLabel(node); - - this.avatar = domConstruct.create("div", { innerHTML: label }); - domClass.add(this.avatar, 'dragging-avatar'); - style.set(this.avatar, 'width', nodeInfo.w.toString() + 'px'); - - this.move({'x': nodeInfo.x.toString(), 'y': nodeInfo.y.toString()}); - - domConstruct.place(this.avatar, win.body()); - domClass.add(node, 'disabled'); - }, - - move: function (pos) { - style.set(this.avatar, 'left', pos.x + 'px'); - style.set(this.avatar, 'top', pos.y + 'px'); - }, - - getPosition: function () { - return geometry.position(this.avatar); - }, - - destroy: function () { - domConstruct.destroy(this.avatar); - }, - - _createLabel: function (node) { - var labelNode = query(".mblListItemLabel", node), - label; - - if (labelNode && labelNode.length > 0) { - label = labelNode[0].innerHTML; - } else { - label = node.innerHTML; - } - return label; - }, - }); -}); diff --git a/js/MeasureTypeList.js b/js/MeasureTypeList.js deleted file mode 100644 index 09ea4d58d67988b581a0d5c893f1b8154065e52a..0000000000000000000000000000000000000000 --- a/js/MeasureTypeList.js +++ /dev/null @@ -1,122 +0,0 @@ -/*global define */ -define(['dojo/_base/declare', - 'dojo/_base/array', - 'dojox/mobile/ListItem', - 'dojox/mobile/RoundRectList'], function (declare, arrayUtils, ListItem, RoundRectList) { - return declare('nesstartouch.MeasureTypeList', [RoundRectList], { - startup: function () { - this.inherited(arguments); - - arrayUtils.forEach(this._types, function (someType, index) { - var checked = index === this._defaultType, - item = { - 'label': someType.label, - 'moveTo': '#settings', - 'transitionDir': -1, - 'noArrow': true, - 'checked': checked, - 'measureType': someType, - onClick: function (obj) { - obj.checked = true; - window.nesstartouch.tabulation.measure.type = this.measureType; - } - }; - - this.addChild(new ListItem(item)); - }, this); - }, - - markSelectedMeasureType: function () { - console.log("marking"); - var selectedType = window.nesstartouch.tabulation.measure.type; - if (selectedType === undefined) { - return; - } - - arrayUtils.forEach(this.getChildren(), function (child) { - if (child.measureType.id === selectedType.id) { - console.log("marked", child); - child.checked = true; - } - }); - }, - - getDefaultType: function () { - return this._types[this._defaultType]; - }, - - - _defaultType : 5, // sum - - _types : [ - { - 'label': 'Mean', - 'id': 'MEAN' - }, - { - 'label': 'Median', - 'id': 'MEDIAN' - }, - { - 'label': 'Standard deviation', - 'id': 'STDDEV' - }, - { - 'label': 'Minimum', - 'id': 'MIN' - }, - { - 'label': 'Maximum', - 'id': 'MAX' - }, - { - 'label': 'Sum of values', - 'id': 'SUM' - }, - { - 'label': 'Number of cases', - 'id': 'COUNT' - }, - { - 'label': 'Lower 95 confidence interval', - 'id': 'CI95MIN' - }, - { - 'label': 'Higher 95 confidence interval', - 'id': 'CI95MAX' - }, - { - 'label': 'Lower 99 confidence interval', - 'id': 'CI99MIN' - }, - { - 'label': 'Higher 99 confidence interval', - 'id': 'CI99MAX' - }, - { - 'label': 'Quartile 1', - 'id': 'Q1' - }, - { - 'label': 'Quartile 3', - 'id': 'Q3' - }, - { - 'label': 'Low whisker', - 'id': 'WHISKER_LO' - }, - { - 'label': 'High whisker', - 'id': 'WHISKER_HI' - }, - { - 'label': 'Sum of squares', - 'id': 'SUM_SQUARES' - }, - { - 'label': 'SE mean', - 'id': 'SE_MEAN' - } - ] - }); -}); diff --git a/js/RegressionBuilder.js b/js/RegressionBuilder.js deleted file mode 100644 index 05d1ba280940662b6dc9eb3f3e0a96bd4558d210..0000000000000000000000000000000000000000 --- a/js/RegressionBuilder.js +++ /dev/null @@ -1,135 +0,0 @@ -/*global define, */ -define(['dojo/_base/declare', - 'dojo/_base/array', - 'dojox/lang/functional', - 'dojox/mobile/RoundRectCategory', - 'dojo/dom-construct', - 'nesstartouch/_RestMixin', - "dojox/charting/axis2d/Default"], function (declare, arrayUtil, functional, RoundRectCategory, domConstruct, _RestMixin) { - "use strict"; - return declare('nesstartouch.RegressionBuilder', [_RestMixin], { - html: "", - - constructor: function (regressionData) { - var table = domConstruct.create("table"); - this._createRegressionTable(regressionData, table); - this.html = table.outerHTML; - }, - - _createRegressionTable: function (regressionData, table) { - this._createRegressionTableHead(table); - this._createRegressionTableBody(regressionData, table); - }, - - _createRegressionTableHead: function (table) { - var tr = domConstruct.create("tr", null, table), - emptyTd = domConstruct.create("td", null, tr), - td; - arrayUtil.forEach(this._headColumnTypes, function (item) { - td = domConstruct.create("td", {innerHTML: item.label, 'class': 'header label'}, tr); - }); - }, - - _createRegressionTableBody: function (regressionData, table) { - this._createRowsForIndependentVariables(regressionData.independentVariablesData, table); - domConstruct.create("td", {innerHTML: ""}, domConstruct.create("tr", null, table)); - this._createColumnVariable(regressionData, table); - }, - - _createRowsForIndependentVariables: function (independentVariablesData, table) { - var self = this, - tr, - variable; - - arrayUtil.forEach(independentVariablesData, function (independentVariable) { - tr = domConstruct.create("tr", null, table); - variable = window.nesstartouch.stores.variableStore.query({id: independentVariable.variableId})[0]; - domConstruct.create("td", {innerHTML: variable.label, 'class': 'stub label'}, tr); - arrayUtil.forEach(self._headColumnTypes, function (type) { - if (undefined !== independentVariable[type.name]) { - var td = domConstruct.create("td", {innerHTML: self._showTwoDigits(independentVariable[type.name]), 'class': 'cell'}, tr); - } - }); - }); - }, - - _createColumnVariable: function (regressionData, table) { - var self = this; - arrayUtil.forEach(this._rowTypes, function (type) { - var tr = domConstruct.create("tr", null, table); - domConstruct.create("td", {innerHTML: type.label, 'class': 'stub label'}, tr); - domConstruct.create("td", {innerHTML: self._showTwoDigits(regressionData[type.name]), 'class': 'cell'}, tr); - }); - }, - - _showTwoDigits: function (value) { - if (!this.isIntAndString(value)) { - return value.toFixed(2); - } - - return value; - }, - - isIntAndString: function (n) { - return (typeof n === 'number' && n % 1 === 0) || (typeof n === 'string'); - }, - - _headColumnTypes: [ - { - label: "B", - name: "unstandarizedCoefficient" - }, - { - label: "SE B", - name: "unstandarizedCoefficientStandardError" - }, - { - label: "Beta", - name: "standarizedCoefficient" - }, - { - label: "T", - name: "t" - }, - { - label: "Significance", - name: "tSignificance" - }, - { - label: "Tolerance", - name: "tolerance" - }, - ], - - _rowTypes: [ - { - label: "Intercept", - name: "intercept" - }, - { - label: "Valid N", - name: "caseCount" - }, - { - label: "Multiple R", - name: "r" - }, - { - label: "Multiple R Squared", - name: "rSquared" - }, - { - label: "Adjustd R Squared", - name: "adjustedRSquared" - }, - { - label: "F value", - name: "f" - }, - { - label: "F sign", - name: "fSignificance" - }, - ], - }); -}); diff --git a/js/SearchField.js b/js/SearchField.js deleted file mode 100644 index 4f10a88f36ba1f2b97e49573f646baf87f62ad14..0000000000000000000000000000000000000000 --- a/js/SearchField.js +++ /dev/null @@ -1,42 +0,0 @@ -/*global define */ -define(['dojo/_base/declare', - 'dijit/registry', - 'dojox/mobile/SearchBox'], - function (declare, registry, SearchBox) { - "use strict"; - return declare('nesstartouch.SearchField', [SearchBox], { - clear: function () { - var query = {}, - args = [{}, query, {}]; - - this.domNode.value = ""; - query[this.searchAttr] = new RegExp(".*"); - this.performSearch(args); - }, - - onSearch: function () { - window.clearTimeout(this.searchTimeout); - var args = Array.prototype.slice.call(arguments); - args.push(this); - this.searchTimeout = setTimeout(this.performSearch, 350, args); - }, - - /** - Arguments should be: - 0: list of results - 1: query - 2: options - 3: context (this) - */ - performSearch: function (args) { - var context = (args[3] !== undefined) ? args[3] : this, - listToSearch = context._getListWidget(); - - listToSearch.performSearch(args[0], args[1], args[2]); - }, - - _getListWidget: function () { - return registry.byId(this.listId); - }, - }); - }); diff --git a/js/SettingsView.js b/js/SettingsView.js deleted file mode 100644 index 03a7da674b984f4b73fc73955c1df774a89bd091..0000000000000000000000000000000000000000 --- a/js/SettingsView.js +++ /dev/null @@ -1,340 +0,0 @@ -/*global define, settings, addVariableList, variableSearchBox, analysisTypeList, measureTypeList */ -define(['dojo/_base/declare', - 'dojo/dom', - 'dojo/query', - 'dijit/registry', - 'dojo/_base/array', - 'nesstartouch/DragAndDrop', - 'dojo/store/Memory', - 'dojox/mobile/ListItem', - 'nesstartouch/VariableList', - 'nesstartouch/MeasureTypeList', - 'nesstartouch/_VariableMixin', - 'dojox/mobile/ScrollableView'], - function (declare, dom, query, registry, arrayUtils, DragAndDrop, Memory, ListItem, VariableList, MeasureTypeList, _VariableMixin, ScrollableView) { - return declare('nesstartouch.SettingsView', [ScrollableView, _VariableMixin], { - _variableListQueryOptions: { - 'sort': [ - { - 'attribute': "listorder", - 'descending': false - } - ] - }, - - analysisType: 'Tabulation', - - startup: function () { - this.inherited(arguments); - var dragAndDrop = new DragAndDrop(); - dragAndDrop.registerDraggable(settings.rowVariables).registerDroppable(settings.rowVariables); - dragAndDrop.registerDraggable(settings.columnVariables).registerDroppable(settings.columnVariables); - }, - - onBeforeScroll: function (evt) { - return !window.nesstartouch.drag.isDragging; - }, - - _createAddVariableListItem: function (type, label, list) { - var addItem = { - 'label': label || "Add variable", - 'moveTo': '#variables', - 'data-nesstar-type': 'addVariableListItem', - 'onClick': function (e) { - window.nesstartouch.variableType = type; - addVariableList.updateVariableList(); - variableSearchBox.clear(); - } - }; - - list.addChild(new ListItem(addItem), 0); - }, - - _setUpVariableLists: function (createAddItemFunc) { - this._hideAllVariablesList(); - switch (this.analysisType) { - case 'Tabulation': - this._setUpTabulationVariablesList(createAddItemFunc); - break; - case 'Regression': - this._setUpRegressionVariablesList(createAddItemFunc); - break; - case 'Correlation': - this._setUpCorrelationVariablesList(createAddItemFunc); - break; - default: - break; - } - }, - - _hideAllVariablesList: function () { - settings.tabulationVariablesList.domNode.style.display = 'none'; - settings.regressionVariablesList.domNode.style.display = 'none'; - settings.correlationVariablesList.domNode.style.display = 'none'; - }, - - _setUpTabulationVariablesList: function (createAddItemFunc) { - settings.tabulationVariablesList.domNode.style.display = 'block'; - if (settings.rowVariables) { - settings.rowVariables.refresh(); - createAddItemFunc('row', null, settings.rowVariables); - } - - if (settings.columnVariables) { - settings.columnVariables.refresh(); - createAddItemFunc('column', null, settings.columnVariables); - } - - if (settings.measureVariable) { - if (undefined === window.nesstartouch.tabulation.measure) { - window.nesstartouch.tabulation.measure = {}; - } - settings.measureVariable.refresh(); - createAddItemFunc('measure', 'Set Measure Variable', settings.measureVariable); - if (this._hasSelectedMeasure()) { - this._createMeasureTypeItem(); - this._setMeasureType(); - this._removeTabulationDataType(); - } - } - }, - - _setUpRegressionVariablesList: function (createAddItemFunc) { - settings.regressionVariablesList.domNode.style.display = 'block'; - if (settings.independentVariables) { - settings.independentVariables.refresh(); - createAddItemFunc('independent', null, settings.independentVariables); - } - - if (settings.dependentVariable) { - if (window.nesstartouch.regression === undefined) { - window.nesstartouch.regression = {}; - } - if (undefined === window.nesstartouch.regression.dependent) { - window.nesstartouch.regression.dependent = {}; - } - settings.dependentVariable.refresh(); - createAddItemFunc('dependent', 'Set Dependent Variable', settings.dependentVariable); - } - }, - - _setUpCorrelationVariablesList: function (createAddItemFunc) { - settings.correlationVariablesList.domNode.style.display = 'block'; - if (settings.correlationVariables) { - if (window.nesstartouch.correlation === undefined) { - window.nesstartouch.correlation = {}; - } - if (undefined === window.nesstartouch.correlation.displayOptions) { - window.nesstartouch.correlation.displayOptions = []; - } - settings.correlationVariables.refresh(); - this._createCorrelationDisplayOptions(); - createAddItemFunc('correlation', null, settings.correlationVariables); - } - }, - - onBeforeTransitionIn: function () { - this.populate(); - }, - - _removeVariableFromTable: function (target) { - var variableWidget = registry.getEnclosingWidget(target.currentTarget), - varId, - listItem, - newListItem; - - if (variableWidget) { - varId = variableWidget.id; - listItem = window.nesstartouch.stores.variableStore.query({id: varId})[0]; - if (listItem.onDimension === 'measure') { - this._removeMeasureTypeItem(); - window.nesstartouch.tabulation.measure = {}; - } - - if ('dependent' === listItem.onDimension) { - window.nesstartouch.regression.dependent = {}; - } - - newListItem = this.setVariableListItemProperties(variableWidget.variable, this.placeVariableOnDimensionCallback); - window.nesstartouch.stores.variableStore.put(newListItem, {'id': varId, 'overwrite': true}); - variableWidget.destroyRecursive(false); - variableWidget = null; - } - }, - - onAfterTransitionIn: function () { - var that = this, - deleteNodes; - - this._getAnalysisType(); - this._setDoButtonText(); - this._setStoreForVariables(); - this._setUpVariableLists(this._createAddVariableListItem); - deleteNodes = query(".mblListItemDeleteIcon"); - - deleteNodes.on("click", function (e) { - that._removeVariableFromTable(e); - }); - }, - - _getAnalysisType: function () { - if (undefined === window.nesstartouch.analysisType) { - window.nesstartouch.analysisType = analysisTypeList.types.getDefaultAnalysisType(); - analysisTypeList.types.markSelectedAnalysisType(); - } - - //reset the store if changing the analysis type - if (this.analysisType !== window.nesstartouch.analysisType) { - switch (this.analysisType) { - case "Tabulation": - this._resetGlobalVariablesStore(['row', 'column', 'measure']); - break; - case "Regression": - this._resetGlobalVariablesStore(['dependent', 'independent']); - break; - case "Correlation": - this._resetGlobalVariablesStore(['correlation']); - break; - } - this.analysisType = window.nesstartouch.analysisType; - window.nesstartouch.stores.setVariableStore = true; - } - - settings.currentAnalysisType.set('rightText', this.analysisType); - }, - - _resetGlobalVariablesStore: function (variableTypes) { - var self = this; - arrayUtils.forEach(variableTypes, function (variableType) { - window.nesstartouch.stores.variableStore.query({onDimension: variableType}).forEach(function (variable) { - registry.byId(variable.id).destroy(); - variable = self.setVariableListItemProperties(variable, self.placeVariableOnDimensionCallback); - window.nesstartouch.stores.variableStore.put(variable); - }); - }); - }, - - _setDoButtonText: function () { - settings.doButton.set('label', this.analysisType); - }, - - _setStoreForVariables: function () { - if (window.nesstartouch.stores.setVariableStore) { - switch (this.analysisType) { - case "Tabulation": - settings.rowVariables.setStore(window.nesstartouch.stores.variableStore, {onDimension: 'row'}, this._variableListQueryOptions); - settings.columnVariables.setStore(window.nesstartouch.stores.variableStore, {onDimension: 'column'}, this._variableListQueryOptions); - settings.measureVariable.setStore(window.nesstartouch.stores.variableStore, {onDimension: 'measure'}); - break; - case "Regression": - settings.dependentVariable.setStore(window.nesstartouch.stores.variableStore, {onDimension: 'dependent'}); - settings.independentVariables.setStore(window.nesstartouch.stores.variableStore, {onDimension: 'independent'}); - break; - case "Correlation": - settings.correlationVariables.setStore(window.nesstartouch.stores.variableStore, {onDimension: 'correlation'}); - break; - default: - break; - } - - window.nesstartouch.stores.setVariableStore = false; - } - }, - - populate: function () { - if (typeof window.nesstartouch.study === 'undefined') { - this._showStudyRelatedWidgets(false); - return false; - } - if (window.nesstartouch.tabulation === undefined) { - window.nesstartouch.tabulation = {}; - } - this._showStudyRelatedWidgets(true); - this._setStudyInfo(); - }, - - _createMeasureTypeItem: function () { - var item = { - moveTo: '#measureTypeList', - label: 'Measure type' - }; - - settings.measureVariable.addChild(new ListItem(item)); - }, - - _removeMeasureTypeItem: function () { - var children = settings.measureVariable.getChildren(); - settings.measureVariable.removeChild(children[children.length - 1]); - window.nesstartouch.tabulation.measure.type = measureTypeList.types.getDefaultType(); - measureTypeList.types.markSelectedMeasureType(); - this._showTabulationDataType(); - }, - - _createCorrelationDisplayOptions: function () { - var item = { - moveTo: '#correlationDisplayOptions', - label: 'Display Options', - }; - - settings.correlationVariables.addChild(new ListItem(item)); - }, - - _showStudyRelatedWidgets: function (visible) { - settings.studyItemsContainer.domNode.style.display = visible ? "block" : "none"; - }, - - _setStudyInfo: function () { - this._setCurrentStudyName(); - this._setCurrentAnalysisType(); - this._setTabulationDataType(); - }, - - _setCurrentStudyName: function () { - var label = window.nesstartouch.study.name; - settings.currentStudyLabel.set('rightText', label); - }, - - _setCurrentAnalysisType: function () { - var analysisType = window.nesstartouch.currentAnalysisType; - if (!analysisType) { - analysisType = "Tabulation"; - } - settings.currentAnalysisType.set('rightText', analysisType); - }, - - _setMeasureType: function () { - var measureList, typeListItem; - - if (window.nesstartouch.tabulation.measure.type === undefined) { - window.nesstartouch.tabulation.measure.type = measureTypeList.types.getDefaultType(); - measureTypeList.types.markSelectedMeasureType(); - } - measureList = settings.measureVariable.getChildren(); - typeListItem = measureList[measureList.length - 1]; - typeListItem.set('rightText', window.nesstartouch.tabulation.measure.type.label); - }, - - _setTabulationDataType: function () { - var tabulationDataType = window.nesstartouch.tabulation.dataType; - if (!tabulationDataType) { - tabulationDataType = "Column Percentage"; - window.nesstartouch.tabulation.dataType = "Column Percentage"; - } - settings.tabulationDataType.set('rightText', tabulationDataType); - }, - - _removeTabulationDataType: function () { - settings.tabulationDataContainer.domNode.style.display = 'none'; - }, - - _showTabulationDataType: function () { - settings.tabulationDataContainer.domNode.style.display = 'block'; - }, - - _hasSelectedMeasure: function () { - //Note: length is 2 because of a) the selected measure and b) the "Set measure" item - return settings.measureVariable.getChildren().length === 2; - }, - - }); - }); diff --git a/js/StudyList.js b/js/StudyList.js deleted file mode 100644 index 35e2c0dbdde6b5fb0a34feb65c01d6cd4f9ff208..0000000000000000000000000000000000000000 --- a/js/StudyList.js +++ /dev/null @@ -1,142 +0,0 @@ -/*global define, studySearchBox, splash, addVariableList, variableSearchBox, studySearchBox */ -define(['dojo/_base/declare', - 'dojo/_base/array', - 'dijit/registry', - "dojo/dom-style", - 'dojo/when', - 'dojo/store/Observable', - 'dojo/store/Memory', - 'dojox/mobile/RoundRectStoreList', - 'dojox/mobile/ListItem', - 'dojo/DeferredList', - 'nesstartouch/_RestMixin', - 'nesstartouch/_VariableMixin', - 'dojo/query'], - function (declare, arrayUtil, registry, style, when, Observable, Memory, RoundRectStoreList, ListItem, DeferredList, _RestMixin, _VariableMixin, query) { - return declare('nesstartouch.StudyList', [RoundRectStoreList, _RestMixin, _VariableMixin], { - serviceUrl: '/study/list', - - startup: function () { - var parent = this.getParent(), - self = this; - - this.inherited(arguments); - this.setStore(new Observable(new Memory())); - this.populate(this._onStudiesReceived); - self.bindClickEventToScrollTopButton(parent); - parent.onBeforeTransitionIn = function () { - self.init(); - self.bindClickEventToScrollTopButton(parent); - }; - - parent.onAfterScroll = function (e) { - self.setScrollToTopButton(parent); - }; - - parent.onBeforeTransitionOut = function () { - self.hideScrollToTopButton(0); - }; - }, - - init: function () { - if (window.nesstartouch.study) { - style.set("cancelStudyPickerButton", "visibility", "visible"); - } - studySearchBox.clear(); - }, - - _onStudiesReceived: function (studyData) { - if (studyData.studies.length) { - when(this.updateContent(studyData.studies), function () { - if (splash) { - splash.endLoading(); - } else { - console.log("no splash"); - } - }); - } - }, - - _addVariableDataToStore: function (variables) { - arrayUtil.forEach(variables, function (variable) { - var variableCallback = this.placeVariableOnDimensionCallback, - item = this.setVariableListItemProperties(variable, variableCallback); - - window.nesstartouch.stores.variableStore.add(item); - - }, this); - addVariableList.initVariableList(); - variableSearchBox.set('store', window.nesstartouch.stores.variableStore); - }, - - _onVariablesReceived: function (data) { - if (data.variables.length) { - this.hasMoreElements = data.variables.length === 100; - } - - this._addVariableDataToStore(data.variables); - }, - - _bindStudiesClickEvent : function () { - var that = this; - query('.studyMetadataClick > div.mblListItemLabel').on('click', function (target) { - var studyWidget = registry.getEnclosingWidget(target.currentTarget); - if (studyWidget) { - if (!(window.nesstartouch.study && window.nesstartouch.study.hasOwnProperty('id') && window.nesstartouch.study.id === studyWidget.id)) { - window.nesstartouch.study = studyWidget.study; - if (!window.nesstartouch.stores) { - window.nesstartouch.stores = {}; - } - window.nesstartouch.stores.variableStore = new Memory(); - window.nesstartouch.stores.setVariableStore = true; - that.populate(that._onVariablesReceived, {'studyId': window.nesstartouch.study.id}, {}, {}, "/study/${studyId}/variables"); - } - - registry.byId('studyList').performTransition('#settings', -1, "slide"); - } - }); - - query('.studyMetadataClick > img.mblListItemRightIcon').on("click", function (target) { - var studyWidget = registry.getEnclosingWidget(target.currentTarget); - if (studyWidget) { - window.nesstartouch.studyMetadata = studyWidget.study; - registry.byId('studyList').performTransition("#studyMetadata", 1, "slide"); - } - }); - - arrayUtil.forEach(query('.studyMetadataClick > img.mblListItemRightIcon'), function (node) { - var padding_top = (node.parentElement.clientHeight - node.height) / 2; - style.set(node, { - padding: padding_top + "px 16px " + padding_top + "px 16px", - }); - }); - }, - - updateContent: function (studies) { - arrayUtil.forEach(studies, function (study) { - var text = '

              ' + study.name + '

              ', - item = { - 'id': study.id, - 'label': text, - 'rightIcon': 'images/detail.png', - 'noArrow': true, - 'clickable': true, - 'study': study, - 'class': 'studyMetadataClick', - 'transitionDir': -1, - }; - - this.store.add(item); - }, this); - studySearchBox.set('store', this.store); - this._bindStudiesClickEvent(); - }, - - performSearch: function (results, query, options) { - this.setQuery(query, options); - this.refresh(); - this._bindStudiesClickEvent(); - } - - }); - }); diff --git a/js/StudyMetadata.js b/js/StudyMetadata.js deleted file mode 100644 index 2719a687bf42ff811195fea5efbe553bfa949660..0000000000000000000000000000000000000000 --- a/js/StudyMetadata.js +++ /dev/null @@ -1,316 +0,0 @@ -/*global define, splash */ -define(['dojo/_base/declare', - 'dojo/_base/array', - 'dojox/mobile/Container', - 'dojox/mobile/FilteredListMixin', - 'nesstartouch/_RestMixin', - 'nesstartouch/_TextMixin', - 'dojo/dom', - 'dojox/lang/functional', - 'dojox/mobile/RoundRectCategory', - 'dojox/mobile/ContentPane', - 'dojox/mobile/Accordion', - 'dojo/dom-construct'], - function (declare, arrayUtil, Container, FilteredListMixin, _RestMixin, _TextMixin, dom, functional, RoundRectCategory, ContentPane, Accordion, domConstruct) { - return declare('nesstartouch.StudyMetadata', [Container, _RestMixin, _TextMixin], { - - studyId : "", - html : "", - - abstract: {}, - - startup : function () { - this.inherited(arguments); - var parent = this.getParent(), - self = this; - - parent.onBeforeTransitionIn = function () { - if (window.nesstartouch.studyMetadata.id !== self.studyId) { - splash.startLoading(); - self.destroyDescendants(); - self.html = ""; - parent.scrollTo({x: 0}); - if (!self._checkIfTranslationMetadataFileExist()) { - self._loadTranslationMetadataFile('en'); - } else { - self.populate(self._updateContent, {studyId: window.nesstartouch.studyMetadata.id}, {}, {}, '/study/${studyId}/metadata'); - } - } - }; - }, - - _loadTranslationMetadataFile: function (languageCode) { - var that = this; - this.populate(function (data) { - window.nesstartouch.stores.metadataTranslation = data.metadataTranslation; - that.populate(that._updateContent, {studyId: window.nesstartouch.studyMetadata.id}, {}, {}, '/study/${studyId}/metadata'); - }, {'languageCode': languageCode}, {}, {}, '/metadataTranslation/${languageCode}'); - }, - - _updateContent : function (study) { - var metadata = study.studyMetadata.stdyDscr; - this.studyId = window.nesstartouch.studyMetadata.id || {}; - this._showStudyDescription(metadata); - }, - - _showStudyDescription: function (metadata) { - this.domNode.innerHTML = ""; - this.addStudyTitle(metadata); - //abstract needs to be displayed in the top - var accordion = new Accordion({singleOpen: true, roundRect: true}), - self = this; - this.addChild(accordion); - - this.abstract = this._addCollapse(metadata.stdyInfo.abstract, 'Abstract'); - accordion.addChild(this.abstract); - - accordion.addChild(this._addCollapse(metadata.citation, "Bibliographic Citation")); - accordion.addChild(this._addCollapse(metadata.stdyInfo, 'Study Scope')); - accordion.addChild(this._addCollapse(metadata.method, 'Methodology And Processing')); - accordion.addChild(this._addCollapse(metadata.othrStdyMat, 'Other Study Description Materials')); - - accordion.startup(); - accordion.select(this.abstract); - - setTimeout(function () { - var style = document.createAttribute('style'); - style.nodeValue = 'display: block;'; - self.abstract.domNode.attributes.setNamedItem(style); - splash.endLoading(); - }, 500); - }, - - addStudyTitle: function (metadata) { - var category = new RoundRectCategory({'label': 'Title'}), - ul = domConstruct.create("p", {'innerHTML': metadata.citation.titlStmt.titl, 'class': 'metadataText'}), - result = this._convertLineBreak(ul.outerHTML, "metadataText"); - - this.domNode.innerHTML += category.domNode.outerHTML + result; - }, - - _addCollapse: function (info, text) { - var pane = new ContentPane({label : text}), - result = ""; - - pane.startup(); - if ("Abstract" === text) { - result = this._createStringInMetadata(info, 'abstract'); - } else { - result = this._recursionScanStudyMetadata(info); - } - pane.set("content", result); - return pane; - }, - - _recursionScanStudyMetadata: function (studyMetadata) { - var self = this, - result = ""; - - functional.forIn(studyMetadata, function (value, key) { - var type = self._checkObjectType(value); - if (key !== 'software') { - //just string - if ('string' === type && value.length > 0 && 'abstract' !== key) { - result += self._createStringInMetadata(value, key); - } else if ('array' === type && value.length > 0) { - //it's array, but still has three situations - //if list, show it in ul - if ('list' === self._getTypeOfFirstMember(value[0])) { - result += self._createListOfArrayInMetadata(value, key); - } else if ('table' === self._getTypeOfFirstMember(value[0])) { - result += self._createTableOfDataInMetadata(value, key); - } else if ('object' === self._getTypeOfFirstMember(value[0])) { - result += self._createParagraphsOfArrayInMetadata(value, key); - } - } else if ('object' === type) { - if (self._checkIfString(value)) { - if ('abstract' !== key) { - result += self._createStringInMetadata(value, key); - } - } else { - result += self._recursionScanStudyMetadata(value); - } - } - } - }); - return result; - }, - - _getTypeOfFirstMember: function (member) { - var result = 'table', - self = this; - functional.forIn(member, function (value, key) { - if ('object' === self._checkObjectType(value)) { - result = 'object'; - return; - } - - if (-1 !== key.indexOf('URI')) { - result = 'list'; - return; - } - }); - - if (result === 'list' && functional.keys(member).length > 3) { - result = 'table'; - } - - return result; - }, - - _checkIfString: function (value) { - if (value.hasOwnProperty("content") && value.hasOwnProperty("ExtLink")) { - return true; - } - return false; - }, - - _createListOfArrayInMetadata : function (value, key) { - var result = "", - category, - ul, - uri, - text; - if (window.nesstartouch.stores.metadataTranslation.hasOwnProperty(key)) { - category = new RoundRectCategory({'label': window.nesstartouch.stores.metadataTranslation[key]}); - ul = domConstruct.create("ul", {'class': 'metadataText'}); - arrayUtil.forEach(value, function (item) { - text = ""; - uri = ""; - functional.forIn(item, function (theValue, theKey) { - if (theKey === 'content' || 'labl' === theKey) { - text = theValue; - } else if (-1 !== theKey.indexOf('URI')) { - uri = theValue; - } - }); - domConstruct.create("li", {'innerHTML': text, 'href': uri}, ul); - }); - result += category.domNode.outerHTML + ul.outerHTML; - } - - return result; - }, - - _createParagraphsOfArrayInMetadata: function (value, key) { - var result = "", - title, - paras, - temp, - content, - self = this; - - if (window.nesstartouch.stores.metadataTranslation.hasOwnProperty(key)) { - title = new RoundRectCategory({'label': window.nesstartouch.stores.metadataTranslation[key]}); - result += title.domNode.outerHTML; - arrayUtil.forEach(value, function (item) { - paras = domConstruct.create('h4', {innerHTML: item.citation.titlStmt.titl, 'class': 'metadataText'}); - temp = {}; - content = ""; - try { - temp = JSON.parse(item.content); - if (undefined !== temp.citation.holdings && "" !== temp.citation.holdings.URI) { - content = domConstruct.create('a', {innerHTML: temp.citation.titlStmt.titl, 'class': 'metadataText', 'href': temp.citation.holdings.URI}); - } else { - content = domConstruct.create('p', {innerHTML: temp.citation.titlStmt.titl, 'class': 'metadataText'}); - } - } catch (err) { - if (undefined !== item.citation.holdings && "" !== item.citation.holdings.URI) { - content = domConstruct.create('a', {innerHTML: item.content, 'class': 'metadataText', 'href': item.citation.holdings.URI}); - } else { - content = domConstruct.create('p', {innerHTML: item.content, 'class': 'metadataText'}); - } - } - - content = self._convertLineBreak(content.outerHTML, "metadataText"); - result += paras.outerHTML + content; - }); - - } - - return result; - }, - - _createTableOfDataInMetadata : function (value, key) { - var result = "", - table, - headTr, - keys, - category; - - if (window.nesstartouch.stores.metadataTranslation.hasOwnProperty(key) && false === this.isEmptyTable(value)) { - category = new RoundRectCategory({'label': window.nesstartouch.stores.metadataTranslation[key]}); - table = domConstruct.create('table', {'class': 'metadataText'}); - headTr = domConstruct.create('tr', null, table); - keys = functional.keys(value[0]); - - //this should be unified, the keyword "content" not only - //appears in the table part, also become commen in all the string. - arrayUtil.forEach(functional.keys(value[0]), function (attr) { - if (window.nesstartouch.stores.metadataTranslation.hasOwnProperty(attr)) { - domConstruct.create('th', {'innerHTML': window.nesstartouch.stores.metadataTranslation[attr]}, headTr); - } else { - domConstruct.create('th', {'innerHTML': "Name"}, headTr); - } - }); - - arrayUtil.forEach(value, function (item) { - var tr = domConstruct.create('tr', null, table), temp; - arrayUtil.forEach(keys, function (attr) { - if (item[attr] !== undefined) { - temp = item[attr]; - } else { - temp = ""; - } - domConstruct.create('td', {'innerHTML': temp}, tr); - }); - }); - - result += category.domNode.outerHTML + '\n
              \n' + table.outerHTML; - } - - return result; - }, - - isEmptyTable: function (value) { - var result = true; - arrayUtil.forEach(value, function (item) { - functional.forIn(item, function (text, key) { - if ("" !== text) { - result = false; - } - }); - }); - return result; - }, - - _createStringInMetadata: function (value, key) { - var result = "", - text = "", - category, - ul; - - if ("string" === typeof value) { - text = value; - } else { - text = value.content; - } - - if (window.nesstartouch.stores.metadataTranslation.hasOwnProperty(key) && "" !== text) { - category = new RoundRectCategory({'label': window.nesstartouch.stores.metadataTranslation[key]}); - ul = domConstruct.create("p", {'innerHTML': text, 'class': 'metadataText'}); - result = this._convertLineBreak(ul.outerHTML, "metadataText"); - - result = category.domNode.outerHTML + result; - } - return result; - }, - - - //string, object, array - _checkObjectType: function (inputObject) { - var le = Object.prototype.toString.call(inputObject); - return le.substring(8, le.length - 1).toLowerCase(); - }, - }); - }); diff --git a/js/TableBuilder.js b/js/TableBuilder.js deleted file mode 100644 index 89764fa462dfa4f68ac0a9f10492393199f0e6cf..0000000000000000000000000000000000000000 --- a/js/TableBuilder.js +++ /dev/null @@ -1,245 +0,0 @@ -/*global define */ -define(['dojo/_base/declare', - 'dojo/_base/array', - 'dojo/number'], function (declare, arrayUtil, number) { - "use strict"; - return declare('nesstartouch.TableBuilder', null, { - html: '', - _numberFormatOptions: { - pattern: '#,##0.##' - }, - totalValuesForColumn : [], - - constructor: function (data, rowVariables, columnVariables, isColumnPercentage) { - this.data = data; - this.rowVariables = rowVariables; - this.columnVariables = columnVariables; - this.isColumnPercentage = isColumnPercentage; - this.updateTable(); - }, - - updateTable: function () { - this.buildTableData(); - this.buildHTMLtable(); - }, - - buildTableData: function () { - var index, - variable; - - this.tableData = { - 'rows': [], - 'addEmptyRow': function () { - this.rows.push({ 'cells': [] }); - }, - 'push': function (cell) { - this.rows[this.rows.length - 1].cells.push(cell); - } - }; - - for (index = 0; index < this.columnVariables.length; index = index + 1) { - variable = this.columnVariables[index]; - this.tableData.addEmptyRow(); - this.createHeaderRow(variable, index); - } - this.tableData.addEmptyRow(); - this.createVariableStubs(this.rowVariables); - this.createTableBody(this.rowVariables); - }, - - createHeaderRow: function (variable, variableIndex) { - var labelColspan = this.calculateLabelColspanForHeaderVariable(), - labelCell = { 'label': variable.label, 'cssClass': 'header dimension' }, - colspan, - rowspan, - categoriesNumberOfPreviousVariables, - j, - i, - category, - cell; - - if (labelColspan > 1) { - labelCell.colspan = labelColspan; - } - this.tableData.push(labelCell); - - colspan = this.calculateSpan(variableIndex, this.columnVariables); - rowspan = this.calculateRowspanForHeader(variableIndex); - categoriesNumberOfPreviousVariables = this.calculateCategoriesNumberOfPreviousVariables(variableIndex); - - for (j = 0; j < categoriesNumberOfPreviousVariables; j = j + 1) { - for (i = 0; i < variable.categories.length; i = i + 1) { - category = variable.categories[i]; - cell = {}; - cell.label = category.label; - cell.cssClass = 'header label'; - if (colspan > 1) { - cell.colspan = colspan; - } - if (rowspan > 1) { - cell.rowspan = rowspan; - } - - this.tableData.push(cell); - } - } - - }, - - calculateLabelColspanForHeaderVariable: function () { - var numberOfRowVariables = this.rowVariables.length; - if (numberOfRowVariables > 1) { - return 2; - } - return 1; - }, - - calculateRowspanForHeader: function (index) { - var numberOfColumnVariables = this.columnVariables.length; - if (numberOfColumnVariables > 0 && index === numberOfColumnVariables - 1) { - return 2; // last row of column headers will always have colspan 2 TODO: really? - } - return 1; - }, - - calculateCategoriesNumberOfPreviousVariables: function (variableIndex) { - var i, numberOfCategoies = 1; - for (i = 0; i < variableIndex; i = i + 1) { - numberOfCategoies *= this.columnVariables[i].categories.length; - } - - return numberOfCategoies; - }, - - calculateSpan: function (forRow, variables) { - var span = 1, - list = variables.slice(forRow + 1), - i; - - for (i = 0; i < list.length; i = i + 1) { - span *= list[i].categories.length; - } - - return span; - }, - - createVariableStubs : function (variables) { - arrayUtil.forEach(variables, function (variable) { - this.tableData.push({ 'label': variable.label, 'cssClass': 'stub label' }); - }, this); - }, - - createTableBody: function (variables) { - this.tableBreadth = this.calculateTableBreadth(); - this.currentRow = 0; - this.tableData.addEmptyRow(); - this.calculateTotalValuesForColumn(); - this.handleVariableAtIndex(0, variables); - }, - - calculateTableBreadth: function () { - var breadth = 1; - arrayUtil.forEach(this.columnVariables, function (variable) { - breadth *= variable.categories.length; - }); - return breadth; - }, - - handleVariableAtIndex: function (index, variables) { - var variable, - rowspan, - j, - cell; - - if (this.isLeafCategory(index)) { - this.createTableBodyRow(); - return; - } - variable = variables[index]; - rowspan = this.calculateSpan(index, variables); - for (j = 0; j < variable.categories.length; j = j + 1) { - cell = { 'label': variable.categories[j].label, 'cssClass': 'stub label' }; - if (rowspan > 1) { - cell.rowspan = rowspan; - } - this.tableData.push(cell); - this.handleVariableAtIndex(index + 1, variables); - if (j < variable.categories.length - 1) { - this.tableData.addEmptyRow(); - } - } - }, - - isLeafCategory: function (index) { - return index === this.rowVariables.length; - }, - - createTableBodyRow: function () { - var start = this.currentRow * this.tableBreadth, - end = start + this.tableBreadth, - formattedNumber, - i; - - for (i = start; i < end; i = i + 1) { - if (this.isColumnPercentage) { - if (0 === this.totalValuesForColumn[i - start]) { - formattedNumber = 0; - } else { - formattedNumber = number.format(this.data[i] / this.totalValuesForColumn[i - start] * 100, this._numberFormatOptions); - } - } else { - formattedNumber = number.format(this.data[i], this._numberFormatOptions); - } - - this.tableData.push({ 'label': formattedNumber, 'rawValue': this.data[i], 'cssClass': 'cell'}); - } - this.currentRow = this.currentRow + 1; - }, - - calculateTotalValuesForColumn: function () { - var i, j; - this.totalValuesForColumn = []; - - for (i = 0; i < this.data.length; true) { - for (j = 0; j < this.tableBreadth; j = j + 1) { - if (undefined === this.totalValuesForColumn[j]) { - this.totalValuesForColumn[j] = this.data[i + j]; - } else { - this.totalValuesForColumn[j] += this.data[i + j]; - } - } - i += this.tableBreadth; - } - }, - - buildHTMLtable: function () { - var html = []; - arrayUtil.forEach(this.tableData.rows, function (row, index) { - var rowHTML = ['']; - arrayUtil.forEach(row.cells, function (cell, index) { - var cellHTML = [' 1) { - cellHTML.push(' colspan="'); - cellHTML.push(cell.colspan); - cellHTML.push('"'); - } - if (cell.rowspan > 1) { - cellHTML.push(' rowspan="'); - cellHTML.push(cell.rowspan); - cellHTML.push('"'); - } - cellHTML.push('>'); - cellHTML.push(cell.label); - cellHTML.push(''); - rowHTML.push(cellHTML.join('')); - }); - rowHTML.push(''); - html.push(rowHTML.join('')); - }); - this.html = '' + html.join('\n') + '
              '; - } - }); -}); diff --git a/js/Tabulation.js b/js/Tabulation.js deleted file mode 100644 index 89560a965e47e714efffb69e132abe75c69f4920..0000000000000000000000000000000000000000 --- a/js/Tabulation.js +++ /dev/null @@ -1,522 +0,0 @@ -/*global define, splash, alert, tabulation, alertDialogButton */ -define(['dojo/_base/declare', - 'dojo/_base/array', - 'dojo/dom', - 'nesstartouch/TableBuilder', - 'nesstartouch/RegressionBuilder', - 'nesstartouch/CorrelationBuilder', - 'dojox/mobile/ScrollableView', - 'dojox/lang/functional', - 'dojox/mobile/ContentPane', - 'dojo/_base/lang', - 'dojox/mobile/SimpleDialog', - 'nesstartouch/VariableMetadataBuilder', - 'nesstartouch/_RestMixin'], function (declare, arrayUtil, dom, TableBuilder, RegressionBuilder, CorrelationBuilder, ScrollableView, functional, ContentPane, lang, Dialog, MetadataBuilder, _RestMixin) { - "use strict"; - return declare('nesstartouch.Tabulation', [ScrollableView, _RestMixin], { - tabulationServiceUrl: '/study/${studyId}/tabulate', - regressionServiceUrl: '/study/${studyId}/regression', - correlationServiceUrl: '/study/${studyId}/correlate', - defaultMeasureType: 'SUM', - - tabulationData : { - 'breakVariableIds': [], - 'measureTypes': [], - }, - - regressionData : { - 'independentVariableIds': [], - }, - - correlationData: { - 'correlationVariableIds': [], - }, - - oldCorrelationData: { - 'correlationVariableIds': [], - 'displayOptions': [], - 'rawData': {}, - }, - - oldTabulationData: { - 'rowVariableIds': [], - 'columnVariableIds': [], - 'measureTypes': [], - 'tabulationDataType': "", - "rawData": {}, - }, - - isCalculationFinished: false, - - isVaraibleMetadataFinished: false, - - variablesId : [], - - onBeforeTransitionIn: function () { - var result; - this.isCalculationFinished = false; - this.isVaraibleMetadataFinished = false; - splash.startLoading(); - - this._setHeadingLabel(window.nesstartouch.analysisType); - this._setStudyLabel(); - - switch (window.nesstartouch.analysisType) { - case 'Tabulation': - if (this.isTabulationVariablesReady(['row', 'column', 'measure'])) { - this.extractTabulateData(); - if (this.ifTabulationVariablesNotChanged()) { - this.isVaraibleMetadataFinished = true; - this.tabulationHandleResponse(this.oldTabulationData.rawData); - } else { - this.tabulate(); - this.getVariablesMetadata(this.tabulationData, ['breakVariableIds', 'measureVariableId']); - } - } else { - this.emptyTableAndVariableMetadata(); - } - break; - case 'Regression': - result = this.isRegressionVariablesReady(); - if (result && 0 !== result[0] && 0 !== result[1]) { - this.extractRegressionData(); - this.regression(); - this.getVariablesMetadata(this.regressionData, ['dependentVariableId', 'independentVariableIds']); - } else { - this.emptyTableAndVariableMetadata(); - if (0 === result[0] && 0 !== result[1]) { - this.showAlertMessage("Dependent Variable must be set!"); - } else if (0 !== result[0] && 0 === result[1]) { - this.showAlertMessage("Independent Variable must exist at least one!"); - } - } - break; - case 'Correlation': - result = this.isCorrelationVariablesReady(); - //if exists variable - if (result && 0 < result) { - this.extractCorrelationData(); - //comparing to the previous one to check if only display options changed - if (this.ifCorrelationVariablesNotChanged()) { - this.isVaraibleMetadataFinished = true; - this.correlationHandleResponse(this.oldCorrelationData.rawData); - } else { - if (1 === result) { - this.correlationHandleResponse(this.createFakeOneVariableCorrelationResult(this.correlationData.correlationVariableIds[0])); - } else { - this.correlation(); - } - this.getVariablesMetadata(this.correlationData, ['correlationVariableIds']); - } - } else { - this.emptyTableAndVariableMetadata(); - } - break; - default: - break; - } - }, - - _setHeadingLabel: function (label) { - tabulation.heading.set('label', label); - }, - - _setStudyLabel: function () { - dom.byId("tabulation.studyTitle").innerHTML = window.nesstartouch.study.name; - }, - - showAlertMessage: function (msg) { - dom.byId('alertMessageContent').innerHTML = msg; - alert.message.show(); - alertDialogButton.onClick = function () { - alert.message.hide(); - }; - console.log(msg); - }, - - errorMethod: function (err) { - splash.endLoading(); - this.showAlertMessage("An error occurred while talking to the server. Please try it again."); - console.log(err); - }, - - checkAndHideLoading: function () { - if (this.isCalculationFinished && this.isVaraibleMetadataFinished) { - splash.endLoading(); - } - }, - - ifTabulationVariablesNotChanged: function () { - var result = true, - self = this; - //if not empty object - if (2 !== JSON.stringify(this.oldTabulationData.rawData).length && - this.oldTabulationData.measureTypes.length === this.tabulationData.measureTypes.length && - this.oldTabulationData.measureVariableId === this.tabulationData.measureVariableId) { - window.nesstartouch.stores.variableStore.query({onDimension: "row"}).forEach(function (variableId) { - if (-1 === self.oldTabulationData.rowVariableIds.indexOf(variableId)) { - result = false; - } - }); - - window.nesstartouch.stores.variableStore.query({onDimension: "column"}).forEach(function (variableId) { - if (-1 === self.oldTabulationData.columnVariableIds.indexOf(variableId)) { - result = false; - } - }); - - arrayUtil.forEach(this.oldTabulationData.measureTypes, function (measureType) { - if (-1 === self.tabulationData.measureTypes.indexOf(measureType)) { - result = false; - } - }); - } else { - result = false; - } - - return result; - }, - - tabulate: function () { - this.populate(this.tabulationHandleResponse, - {'studyId': window.nesstartouch.study.id}, - {'method': 'POST', 'data': this.tabulationData}, - null, - this.tabulationServiceUrl, - lang.hitch(this, this.errorMethod)); - }, - - tabulationHandleResponse: function (rawData) { - var rowVariables, columnVariables, measureVariable, isColumnPercentage, tableBuilder; - - if (rawData.tabulation) { - this.updateTableView(''); //TODO: add spinner? - rowVariables = this.identifyVariables(rawData.tabulation.breakVariables, 'row'); - columnVariables = this.identifyVariables(rawData.tabulation.breakVariables, 'column'); - - measureVariable = this.createVariableFromMeasureTypes(rawData.tabulation.measureTypes); - if (rowVariables.length === 0) { - rowVariables = measureVariable; - } else if (columnVariables.length === 0) { - columnVariables = measureVariable; - } - - isColumnPercentage = ("Column Percentage" === window.nesstartouch.tabulation.dataType && undefined === rawData.tabulation.measureVariable); - tableBuilder = new TableBuilder(rawData.tabulation.data, rowVariables, columnVariables, isColumnPercentage); - this.updateTableView(tableBuilder.html); - this.isCalculationFinished = true; - this.checkAndHideLoading(); - - this.saveCurrentTabulationInfo(rawData); - } - }, - - saveCurrentTabulationInfo: function (rawData) { - this.oldTabulationData.rawData = rawData; - this.oldTabulationData.rowVariableIds = []; - this.addVariablesFromStore('row', this.oldTabulationData.rowVariableIds); - this.oldTabulationData.columnVariableIds = []; - this.addVariablesFromStore('column', this.oldTabulationData.columnVariableIds); - this.oldTabulationData.measureTypes = this.tabulationData.measureTypes; - this.oldTabulationData.tabulationDataType = window.nesstartouch.tabulation.dataType; - this.oldTabulationData.measureVariableId = this.tabulationData.measureVariableId; - }, - - updateTableView: function (html) { - dom.byId('table').innerHTML = html; - }, - - identifyVariables: function (tabulationVariables, dim) { - var dataStore = window.nesstartouch.stores.variableStore, - variablesFromStore = dataStore.query({onDimension: dim}).map(function (listItemData) { - return listItemData.variable; - }); - - variablesFromStore.forEach(function (variable) { - arrayUtil.forEach(tabulationVariables, function (someVariable) { - if (someVariable.id === variable.id) { - variable.categories = someVariable.categories; - } - }, this); - }, this); - return variablesFromStore; - }, - - createVariableFromMeasureTypes: function (types) { - var measureVariable = {}, - result = window.nesstartouch.stores.variableStore.query({onDimension: 'measure'}); - - if (result.total > 0) { - measureVariable = result[0].variable; - } - - if (window.nesstartouch.tabulation.measure.type !== undefined) { - measureVariable.categories = [window.nesstartouch.tabulation.measure.type]; - } else { - measureVariable.categories = arrayUtil.map(types, function (someType) { - return { 'label': someType }; - }); - } - - return [measureVariable]; //Note: function returns an array - }, - - extractTabulateData: function () { - this.tabulationData = { - 'breakVariableIds': [], - 'measureTypes': [], - }; - this.addBreakVariables(); - this.addMeasure(); - this.addWeightVariables(); - this.setSubsetExpression(); - console.log("tabulation data ready:", this.tabulationData); - }, - - isTabulationVariablesReady: function (variablesType) { - var store = window.nesstartouch.stores.variableStore, - result = false; - - if (!store) { - return result; - } - - arrayUtil.forEach(variablesType, function (variableType) { - result = result || store.query({onDimension: variableType}).length > 0; - }); - - return result; - }, - - isRegressionVariablesReady: function () { - var store = window.nesstartouch.stores.variableStore, - result = false; - - if (!store) { - return result; - } - - result = [null, null]; - result[0] = store.query({onDimension: 'dependent'}).length; - result[1] = store.query({onDimension: 'independent'}).length; - - return result; - }, - - isCorrelationVariablesReady: function () { - var store = window.nesstartouch.stores.variableStore, - result = false; - - if (!store) { - return result; - } - - result = store.query({onDimension: 'correlation'}).length; - - return result; - }, - - addBreakVariables: function () { - this.addVariablesFromStore('row', this.tabulationData.breakVariableIds); - this.addVariablesFromStore('column', this.tabulationData.breakVariableIds); - }, - - addVariablesFromStore: function (dim, idArray) { - var store = window.nesstartouch.stores.variableStore; - store.query(function (item) { - return item.variable !== undefined && item.onDimension === dim; - }).forEach(function (item) { - idArray.push(item.variable.id); - }, this); - }, - - addMeasure: function () { - //if not empty object - var measureVariables = window.nesstartouch.stores.variableStore.query({onDimension: 'measure'}), - first; - - if (measureVariables.length > 0) { - first = measureVariables[0].variable; - this.tabulationData.measureVariableId = first.id; - if (window.nesstartouch.tabulation.measure.type === undefined) { - window.nesstartouch.tabulation.measure.type.id = this.defaultMeasureType; - } - this.tabulationData.measureTypes.push(window.nesstartouch.tabulation.measure.type.id); - } - }, - - addWeightVariables: function () { - console.log("addWeightVariables not yet implemented"); - }, - - setSubsetExpression: function () { - console.log("setSubsetExpression not yet implemented"); - }, - - emptyTableAndVariableMetadata : function () { - dom.byId('table').innerHTML = ""; - tabulation.variablesMetadata.destroyDescendants(); - tabulation.variablesMetadata.domNode.innerHTML = ""; - splash.endLoading(); - }, - - regression: function () { - this.populate(this.regressionHandleResponse, - {'studyId': window.nesstartouch.study.id}, - {'method': 'POST', 'data': this.regressionData}, - null, - this.regressionServiceUrl, - lang.hitch(this, this.errorMethod)); - }, - - regressionHandleResponse: function (rawData) { - if (rawData.regression) { - this.updateTableView(''); //TODO: add spinner? - - var regressionBuilder = new RegressionBuilder(rawData.regression); - this.updateTableView(regressionBuilder.html); - this.isCalculationFinished = true; - this.checkAndHideLoading(); - } - }, - - extractRegressionData: function () { - this.regressionData = { - 'independentVariableIds': [], - }; - this.addVariablesFromStore('independent', this.regressionData.independentVariableIds); - this.addDependentVariable(); - console.log("regression data ready:", this.regressionData); - }, - - addDependentVariable: function () { - var dependentVariables = window.nesstartouch.stores.variableStore.query({onDimension: 'dependent'}), - first; - - if (dependentVariables.length > 0) { - first = dependentVariables[0].variable; - this.regressionData.dependentVariableId = first.id; - } - }, - - ifCorrelationVariablesNotChanged: function () { - var result = true, - self = this; - - //if not empty object - if (2 !== JSON.stringify(this.oldCorrelationData.rawData).length && - this.oldCorrelationData.correlationVariableIds.length === this.correlationData.correlationVariableIds.length) { - arrayUtil.forEach(this.oldCorrelationData.correlationVariableIds, function (variableId) { - if (-1 === self.correlationData.correlationVariableIds.indexOf(variableId)) { - result = false; - } - }); - } else { - result = false; - } - - return result; - }, - - correlation: function () { - this.populate(this.correlationHandleResponse, - {'studyId': window.nesstartouch.study.id}, - {'method': 'POST', 'data': this.correlationData}, - null, - this.correlationServiceUrl, - lang.hitch(this, this.errorMethod)); - }, - - correlationHandleResponse: function (rawData) { - var temp, - correlationBuilder; - - if (rawData.correlation) { - this.updateTableView(""); - temp = {}; - arrayUtil.forEach(window.nesstartouch.stores.variableStore.query({onDimension: 'correlation'}), function (variable) { - temp[variable.id] = variable.label; - }); - correlationBuilder = new CorrelationBuilder(rawData.correlation, temp, window.nesstartouch.correlation.displayOptions); - this.updateTableView(correlationBuilder.html); - this.isCalculationFinished = true; - this.checkAndHideLoading(); - - this.saveCurrentCorrelationInfo(rawData); - } - }, - - saveCurrentCorrelationInfo: function (rawData) { - this.oldCorrelationData.rawData = rawData; - this.oldCorrelationData.correlationVariableIds = this.correlationData.correlationVariableIds; - this.oldCorrelationData.displayOptions = window.nesstartouch.correlation.displayOptions; - }, - - createFakeOneVariableCorrelationResult: function (variableId) { - var key = variableId + "|" + variableId, - result = {correlation: { - resultValuesMap: {} - }}; - - result.correlation.resultValuesMap[key] = { - "correlationCoefficient": '-', - "significance": '-', - "caseCount": '-' - }; - - return result; - }, - - extractCorrelationData: function () { - this.correlationData = { - 'correlationVariableIds': [], - }; - this.addVariablesFromStore('correlation', this.correlationData.correlationVariableIds); - console.log("correlation data ready:", this.correlationData); - }, - - getVariablesMetadata : function (variablesData, typeArray) { - var self = this; - this._extractVariablesForMetadata(variablesData, typeArray); - arrayUtil.forEach(self.variablesId, function (variableId, index) { - var variableMetadataBuilder = new MetadataBuilder(); - variableMetadataBuilder.getVariableMetadata(variableId, null, index, lang.hitch(self, self._addVariableMetadata)); - }); - }, - - _extractVariablesForMetadata : function (variablesData, typeArray) { - var self = this; - if (tabulation.variablesMetadata) { - tabulation.variablesMetadata.destroyDescendants(); - tabulation.variablesMetadata.domNode.innerHTML = ""; - } - self.variablesId = []; - functional.forIn(variablesData, function (value, key) { - if (-1 !== typeArray.indexOf(key)) { - if ('array' === self._checkObjectType(value)) { - arrayUtil.forEach(value, function (item) { - self.variablesId.push(item); - }); - } else if ('string' === self._checkObjectType(value)) { - self.variablesId.push(value); - } - } - }); - }, - - _checkObjectType: function (inputObject) { - var le = Object.prototype.toString.call(inputObject); - return le.substring(8, le.length - 1).toLowerCase(); - }, - - _addVariableMetadata : function (metadataNodes, variableLabel, indexOfVariableId) { - var pane = new ContentPane({label : variableLabel}); - pane.domNode.innerHTML = metadataNodes; - tabulation.variablesMetadata.addChild(pane); - if (indexOfVariableId === this.variablesId.length - 1) { - this.isVaraibleMetadataFinished = true; - } - this.checkAndHideLoading(); - }, - }); -}); diff --git a/js/TabulationDataType.js b/js/TabulationDataType.js deleted file mode 100644 index 17d64e0e7274e946e4885f9956aaeeaad764b0d4..0000000000000000000000000000000000000000 --- a/js/TabulationDataType.js +++ /dev/null @@ -1,37 +0,0 @@ -/*global define, settings */ -define(['dojo/_base/declare', - 'dojo/_base/array', - 'dojo/topic', - 'dojox/mobile/ListItem', - 'dojox/mobile/RoundRectList'], function (declare, arrayUtils, topic, ListItem, RoundRectList) { - return declare('nesstartouch.TabulationDataType', [RoundRectList], { - startup: function () { - this.inherited(arguments); - - arrayUtils.forEach(this._types, function (someType, index) { - var checked = index === this._defaultType, - item = { - 'label': someType, - 'moveTo': '#settings', - 'transitionDir': -1, - 'noArrow': true, - 'checked': checked, - 'dataType': someType, - onClick: function (obj) { - obj.checked = true; - window.nesstartouch.tabulation.dataType = this.dataType; - settings.tabulationDataType.set("rightText", this.dataType); - } - }; - this.addChild(new ListItem(item)); - }, this); - }, - - getDefaultTabulationDataType: function () { - return this._types[this._defaultType]; - }, - - _defaultType : 0, // Column Percentage - _types : ['Column Percentage', 'Raw Number'] - }); -}); diff --git a/js/VariableList.js b/js/VariableList.js deleted file mode 100644 index 68f96a6375dd36f92fbaa4ddf034b4a202e26024..0000000000000000000000000000000000000000 --- a/js/VariableList.js +++ /dev/null @@ -1,155 +0,0 @@ -/*global define, moreVariablesButton, addVariableList */ -define(['dojo/_base/declare', - 'dojo/_base/lang', - 'dojo/_base/array', - 'dijit/registry', - 'dojo/query', - 'dojo/on', - 'dojo/dom-style', - 'dojox/mobile/RoundRectStoreList', - 'dojox/mobile/ListItem', - 'nesstartouch/_VariableMixin'], - function (declare, lang, array, registry, query, on, style, RoundRectStoreList, ListItem, _VariableMixin) { - "use strict"; - return declare('nesstartouch.VariableList', [RoundRectStoreList, _VariableMixin], { - pageSize: 100, - currentPageSize: 100, - rightIconClickEvents: [], - labelClickEvents: [], - defaultQuery: {'onDimension': 'none'}, - - startup: function () { - var onclickWithContext = lang.hitch(this, this.moreButtonClick); - on(moreVariablesButton, "click", onclickWithContext); - }, - - initVariableList: function () { - this.setStore(window.nesstartouch.stores.variableStore); - }, - - updateVariableList: function () { - this.currentPageSize = this.pageSize; - this._displayListItems(); - this.addBindVariablesClickEvent(); - }, - - addBindVariablesClickEvent: function () { - var that = this, - parent = addVariableList.getParent(); - this.changePageTitle(); - - parent.onAfterTransitionIn = function () { - that.bindVariablesClickEvent(); - that.bindClickEventToScrollTopButton(parent); - }; - - parent.onAfterScroll = function (e) { - that.setScrollToTopButton(parent); - }; - - parent.onBeforeTransitionOut = function () { - that.hideScrollToTopButton(0); - }; - }, - - bindVariablesClickEvent: function () { - //remove the previous binding events - array.forEach(this.rightIconClickEvents, function (handle) {handle.remove(); }); - array.forEach(this.labelClickEvents, function (handle) {handle.remove(); }); - - array.forEach(query('.variableMetadataClick > img.mblListItemRightIcon'), function (item) { - var padding_left, - padding_top, - variableWidget; - - this.rightIconClickEvents.push(on(item, "click", function (target) { - variableWidget = registry.getEnclosingWidget(target.currentTarget); - if (variableWidget) { - if (!window.nesstartouch.variableMetadata) { - window.nesstartouch.variableMetadata = {}; - } - - window.nesstartouch.variableMetadata.id = variableWidget.variable.id; - window.nesstartouch.variableMetadata.label = variableWidget.variable.label; - registry.byId('variables').performTransition('#variableMetadata', -1, "slide"); - } - })); - padding_left = 8 + style.get(item.parentNode, "padding-right"); - padding_top = (item.parentNode.clientHeight - item.height) / 2; - style.set(item, { - padding: padding_top + "px " + padding_left + "px " + padding_top + "px " + padding_left + "px", - }); - }, this); - - array.forEach(query('.variableMetadataClick > div.mblListItemLabel'), function (item) { - this.labelClickEvents.push(on(item, "click", function (target) { - var variableWidget = registry.getEnclosingWidget(target.currentTarget); - if (variableWidget) { - variableWidget.click(); - } - })); - }, this); - }, - - performSearch: function (results, query, options) { - query.onDimension = 'none'; - this.setQuery(query, options); - this.refresh(); - this.bindVariablesClickEvent(); - }, - - _displayListItems: function () { - this.setQuery(this.defaultQuery, { 'count': this.currentPageSize, 'start': 0 }); - this.refresh(); - this._displayMoreButton(); - }, - - _displayMoreButton: function () { - if (this._numberOfVariablesInStore() > this.currentPageSize) { - moreVariablesButton.set("style", "visibility: visible"); - } else { - moreVariablesButton.set("style", "visibility: hidden"); - } - }, - - _numberOfVariablesInStore: function () { - return window.nesstartouch.stores.variableStore.data.length; - }, - - moreButtonClick: function () { - this.currentPageSize += this.pageSize; - addVariableList.setQuery( - this.defaultQuery, - { 'count': this.currentPageSize, 'start': 0 } - ); - this.refresh(); - this._displayMoreButton(); - }, - - changePageTitle: function () { - var title = ""; - switch (window.nesstartouch.variableType) { - case "row": - title = "Add Row Variable"; - break; - case "column": - title = "Add Column Variable"; - break; - case "independent": - title = "Add Independent Variable"; - break; - case "dependent": - title = "Set Dependent Variable"; - break; - case "measure": - title = "Set Measure Variable"; - break; - case "correlation": - title = "Add Correlation Variable"; - break; - } - registry.byId("variables.title").set("label", title); - registry.byId("variables.title").set("style", "font-size: 1em;"); - }, - }); - }); diff --git a/js/VariableMetadata.js b/js/VariableMetadata.js deleted file mode 100644 index 8220b1ed6390425dadd8a72617335b3fb6be2d84..0000000000000000000000000000000000000000 --- a/js/VariableMetadata.js +++ /dev/null @@ -1,34 +0,0 @@ -/*global define, splash */ -define(['dojo/_base/declare', - 'dojox/mobile/Container', - 'dojo/_base/lang', - 'nesstartouch/VariableMetadataBuilder'], function (declare, Container, lang, Builder) { - return declare('nesstartouch.VariableMetadata', [Container], { - variableMetadataBuilder : null, - variableId: null, - - startup : function () { - this.inherited(arguments); - var parent = this.getParent(), - self = this; - - parent.onAfterTransitionIn = function () { - if (!self.variableMetadataBuilder) { - self.variableMetadataBuilder = new Builder(); - } - - if (this.variableId !== window.nesstartouch.variableMetadata.id) { - this.variableId = window.nesstartouch.variableMetadata.id; - splash.startLoading(); - } - - self.variableMetadataBuilder.getVariableMetadata(this.variableId, parent, 0, lang.hitch(self, self.updateMetadata)); - }; - }, - - updateMetadata: function (html) { - this.domNode.innerHTML = html; - splash.endLoading(); - } - }); -}); diff --git a/js/VariableMetadataBuilder.js b/js/VariableMetadataBuilder.js deleted file mode 100644 index 20b03f3a2b8a2cba97b066423d8edace49bb20e6..0000000000000000000000000000000000000000 --- a/js/VariableMetadataBuilder.js +++ /dev/null @@ -1,186 +0,0 @@ -/*global define */ -define(['dojo/_base/declare', - 'dojo/_base/array', - 'dojox/lang/functional', - 'dojox/mobile/RoundRectCategory', - 'dojo/dom-construct', - 'dojo/number', - 'nesstartouch/_TextMixin', - 'nesstartouch/_RestMixin'], function (declare, arrayUtil, functional, RoundRectCategory, domConstruct, number, _TextMixin, _RestMixin) { - "use strict"; - return declare('nesstartouch.VariableMetadataBuilder', [_TextMixin, _RestMixin], { - variableId: "", - html: "", - callbackFunction : null, - indexOfVariable: 0, - - getVariableMetadata : function (variableId, widgetParent, index, callbackMethod) { - this.callbackFunction = callbackMethod; - this.indexOfVariable = index; - - if (widgetParent) { - widgetParent.scrollTo({x: 0}); - } - - this.variableId = variableId; - - if (!this._checkIfTranslationMetadataFileExist()) { - this._loadTranslationMetadataFile('en'); - } else { - this.populate(this._updateContent, {'variableId': this.variableId}, {}, {}, "/variable/${variableId}"); - } - }, - - _loadTranslationMetadataFile: function (languageCode) { - var that = this; - this.populate(function (data) { - window.nesstartouch.stores.metadataTranslation = data.metadataTranslation; - that.populate(this._updateContent, {'variableId': this.variableId}, {}, {}, "/variable/${variableId}"); - }, {'languageCode': languageCode}, {}, {}, '/metadataTranslation/${languageCode}'); - }, - - _updateContent : function (variableMetadata) { - this.variable = variableMetadata.variable; - this.variableId = this.variable.id || {}; - this.html = ""; - this._addMetadata(); - this._showContent(); - }, - - _addMetadata: function () { - var metadata = "", - section, - value, - item; - - //add variable name - section = new RoundRectCategory({'label': "Name"}); - metadata += section.domNode.outerHTML; - item = this.createParagraphsFromText(this.variable.labl, {'class': 'variableMetadataText'}); - metadata += item.outerHTML; - - //add questions - arrayUtil.forEach(this._questionTypes, function (type) { - if (this.variable.qstn.hasOwnProperty(type.name) && 0 !== this.variable.qstn[type.name].length) { - section = new RoundRectCategory({'label': type.label}); - value = this.variable.qstn[type.name]; - metadata += section.domNode.outerHTML; - - if (type.name !== 'categories') { - item = this.createParagraphsFromText(value, {'class': 'variableMetadataText'}); - metadata += item.outerHTML; - } - } - }, this); - - section = new RoundRectCategory({'label': "Category"}); - metadata += section.domNode.outerHTML; - metadata += this._createCategoryTable(); - - this.html += metadata + '\n
              \n'; - }, - - _createCategoryTable : function () { - var properties = this._categoryTypes, - table = domConstruct.create('table', {'class': 'variableMetadataText'}), - bars = this._calculateBars(), - domProperties; - - this._createTableHeader(table); - - arrayUtil.forEach(this.variable.catgry, function (item, index) { - var tr = domConstruct.create('tr', null, table); - arrayUtil.forEach(properties, function (attr) { - if (item[attr.name] !== undefined) { - if (typeof item[attr.name] === "object") { - domProperties = {'innerHTML': item[attr.name][0].content, 'class': attr.name}; - } else { - domProperties = {'innerHTML': item[attr.name], 'class': attr.name}; - } - domConstruct.create('td', domProperties, tr); - } else { - domConstruct.create('td', {innerHTML: ""}, tr); - } - - }, this); - this._addBarToTable(bars[index], tr); - }, this); - - return table.outerHTML; - }, - - _createTableHeader: function (table) { - var headTr = domConstruct.create('tr', null, table); - arrayUtil.forEach(this._categoryTypes, function (attr) { - domConstruct.create('th', {'innerHTML': attr.label, 'class': attr.name}, headTr); - }); - domConstruct.create('th', { 'innerHTML': '', 'class': 'bars'}, headTr); - }, - - _calculateBars : function () { - var total = this._calculateTotal(); - - return arrayUtil.map(this.variable.catgry, function (category, index) { - return parseInt(category.catStat[0].content, 0) / total * 100; - }); - }, - - _calculateTotal: function () { - var total = 0; - arrayUtil.forEach(this.variable.catgry, function (category) { - total += parseInt(category.catStat[0].content, 0); - }); - return total; - }, - - _addBarToTable: function (percentage, parentElement) { - var formattedPercentage, - barHTML; - - if (percentage === null || isNaN(percentage)) { - return; - } - formattedPercentage = number.format(percentage, {pattern : '#,##0.#'}); - barHTML = '
              ' + formattedPercentage + '%
              '; - domConstruct.create('td', {'innerHTML': barHTML}, parentElement); - }, - - _showContent : function () { - this.callbackFunction(this.html, this.variable.labl, this.indexOfVariable); - }, - - _questionTypes : [ - { - 'label': 'Pre Question', - 'name': 'preQTxt' - }, - { - 'label': 'Post Question', - 'name': 'postQTxt' - }, - { - 'label': 'Literal Question', - 'name': 'qstnLit' - }, - { - 'label': 'Interviewer Instruction', - 'name': 'ivuInstr' - } - ], - - _categoryTypes: [ - { - 'label': 'Value', - 'name': 'catValu' - }, - { - 'label': 'Categories', - 'name': 'labl' - }, - { - 'label': 'N', - 'name': 'catStat' - } - ], - }); -}); diff --git a/js/_Console.js b/js/_Console.js deleted file mode 100644 index cacb5a75339eb4d83fe4bebd702b2600e6d5f605..0000000000000000000000000000000000000000 --- a/js/_Console.js +++ /dev/null @@ -1,92 +0,0 @@ -/*global define */ -define(['dojo/_base/declare'], - function (declare) { - "use strict"; - return declare('nesstartouch.Console', null, { - numberOfAttributesToShow: 9, - - constructor: function () { - var that = this, - x, - arg, - line; - - this._createOutputConsoleStyling(); - this._createOutputConsole(); - window.console.log = function () { - for (x = 0; x < arguments.length; x = x + 1) { - arg = arguments[x]; - - if (typeof arg === 'object') { - line = that.objectTraverser(arg); - } else { - line = document.createElement('p'); - line.innerHTML = arg; - } - that.output.appendChild(line); - line.scrollIntoView(false); - } - }; - - window.onerror = function (msg, url, line) { - window.console.log('Error: ' + msg + ' (' + url + ':' + line + ')'); - }; - }, - - objectTraverser: function (object) { - var ul = document.createElement('ul'), - limit = 0, - att, - type, - value, - item, - li; - - for (att in object) { - if (object.hasOwnProperty(att)) { - type = typeof object[att]; - value = object[att]; - item = att + '(' + type + '): ' + value; - li = document.createElement('li'); - li.innerHTML = item; - ul.appendChild(li); - limit = limit + 1; - if (limit > this.numberOfAttributesToShow) { - break; - } - } - } - return ul; - }, - - /* Eww, this will break in older browsers */ - /*jshint multistr: true */ - _createOutputConsoleStyling: function () { - var style = document.createElement('style'), - head = document.getElementsByTagName('head')[0]; - style.innerHTML = "\ - #console { \ - background-color: #fff; \ - border: 1px solid #333; \ - height: 250px; \ - width: 100%; \ - z-index: 9000; \ - position: fixed; \ - bottom: 5px; \ - } \ - #console p { \ - border-bottom: 1px solid #bbb;\ - line-height: 16px; \ - }"; - - head.appendChild(style); - }, - - _createOutputConsole: function () { - this.output = document.createElement('div'); - this.output.setAttribute('id', 'console'); - this.output.setAttribute('class', 'scrollable-view'); - document.body.appendChild(this.output); - }, - }); - }); diff --git a/js/_RestMixin.js b/js/_RestMixin.js deleted file mode 100644 index fee0dd3fceff96dc0fad09a430618f4a56853f7b..0000000000000000000000000000000000000000 --- a/js/_RestMixin.js +++ /dev/null @@ -1,97 +0,0 @@ -/*global define */ -define(['dojo/_base/declare', - 'dojo/_base/lang', - 'dojo/request', - 'dojo/json', - 'nesstarconfig/config'], function (declare, lang, request, jsonUtils) { - - "use strict"; - return declare('nesstartouch._RestMixin', null, { - defaultOptions: { - method: 'GET', - preventCache: true, - timeout: 30000, - handleAs: 'json', - headers: { - 'Content-Type': 'application/json' - } - }, - - /** - Send the request to the server. - - * callback: The function to call when the request returns. - * urlProperties: An object containing any key/value pairs to substitute in the URL. - * userOptions: An optional object with request options. Values in this object will - override the corresponding value in the defualtOptions object. This is handy for - using another HTTP method (say, POST) or adding data to the request. - */ - populate: function (callback, urlProperties, userOptions, data, urlOverride, errorMethod) { - var url = this.substitute(urlOverride || this.serviceUrl, urlProperties), - options, - promise; - - url = this.addBaseUrl(url); - if (data !== undefined && null !== data) { - userOptions.data = data; - } - - options = this.getOptions(userOptions); - promise = request(url, options); - - if (errorMethod) { - promise.then(lang.hitch(this, callback), errorMethod); - } else { - promise.then(lang.hitch(this, callback), this.handleError); - } - - - }, - - /** - Substitutes named wildcards in the default URL with user-specified values. - For example, if the url /foo/${id}/bar/${baz}/list the user can (read: must) - supply an object like: { 'id': 123, 'baz': 'some-value' } - */ - substitute: function (template, values) { - return template.replace(/\$\{([^\s\:\}]+)(?:\:([^\s\:\}]+))?\}/g, function (match, key) { - return values[key]; - }); - }, - - addBaseUrl: function (originalUrl) { - if (window.config) { - var base = window.config.baseUrl; - if (base.indexOf('/', base.length - 1) !== -1) { - base = base.substring(0, base.length - 1); - } - return base + originalUrl; - } - return originalUrl; - }, - - getOptions: function (userOptions) { - if (!userOptions) { - return this.defaultOptions; - } - - var mergedOptions = this.mergeOptions(this.defaultOptions, userOptions); - if (mergedOptions.data !== undefined) { - mergedOptions.data = jsonUtils.stringify(mergedOptions.data); - } - return mergedOptions; - }, - - mergeOptions: function (masterOptions, userOptions) { - var mergedOptions = {}; - lang.mixin(mergedOptions, masterOptions); - lang.mixin(mergedOptions, userOptions); - return mergedOptions; - }, - - handleError: function (errorData) { - console.log("An error occurred while talking to the server:"); - console.log(errorData); - } - }); -}); diff --git a/js/_TextMixin.js b/js/_TextMixin.js deleted file mode 100644 index a2bd8c193b1b55fe845d696389f9889d5c523942..0000000000000000000000000000000000000000 --- a/js/_TextMixin.js +++ /dev/null @@ -1,57 +0,0 @@ -/*global define */ -define(['dojo/_base/declare', - 'dojo/_base/array', - 'dojo/_base/lang', - 'dojo/dom-construct', - 'dojo/dom-class'], - function (declare, arrayUtil, lang, domConstruct, domClass) { - "use strict"; - return declare('nesstartouch._TextMixin', null, { - defaultTextOptions: { - separator : "\n", - }, - - createParagraphsFromText: function (text, options) { - var textOptions = this._mergeOptionsWithDefault(options), - parentElement = domConstruct.create("div"), - textParts, - paragraph; - - this._addClassToElement(parentElement, textOptions); - if (text) { - textParts = text.split(textOptions.separator); - arrayUtil.forEach(textParts, function (part) { - paragraph = domConstruct.create('p', {'innerHTML': part}, parentElement); - }, this); - } - return parentElement; - }, - - _addClassToElement: function (element, options) { - if (options['class'] !== undefined) { - domClass.add(element, options['class']); - } - }, - - _mergeOptionsWithDefault: function (options) { - var mergedOptions = {}; - lang.mixin(mergedOptions, this.defaultTextOptions); - lang.mixin(mergedOptions, options); - return mergedOptions; - }, - - _checkIfTranslationMetadataFileExist: function () { - if (!window.nesstartouch.stores) { - window.nesstartouch.stores = {}; - return false; - } - return window.nesstartouch.stores.metadataTranslation !== undefined; - }, - - _convertLineBreak: function (input, className) { - var result = input.replace(/\r\n\r\n/g, "

              ").replace(/\n\n/g, "

              "); - result = result.replace(/\r\n/g, "
              ").replace(/\n/g, "
              "); - return result; - }, - }); - }); diff --git a/js/_VariableMixin.js b/js/_VariableMixin.js deleted file mode 100644 index b48a9ac0a700fe2834909cb89dfe03cdb15d4f26..0000000000000000000000000000000000000000 --- a/js/_VariableMixin.js +++ /dev/null @@ -1,117 +0,0 @@ -/*global define, addVariableList, variableView */ -define(['dojo/_base/declare', - 'dojo/dom-style', - 'dojo/_base/fx', - 'dojo/on', - 'dojo/dom', - 'dojo/dom-geometry', - 'dojo/_base/lang'], - function (declare, domStyle, fx, on, dom, domGeometry) { - "use strict"; - return declare('nesstartouch._VariableMixin', null, { - setVariableListItemProperties: function (variable, callback) { - var variableObject = { - 'id': variable.id, - 'name': variable.name, - 'label': variable.label, - 'deleteIcon': null, - 'rightIcon': 'images/detail.png', - 'noArrow': true, - 'class': 'variableMetadataClick', - 'variable': variable, - 'clickable': true, - 'transitionDir': -1, - 'onDimension': 'none', - 'click': callback - }; - - return variableObject; - }, - - hideScrollToTopButton: function (timeout) { - setTimeout(function () { - fx.fadeOut({ - node: 'gototop', - onEnd: function (node) { - domStyle.set(node, 'visibility', 'hidden'); - } - }).play(); - }, timeout); - }, - - showScrollToTopButton: function (timeout) { - setTimeout(function () { - fx.fadeIn({ - node: 'gototop', - onEnd: function (node) { - domStyle.set(node, 'visibility', 'visible'); - } - }).play(); - }, timeout); - }, - - setScrollToTopButton: function (parent) { - var self = this; - parent.adjustDestination = function (to, pos, dim) { - //if the scroll destination direction is downward - //and list height is larger than window's height, show the scroll-top button - if (to.y < 0 && dim.v.h < dim.c.h + 50) { - self.showScrollToTopButton(200); - //hide it 2.5s later - self.hideScrollToTopButton(2500); - } else { - self.hideScrollToTopButton(200); - } - }; - }, - - bindClickEventToScrollTopButton: function (view) { - var self = this; - on(dom.byId('gototop'), 'click', function () { - view.scrollTo({x: 0, y: 0}, false); - self.hideScrollToTopButton(0); - }); - }, - - placeVariableOnDimensionCallback: function (e) { - var listItem = addVariableList.setVariableListItemProperties(this.variable, undefined), - targetDimension = window.nesstartouch.variableType || 'none', - position = window.nesstartouch.stores.variableStore.query({onDimension: targetDimension}).length; - - if (targetDimension !== 'none') { - listItem.deleteIcon = "mblDomButtonRedCircleMinus"; - } - listItem.rightIcon = undefined; - - listItem.onDimension = targetDimension; - listItem.listorder = position; - - if (addVariableList.isSingleVariableDimension(targetDimension)) { - addVariableList.unmarkPreviouslySelected(targetDimension); - } - - addVariableList.replaceItemInList(listItem, this.id); - window.nesstartouch.variableType = 'none'; - this.destroyRecursive(false); - variableView.performTransition('#settings', -1, "slide"); - }, - - isSingleVariableDimension: function (dimension) { - return dimension === 'measure' || dimension === 'dependent'; - }, - - unmarkPreviouslySelected: function (dimension) { - var list = window.nesstartouch.stores.variableStore.query({onDimension: dimension}), - callback = this.placeVariableOnDimensionCallback, - unmarkedItem; - list.forEach(function (previouslyMarkedItem) { - unmarkedItem = this.setVariableListItemProperties(previouslyMarkedItem.variable, callback); - this.replaceItemInList(unmarkedItem, previouslyMarkedItem.id); - }, this); - }, - - replaceItemInList: function (item, id) { - window.nesstartouch.stores.variableStore.put(item, {'id': id, 'overwrite': true}); - }, - }); - }); diff --git a/js/common.js b/js/common.js new file mode 100644 index 0000000000000000000000000000000000000000..f75946fbca4e89748798292cb3175dcded952d59 --- /dev/null +++ b/js/common.js @@ -0,0 +1,32 @@ +function loadFromRestServer(urlEnding) { + return syncAjax(Model.restServerURL + "/" + urlEnding, "json"); +} + +function getJSON(urlString) { + return syncAjax(urlString, "json"); +} + +function syncAjax(urlString, dataType) { + var result = null; + $.ajax({ + url: urlString, + datatype: dataType, + async: false, + success: function(data) { + result = data; + }, + error: function(jqXHR, textStatus, errorThrown) { + console.log("Error from model.js -> getJSON:"); + console.log("jqXHR:"); + console.log(jqXHR); + console.log("textStatus: " + textStatus); + console.log("errorThrown: " + errorThrown); + console.log("urlString: " + urlString); + } + }); + return result; +} + +function getTranslation(text) { + return text; +} \ No newline at end of file diff --git a/js/controller.js b/js/controller.js new file mode 100644 index 0000000000000000000000000000000000000000..d26ed68750d5ef7940bdebb0afa18b11aea01cc7 --- /dev/null +++ b/js/controller.js @@ -0,0 +1,121 @@ +var AppRouter = Backbone.Router.extend({ + routes: { + // Actions + "goto/*route" : "goto", + "goBack" : "goBack", + "useVariableAndGoBack/:variableId" : "useVariableAndGoBack", + // Pages + "" : "frontPage", + "studies/*urlObject" : "studies", + "studyMetadata/:studyId/*urlObject" : "studyMetadata", + "variableMetadata/:variableId/*urlObject" : "variableMetadata" + }, + + // Actions + + goto: function(route) { + console.log("goto: " + route); + Model.urlObject.backRoutes.push(route); + appRouter.navigate(route+"/"+getUrlString(), {trigger:true, replace: true}); + }, + + goBack: function() { + console.log("goBack."); + Model.urlObject.backRoutes.pop(); + appRouter.goto(Model.urlObject.backRoutes.pop()); + }, + + + useVariableAndGoBack: function(variableId) { + console.log("userVariableAndGoBack: " + variableId) + var store = Model.urlObject[Model.urlObject.currentAnalysisType][Model.urlObject.currentVariableStore]; + if (store instanceof Array) { + store.push(variableId); + } + else { + Model.urlObject[Model.urlObject.currentAnalysisType][Model.urlObject.currentVariableStore] = variableId; + } + appRouter.goBack(); + }, + + // Pages + + frontPage: function() { + console.log("frontPage"); + initNewTabulation(); + appRouter.goto("studies"); + }, + + studies: function(urlString) { + saveUrlString(urlString); + showStudies(); + }, + + studyMetadata: function(studyId, urlString) { + saveUrlString(urlString); + showStudyMetadata(studyId); + }, + + variableMetadata: function(variableId, urlString) { + console.log("variableMetadata"); + saveUrlString(urlString); + showVariableMetadata(variableId); + } + +}); + +var appRouter = new AppRouter; + +Backbone.history.start(); + +// --------------------------------- // + +function getUrlString() { + var jsonString = JSON.stringify(Model.urlObject); + return encodeURIComponent(jsonString); +} + +function saveUrlString(urlString) { + if (!Model.urlObjectSaved) { + var urlObject = JSON.parse(urlString); + Model.urlObject = urlObject; + Model.urlObjectSaved = true; + } +} + +// --------------------------------- // + +function showStudies() { + if (!Model.studies) { + Model.studies = loadFromRestServer("studies").studies; + } + var html = studiesTemplate(Model); + $('#nesstarTouchContent').empty(); + $('#nesstarTouchContent').append(html); +} + +function showStudyMetadata(studyId) { + var studyMetadata = loadFromRestServer("study/"+studyId); + var templateObject = {} + templateObject.variables = loadFromRestServer("study/"+studyId+"/variables").variables; + + $('#nesstarTouchContent').empty(); + var html = studyMetadataTemplate(templateObject); + $('#nesstarTouchContent').append(html); + + html = getMetadataHtml(Model.studyMetadataSelection, studyMetadata); + $('#studyMetadata').append(html); +} + +function showVariableMetadata(variableId) { + var variableMetadata = loadFromRestServer("variable/"+variableId); + var templateObject = {} + templateObject.variableId = variableId; + + $('#nesstarTouchContent').empty(); + var html = variableMetadataTemplate(templateObject); + $('#nesstarTouchContent').append(html); + + html = getMetadataHtml(Model.variableMetadataSelection, variableMetadata); + $('#variableMetadata').append(html); +} \ No newline at end of file diff --git a/js/metadata-maker.js b/js/metadata-maker.js new file mode 100644 index 0000000000000000000000000000000000000000..12f8ad8b74dbbe6457bfe18e4e38ef40d869f270 --- /dev/null +++ b/js/metadata-maker.js @@ -0,0 +1,298 @@ +function getMetadataHtml(metadataSelection, metadata) { + var result = ""; + for (var prop in metadataSelection) { + var obj = metadataSelection[prop]; + var html = null; + switch (obj.type) { + case "heading": + html = getHeadingHtml(obj, metadata); + break; + case "text": + html = getMetadataTextHtml(obj, metadata); + break; + case "list": + html = getMetadataListHtml(obj, metadata); + break; + case "table": + html = getMetadataTableHtml(obj, metadata); + break; + case "sumStat": + html = getMetadataSumStatHtml(obj, metadata); + break; + case "categories": + html = getMetadataCategoriesHtml(obj, metadata); + } + if (html) { + result += "\n" + html; + } + } + return result; +} + +function getHeadingHtml(metadataSelection, metadata) { + var templateObject = {} + templateObject.heading = metadataSelection.heading; + return metadataHeadingTemplate(templateObject); +} + +function getMetadataTextHtml(metadataSelection, metadata) { + var templateObject = {} + templateObject.heading = getLabel(metadataSelection.heading, metadataSelection.field); + var metadataPart = getObjectValue(metadata, metadataSelection.field); + templateObject.fields = getTemplateObjectFields(metadataSelection.innerFields, metadataPart); + if (templateObject.fields.length > 0) { + return metadataTextTemplate(templateObject); + } + else { + return null; + } +} + +function getLabel(label, field) { + if (label == "--default--") { + var fields = field.split('.'); + var lastField = fields[fields.length-1]; + return Model.metadataTranslation[lastField]; + } + else { + return getTranslation(label); + } +} + +function getTemplateObjectFields(fields, metadata) +{ + var result = [] + $.each(fields, function(index, field) { + var content; + var label; + for (var prop in field) { + content = metadata[prop]; + label = getLabel(field[prop], prop); + } + if (content) { + var obj = {} + obj.label = label; + obj.content = content + result.push(obj); + } + }); + return result; +} + +function getObjectValue(obj, dotNotationString) { + var props = dotNotationString.split("."); + var result = obj; + $.each(props, function(index, prop) { + result = result[prop]; + }); + return result; +} + +function getMetadataListHtml(metadataSelection, metadata) { + var templateObject = {} + templateObject.heading = getLabel(metadataSelection.heading, metadataSelection.field); + templateObject.entry = [] + var entries = getObjectValue(metadata, metadataSelection.field); + $.each(entries, function(index, entry) { + var fields = getTemplateObjectFields(metadataSelection.innerFields, entry); + var obj = {}; + obj.fields = fields; + templateObject.entry.push(obj); + }); + return metadataListTemplate(templateObject); +} + +function getMetadataTableHtml(metadataSelection, metadata) { + var templateObject = {} + templateObject.heading = getLabel(metadataSelection.heading, metadataSelection.field); + var metadataPart = getObjectValue(metadata, metadataSelection.field); + var data = []; + $.each(metadataPart, function(index, item){ + var fields = getTemplateObjectFields(metadataSelection.innerFields, item); + if (index == 0) { + data.push(getColumns(fields, true)); + } + data.push(getColumns(fields, false)); + }); + templateObject.data = data; + return metadataTableTemplate(templateObject); +} + +function getColumns(fields, isHeading) { + var columns = []; + var prop = "content"; + if (isHeading) { + prop = "label"; + } + $.each(fields, function(index, item) { + var col = getCol(item[prop], isHeading); + columns.push(col); + }); + return columns; +} + +function getMetadataSumStatHtml(metadataSelection, metadata) { + var templateObject = {} + templateObject.heading = getLabel(metadataSelection.heading, metadataSelection.field); + var metadataPart = getObjectValue(metadata, metadataSelection.field); + + var data = [] + data.push([getCol(""), getCol("Not Weighted", true), getCol("Weighted", true)]); + data.push([getCol("Valid Cases", true), getCol(""), getCol("")]); + data.push([getCol("Missing Cases", true), getCol(""), getCol("")]); + data.push([getCol("Minimum", true), getCol(""), getCol("")]); + data.push([getCol("Maximum", true), getCol(""), getCol("")]); + data.push([getCol("Mean", true), getCol(""), getCol("")]); + data.push([getCol("Standard Deviation", true), getCol(""), getCol("")]); + + var isWeighted = false; + $.each(metadataPart, function(index, item){ + var column; + if (item.wgtd == "wgtd") { + column = 2; + isWeighted = true; + } + else { + column = 1; + } + switch (item.type) { + case "vald": data[1][column].value = item.content; break; + case "invd": data[2][column].value = item.content; break; + case "min": data[3][column].value = item.content; break; + case "max": data[4][column].value = item.content; break; + case "mean": data[5][column].value = item.content; break; + case "stdev": data[6][column].value = item.content; break; + } + }); + if (!isWeighted) { + data.splice(0,1); + removeLastColumn(data); + } + + templateObject.data = data; + + return metadataTableTemplate(templateObject); +} + + +function getCol(value) { + return getCol(value, false) +} + +function getCol(value, isHeading) { + return getCol(value, false, false); +} + +function getCol(value, isHeading, isPercentBar) { + var translatedValue = value; + if (isHeading) { + translatedValue = getTranslation(value); + } + return {"value" : translatedValue, "isHeading" : isHeading, "isPercentBar" : isPercentBar} +} +function removeLastColumn(data) { + $.each(data, function(index, item) { + item.splice(-1, 1); + }); +} + +function getMetadataCategoriesHtml(metadataSelection, metadata) { + var templateObject = {} + templateObject.heading = getLabel(metadataSelection.heading, metadataSelection.field); + var metadataPart = getObjectValue(metadata, metadataSelection.field); + + var categories = []; + getCategories(metadataPart, categories); + + var isWeighted = containsWeightedCategories(categories); + getFreqPercents(categories, isWeighted); + + var data = [] + data.push([getCol("Value", true), getCol("Label", true), getCol("N", true)]); + if (isWeighted) { + data[0].push(getCol("NW", true)); + } + data[0].push(getCol("")); + + $.each(categories, function(index, cat) { + var columns = [getCol(cat.value), getCol(cat.label), getCol(cat.freq)]; + if (isWeighted) { + columns.push(getCol(cat.freqWeighted)); + } + if (cat.isMissing) { + columns.push(getCol(getTranslation("Missing"))); + } + else { + columns.push(getCol(cat.freqPercent, false, true)); + } + data.push(columns); + }) + templateObject.data = data; + + return metadataTableTemplate(templateObject); +} + +function getCategories(source, destination) { + $.each(source, function(index, category) { + var obj = {} + obj.isMissing = category.missing == "Y"; + obj.label = category.labl; + obj.value = category.catValu; + obj.freq = ""; + obj.freqWeighted = ""; + obj.freqPercent = 0; + obj.isWeighted = false; + $.each(category.catStat, function(index, catStat){ + if (catStat.type == "freq") { + if (catStat.wgtd == "wgtd") { + obj.freqWeighted = catStat.content; + obj.isWeighted = true; + } + else { + obj.freq = catStat.content; + } + } + }); + if (category.catgry.length > 0) { + obj.hasChildren = true; + } + else { + obj.hasChildren = false; + } + destination.push(obj); + getCategories(category.catgry, destination); + }); +} + +function containsWeightedCategories(categories) { + var result = false; + $.each(categories, function(index, category) { + if (category.isWeighted) { + result = true; + return true; + } + }); + return result; + +} + +function getFreqPercents(categories, isWeighted) { + var prop; + if (isWeighted) { + prop = "freqWeighted"; + } + else { + prop = "freq"; + } + var freqSum = 0; + $.each(categories, function(index, category) { + if (!category.isMissing) { + freqSum += parseInt(category[prop]); + } + }); + $.each(categories, function(index, category) { + if (!category.isMissing) { + category.freqPercent = (parseInt(category[prop]) * 100 / freqSum).toFixed(2); + } + }); +} \ No newline at end of file diff --git a/js/model.js b/js/model.js new file mode 100644 index 0000000000000000000000000000000000000000..69cc4acec2bb4e357aa0394a160e3de7ee05d846 --- /dev/null +++ b/js/model.js @@ -0,0 +1,71 @@ +var Model = { + + "restServerURL" : "http://localhost:8080", + + "urlObject" : { + "tabulation" : null, + "regression" : null, + "correlation" : null, + "backRoutes" : [], + "currentAnalysisType" : "", // tabulation / regression / correlation + "currentVariableStore" : "" // rowVariableIds / columnVariableIds /measureVariableId / dependentVariableId / independentVariableIds + }, + + "urlObjectSaved" : false, + + "studies" : null, + /* + [ + { + id: "text", + name : "text", + creationDate : number, + abstractText: "text" + } + ] + */ + + "variables" : null, + /* + [ + { + id : "text", + name : "text", + label : "text" + } + ] + */ + + "studyMetadataSelection" : null, + + "variableMetadataSelection" : null, + + "metadataTranslation" : null, +} + +function Tabulation() { + this.rowVariableIds = []; + this.columnVariableIds = []; + this.measureVariableId = ""; +} + +function Regression() { + this.dependentVariableId = ""; + this.independentVariableIds = [] +} + +function Correlation() { + this.correlationVariableIds = []; +} + +Model.studyMetadataSelection = getJSON("/metadata-selection/study-metadata-selection.json"); + +Model.variableMetadataSelection = getJSON("/metadata-selection/variable-metadata-selection.json"); + +Model.metadataTranslation = getJSON(Model.restServerURL + "/metadata-translation/en").metadataTranslation; + +function initNewTabulation() { + Model.urlObject.tabulation = new Tabulation(); + Model.urlObject.currentAnalysisType = "tabulation"; + Model.urlObject.currentVariableStore = "rowVariableIds"; +} \ No newline at end of file diff --git a/js/templates-loader.js b/js/templates-loader.js new file mode 100644 index 0000000000000000000000000000000000000000..0048e592859d29656c88bb2280d5693b30d6e716 --- /dev/null +++ b/js/templates-loader.js @@ -0,0 +1,23 @@ +var studiesTemplate = getTemplate("studies-template.html", "#studiesTemplate"); +var variableMetadataTemplate = getTemplate("variable-metadata-template.html", "#variableMetadataTemplate"); +var studyMetadataTemplate = getTemplate("study-metadata-template.html", "#studyMetadataTemplate"); + +metadataTemplates = getTemplateFile("metadata-templates.html"); +var metadataHeadingTemplate = getTemplateFromFile(metadataTemplates, "#metadataHeadingTemplate"); +var metadataTextTemplate = getTemplateFromFile(metadataTemplates, "#metadataTextTemplate"); +var metadataListTemplate = getTemplateFromFile(metadataTemplates, "#metadataListTemplate"); +var metadataTableTemplate = getTemplateFromFile(metadataTemplates, "#metadataTableTemplate"); + +function getTemplate(fileName, templateId) { + var templateFile = getTemplateFile(fileName); + return getTemplateFromFile(templateFile, templateId); +} + +function getTemplateFile(fileName) { + return syncAjax("/templates/" + fileName, "html"); +} + +function getTemplateFromFile(templateFile, templateId) { + var source = $(templateFile).filter(templateId).html(); + return Handlebars.compile(source); +} \ No newline at end of file diff --git a/metadata-selection/study-metadata-selection.json b/metadata-selection/study-metadata-selection.json new file mode 100644 index 0000000000000000000000000000000000000000..1cdbc978511d7f8dab1fb31249b80b0a44561d4b --- /dev/null +++ b/metadata-selection/study-metadata-selection.json @@ -0,0 +1,36 @@ +[ +{ + "type" : "heading", + "heading" : "Study Description" +}, +{ + "type" : "table", + "heading" : "--default--", + "field" : "studyMetadata.stdyDscr.stdyInfo.sumDscr.timePrd", + "innerFields" : [{"date" : "--default--"}, {"event" : "--default--"}, {"cycle" : "--default--"}] +}, +{ + "type" : "text", + "heading" : "Abstract", + "field" : "studyMetadata.stdyDscr.stdyInfo.abstract", + "innerFields" : [{"content" : null}] +}, +{ + "type" : "text", + "heading" : "Version", + "field" : "studyMetadata.stdyDscr.citation.verStmt.version", + "innerFields" : [{"content" : null}, {"date" : "--default--"}, {"type" : "--default--"}] +}, +{ + "type" : "list", + "heading" : "--default--", + "field" : "studyMetadata.stdyDscr.stdyInfo.subject.keyword", + "innerFields" : [{"content" : null}] +}, +{ + "type" : "list", + "heading" : "--default--", + "field" : "studyMetadata.stdyDscr.stdyInfo.sumDscr.nation", + "innerFields" : [{"content" : null}, {"abbr" : null}] +} +] \ No newline at end of file diff --git a/metadata-selection/variable-metadata-selection.json b/metadata-selection/variable-metadata-selection.json new file mode 100644 index 0000000000000000000000000000000000000000..c8c3925daf5443c623684d7e203f764780b5ebac --- /dev/null +++ b/metadata-selection/variable-metadata-selection.json @@ -0,0 +1,34 @@ +[ +{ + "type" : "heading", + "heading" : "Variable Description" +}, +{ + "type" : "text", + "heading" : "Label", + "field" : "variable", + "innerFields" : [{"labl" : null}] +}, +{ + "type" : "list", + "heading" : "--default--", + "field" : "variable.concept", + "innerFields" : [{"content" : null}] +}, +{ + "type" : "text", + "heading" : "--default--", + "field" : "variable.qstn", + "innerFields" : [{"postQTxt" : "--default--"}, {"qstnLit" : "--default--"}, {"ivuInstr" : "--default--"}, {"preQTxt" : "--default--"}] +}, +{ + "type" : "sumStat", + "heading" : "--default--", + "field" : "variable.sumStat" +}, +{ + "type" : "categories", + "heading" : "--default--", + "field" : "variable.catgry" +} +] \ No newline at end of file diff --git a/templates/metadata-templates.html b/templates/metadata-templates.html new file mode 100644 index 0000000000000000000000000000000000000000..40c1ddb5dafd05b2d49d19f1088944df1a9b0a8a --- /dev/null +++ b/templates/metadata-templates.html @@ -0,0 +1,50 @@ + + + + + + + \ No newline at end of file diff --git a/templates/studies-template.html b/templates/studies-template.html new file mode 100644 index 0000000000000000000000000000000000000000..9b2b9b2780b768c21d3879399f3a551d8e9c316c --- /dev/null +++ b/templates/studies-template.html @@ -0,0 +1,8 @@ + \ No newline at end of file diff --git a/templates/study-metadata-template.html b/templates/study-metadata-template.html new file mode 100644 index 0000000000000000000000000000000000000000..2dce34f5bcee8a0bb4659a28855e0475997038cf --- /dev/null +++ b/templates/study-metadata-template.html @@ -0,0 +1,9 @@ + \ No newline at end of file diff --git a/templates/variable-metadata-template.html b/templates/variable-metadata-template.html new file mode 100644 index 0000000000000000000000000000000000000000..3b65abcd065716b7f98d753980694de0911f0f0f --- /dev/null +++ b/templates/variable-metadata-template.html @@ -0,0 +1,6 @@ + \ No newline at end of file