From 5d55f0c087dd5fefa2e1e991d46db18886bd598f Mon Sep 17 00:00:00 2001 From: goldpbear Date: Thu, 8 Sep 2016 10:53:36 -0700 Subject: [PATCH 1/7] clean up and clarify each_place_item template helper; handle input types on a case-by-case basis --- src/sa_web/jstemplates/place-detail.html | 82 ++++++++++++++++++---- src/sa_web/static/js/handlebars-helpers.js | 57 ++++++++++++--- 2 files changed, 116 insertions(+), 23 deletions(-) diff --git a/src/sa_web/jstemplates/place-detail.html b/src/sa_web/jstemplates/place-detail.html index 3e62046448..fd6f40639b 100644 --- a/src/sa_web/jstemplates/place-detail.html +++ b/src/sa_web/jstemplates/place-detail.html @@ -47,19 +47,75 @@

- {{# attachments }} -
- {{ name }} -
- {{/ attachments }} - {{#each_place_item "submitter_name" "name" "location_type"}} -
- {{label}} -

{{nlToBr value }}

-
- {{/each_place_item }} +
+ {{# attachments }} +
+ {{ name }} +
+ {{/ attachments }} + + {{#each_place_item "submitter_name" "name" "location_type"}} +
+ {{ prompt }} + + {{#is type "datetime"}} +

{{nlToBr content}}

+ {{/is}} + + {{#is type "text"}} +

{{nlToBr content}}

+ {{/is}} + + {{#is type "textarea"}} +

{{nlToBr content}}

+ {{/is}} + + {{#is type "radio_big_buttons"}} +
+ {{#each content}} + {{#if selected}} + {{ label }} + {{/if}} + {{/each}} +
+ {{/is}} + + {{#is type "checkbox_big_buttons"}} +
+ {{#each content}} + {{#if selected}} + {{ label }} + {{/if}} + {{/each}} +
+ {{/is}} + + {{#is type "binary_toggle"}} +

+ {{#if content.selected}} + {{ content.selectedLabel }} + {{else}} + {{ content.unselectedLabel }} + {{/if}} +

+ {{/is}} + + {{#is type "dropdown"}} + {{#each content}} +

+ {{#if selected}} + {{nlToBr label}} + {{/if}} +

+ {{/each}} + {{/is}} + +
+
+ {{/each_place_item }} +
{{#if survey_config}} -
- {{/if}} +
+ {{/if}} \ No newline at end of file diff --git a/src/sa_web/static/js/handlebars-helpers.js b/src/sa_web/static/js/handlebars-helpers.js index 35cadd66c9..618ffa0f3e 100644 --- a/src/sa_web/static/js/handlebars-helpers.js +++ b/src/sa_web/static/js/handlebars-helpers.js @@ -181,25 +181,62 @@ var Shareabouts = Shareabouts || {}; options = args.slice(-1)[0]; exclusions = args.slice(0, args.length-1); + // iterate through all the form fields for this location_type _.each(selectedCategoryConfig.fields, function(item, i) { - // filter for the correct label/value pair - var display_value = _.filter(item.content, function(option) { - return option.value == self[item.name]; - })[0] || {}; + // handle input types on a case-by-case basis, building an appropriate + // context object for each + var userInput = self[item.name], + fieldType = item.type, + content; + + // special handling for checkboxes with only one item selected + // (which will be a string and not an array of strings) + if (fieldType === "checkbox_big_buttons" && !$.isArray(this[item.name])) { + // convert to an array of length 1 + userInput = [self[item.name]]; + } + + // case: plain text + if (fieldType === "text" || fieldType === "textarea" || fieldType === "datetime") { + content = userInput || ""; + } + // case: checkboxes, radio buttons, and dropdowns + else if (fieldType === "checkbox_big_buttons" || fieldType === "radio_big_buttons" || fieldType === "dropdown") { + content = []; + _.each(item.content, function(option) { + content.push({ + value: option.value, + label: option.label, + selected: (_.contains(userInput, option.value)) ? true : false + }); + }); + } + // case: binary toggle buttons + else if (fieldType === "binary_toggle") { + // NOTE: we assume that the first option listed under content + // corresponds to the "on" value of the toggle input + content = { + selectedValue: item.content[0].value, + selectedLabel: item.content[0].label, + unselectedValue: item.content[1].value, + unselectedLabel: item.content[1].label, + selected: (userInput == item.content[0].value) ? true : false + } + } var newItem = { name: item.name, - label: item.display_prompt, - // get the (possibly) translated label from a dropdown, radio, or select input, or get free text entry - value: display_value.label || this[item.name], - type: item.type + type: item.type, + content: content, + prompt: item.display_prompt, + isEditingToggled: this.isEditingToggled }; // if not an exclusion and not private data and not an empty response if (_.contains(exclusions, item.name) === false && item.name.indexOf('private-') !== 0 && - newItem.value != undefined && - newItem.value !== "") { + newItem.content != undefined && + newItem.content !== "") { result += options.fn(newItem); } }, this); From 559acf6b2877e3415512a7dc1435d84fd45c85a2 Mon Sep 17 00:00:00 2001 From: goldpbear Date: Thu, 8 Sep 2016 11:01:02 -0700 Subject: [PATCH 2/7] don't show a duplicated title field in place detail views and the list view --- src/sa_web/jstemplates/place-detail.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sa_web/jstemplates/place-detail.html b/src/sa_web/jstemplates/place-detail.html index fd6f40639b..ba19e51c8b 100644 --- a/src/sa_web/jstemplates/place-detail.html +++ b/src/sa_web/jstemplates/place-detail.html @@ -54,7 +54,7 @@

{{/ attachments }} - {{#each_place_item "submitter_name" "name" "location_type"}} + {{#each_place_item "submitter_name" "name" "location_type" "fullTitle" "title" "name"}}
{{ prompt }} From c09e392f69691c19ea3a7f60f382f76b9727a749 Mon Sep 17 00:00:00 2001 From: goldpbear Date: Thu, 8 Sep 2016 13:18:53 -0700 Subject: [PATCH 3/7] styling for place detail views --- src/sa_web/jstemplates/place-detail.html | 126 ++++++++++++----------- src/sa_web/static/scss/_content.scss | 24 +++++ 2 files changed, 88 insertions(+), 62 deletions(-) diff --git a/src/sa_web/jstemplates/place-detail.html b/src/sa_web/jstemplates/place-detail.html index ba19e51c8b..45564e42d7 100644 --- a/src/sa_web/jstemplates/place-detail.html +++ b/src/sa_web/jstemplates/place-detail.html @@ -40,80 +40,82 @@

{{ survey_count }} {{ survey_label_by_count }} {{^if survey_config}} - View On Map + View On Map {{/if}}
-
- {{# attachments }} -
- {{ name }} -
- {{/ attachments }} - - {{#each_place_item "submitter_name" "name" "location_type" "fullTitle" "title" "name"}} -
- {{ prompt }} - - {{#is type "datetime"}} -

{{nlToBr content}}

- {{/is}} - - {{#is type "text"}} -

{{nlToBr content}}

- {{/is}} - - {{#is type "textarea"}} -

{{nlToBr content}}

- {{/is}} - - {{#is type "radio_big_buttons"}} -
- {{#each content}} - {{#if selected}} - {{ label }} - {{/if}} - {{/each}} -
- {{/is}} - - {{#is type "checkbox_big_buttons"}} -
- {{#each content}} - {{#if selected}} - {{ label }} - {{/if}} - {{/each}} -
- {{/is}} - - {{#is type "binary_toggle"}} -

+ {{# attachments }} +

+ {{ name }} +
+ {{/ attachments }} + + {{#each_place_item "submitter_name" "name" "location_type" "fullTitle" "title" "name"}} +
+ {{ prompt }} + + {{#is type "datetime"}} +

{{nlToBr content}}

+ {{/is}} + + {{#is type "text"}} +

{{nlToBr content}}

+ {{/is}} + + {{#is type "textarea"}} +

{{nlToBr content}}

+ {{/is}} + + {{#is type "radio_big_buttons"}} +
    + {{#each content}} + {{#if selected}} +
  • {{ label }}
  • + {{/if}} + {{/each}} +
+ {{/is}} + + {{#is type "checkbox_big_buttons"}} +
    + {{#each content}} + {{#if selected}} +
  • {{ label }}
  • + {{/if}} + {{/each}} +
+ {{/is}} + + {{#is type "binary_toggle"}} +
    +
  • {{#if content.selected}} {{ content.selectedLabel }} {{else}} {{ content.unselectedLabel }} {{/if}} -

    - {{/is}} - - {{#is type "dropdown"}} - {{#each content}} -

    - {{#if selected}} +

  • +
+ {{/is}} + + {{#is type "dropdown"}} + {{#each content}} + {{#if selected}} +
    +
  • {{nlToBr label}} - {{/if}} -

    - {{/each}} - {{/is}} - -
    -
- {{/each_place_item }} - + + + {{/if}} + {{/each}} + {{/is}} + +
+
+ {{/each_place_item }}
{{#if survey_config}} diff --git a/src/sa_web/static/scss/_content.scss b/src/sa_web/static/scss/_content.scss index 06921bbaee..2bc96676a9 100644 --- a/src/sa_web/static/scss/_content.scss +++ b/src/sa_web/static/scss/_content.scss @@ -147,6 +147,30 @@ a.close-btn { } } +.place-items { + .place-item { + margin-top: 20px; + margin-bottom: 20px; + } + + ul { + margin: 0; + } + + .place-label { + font-weight: bold; + } + + .place-value { + color: #777777; + word-break: break-all; + } + + .multi-select-response { + padding: 0; + } +} + .place-submission-details { display: block; padding-left: 3.75em; From 5df88d80aedfc1627a6131614ac4ca581a4b8856 Mon Sep 17 00:00:00 2001 From: goldpbear Date: Thu, 8 Sep 2016 13:19:29 -0700 Subject: [PATCH 4/7] small change to each_place_item template helper --- src/sa_web/static/js/handlebars-helpers.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/sa_web/static/js/handlebars-helpers.js b/src/sa_web/static/js/handlebars-helpers.js index 618ffa0f3e..3519c7c6f1 100644 --- a/src/sa_web/static/js/handlebars-helpers.js +++ b/src/sa_web/static/js/handlebars-helpers.js @@ -189,19 +189,16 @@ var Shareabouts = Shareabouts || {}; fieldType = item.type, content; - // special handling for checkboxes with only one item selected - // (which will be a string and not an array of strings) - if (fieldType === "checkbox_big_buttons" && !$.isArray(this[item.name])) { - // convert to an array of length 1 - userInput = [self[item.name]]; - } - // case: plain text if (fieldType === "text" || fieldType === "textarea" || fieldType === "datetime") { content = userInput || ""; } // case: checkboxes, radio buttons, and dropdowns else if (fieldType === "checkbox_big_buttons" || fieldType === "radio_big_buttons" || fieldType === "dropdown") { + // if input is not an array, convert to an array of length 1 + if (!$.isArray(this[item.name])) { + userInput = [self[item.name]]; + } content = []; _.each(item.content, function(option) { content.push({ @@ -228,8 +225,7 @@ var Shareabouts = Shareabouts || {}; name: item.name, type: item.type, content: content, - prompt: item.display_prompt, - isEditingToggled: this.isEditingToggled + prompt: item.display_prompt }; // if not an exclusion and not private data and not an empty response From 0b7a838def79ff780703576eef4fb9740421b8d6 Mon Sep 17 00:00:00 2001 From: goldpbear Date: Thu, 8 Sep 2016 13:49:00 -0700 Subject: [PATCH 5/7] ignore place detail items with no response --- src/sa_web/static/js/handlebars-helpers.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/sa_web/static/js/handlebars-helpers.js b/src/sa_web/static/js/handlebars-helpers.js index 3519c7c6f1..00b7ccd65a 100644 --- a/src/sa_web/static/js/handlebars-helpers.js +++ b/src/sa_web/static/js/handlebars-helpers.js @@ -187,11 +187,15 @@ var Shareabouts = Shareabouts || {}; // context object for each var userInput = self[item.name], fieldType = item.type, - content; + content, + wasAnswered = false; // case: plain text if (fieldType === "text" || fieldType === "textarea" || fieldType === "datetime") { content = userInput || ""; + if (content !== "") { + wasAnswered = true; + } } // case: checkboxes, radio buttons, and dropdowns else if (fieldType === "checkbox_big_buttons" || fieldType === "radio_big_buttons" || fieldType === "dropdown") { @@ -201,10 +205,15 @@ var Shareabouts = Shareabouts || {}; } content = []; _.each(item.content, function(option) { + var selected = false; + if (_.contains(userInput, option.value)) { + selected = true; + wasAnswered = true; + } content.push({ value: option.value, label: option.label, - selected: (_.contains(userInput, option.value)) ? true : false + selected: selected }); }); } @@ -219,20 +228,21 @@ var Shareabouts = Shareabouts || {}; unselectedLabel: item.content[1].label, selected: (userInput == item.content[0].value) ? true : false } + wasAnswered = true; } var newItem = { name: item.name, type: item.type, content: content, - prompt: item.display_prompt + prompt: item.display_prompt, + wasAnswered: wasAnswered }; - // if not an exclusion and not private data and not an empty response if (_.contains(exclusions, item.name) === false && item.name.indexOf('private-') !== 0 && newItem.content != undefined && - newItem.content !== "") { + newItem.wasAnswered === true) { result += options.fn(newItem); } }, this); From 38cc0b54e386fd00ef6b358badabb412a6745993 Mon Sep 17 00:00:00 2001 From: goldpbear Date: Thu, 8 Sep 2016 20:32:35 -0700 Subject: [PATCH 6/7] fix a bug --- src/sa_web/static/js/handlebars-helpers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sa_web/static/js/handlebars-helpers.js b/src/sa_web/static/js/handlebars-helpers.js index 00b7ccd65a..5fe105e1a6 100644 --- a/src/sa_web/static/js/handlebars-helpers.js +++ b/src/sa_web/static/js/handlebars-helpers.js @@ -200,7 +200,7 @@ var Shareabouts = Shareabouts || {}; // case: checkboxes, radio buttons, and dropdowns else if (fieldType === "checkbox_big_buttons" || fieldType === "radio_big_buttons" || fieldType === "dropdown") { // if input is not an array, convert to an array of length 1 - if (!$.isArray(this[item.name])) { + if (!$.isArray(self[item.name])) { userInput = [self[item.name]]; } content = []; From e1177e8c021d3fabc1797958149fa84805dbda30 Mon Sep 17 00:00:00 2001 From: goldpbear Date: Thu, 8 Sep 2016 20:39:44 -0700 Subject: [PATCH 7/7] better comment syntax --- src/sa_web/static/js/handlebars-helpers.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/sa_web/static/js/handlebars-helpers.js b/src/sa_web/static/js/handlebars-helpers.js index 5fe105e1a6..74de18e11f 100644 --- a/src/sa_web/static/js/handlebars-helpers.js +++ b/src/sa_web/static/js/handlebars-helpers.js @@ -190,15 +190,14 @@ var Shareabouts = Shareabouts || {}; content, wasAnswered = false; - // case: plain text if (fieldType === "text" || fieldType === "textarea" || fieldType === "datetime") { + // case: plain text content = userInput || ""; if (content !== "") { wasAnswered = true; } - } - // case: checkboxes, radio buttons, and dropdowns - else if (fieldType === "checkbox_big_buttons" || fieldType === "radio_big_buttons" || fieldType === "dropdown") { + } else if (fieldType === "checkbox_big_buttons" || fieldType === "radio_big_buttons" || fieldType === "dropdown") { + // case: checkboxes, radio buttons, and dropdowns // if input is not an array, convert to an array of length 1 if (!$.isArray(self[item.name])) { userInput = [self[item.name]]; @@ -216,9 +215,8 @@ var Shareabouts = Shareabouts || {}; selected: selected }); }); - } - // case: binary toggle buttons - else if (fieldType === "binary_toggle") { + } else if (fieldType === "binary_toggle") { + // case: binary toggle buttons // NOTE: we assume that the first option listed under content // corresponds to the "on" value of the toggle input content = {