Skip to content

Commit

Permalink
Merge pull request #435 from smartercleanup/placeViewUpdates-434
Browse files Browse the repository at this point in the history
Place view updates
  • Loading branch information
modulitos authored Sep 9, 2016
2 parents 92f4254 + e1177e8 commit b04beab
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 22 deletions.
80 changes: 69 additions & 11 deletions src/sa_web/jstemplates/place-detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,84 @@ <h1>
<span class="survey-count">{{ survey_count }} {{ survey_label_by_count }}</span>

{{^if survey_config}}
<a href="/{{ datasetSlug }}/{{ id }}" class="view-on-map-btn btn btn-small">View On Map</a>
<a href="/{{ datasetSlug }}/{{ id }}" class="view-on-map-btn btn btn-small">View On Map</a>
{{/if}}

</span>
</header>

<section class="place-items">
{{# attachments }}
<div class="place-item place-item-attachment place-attachment-{{ name }}">
<img src="{{ file }}" class="place-value place-value-{{ name }}" alt="{{ name }}">
</div>
<div class="place-item place-item-attachment place-attachment-{{ name }}">
<img src="{{ file }}" class="place-value place-value-{{ name }}" alt="{{ name }}" />
</div>
{{/ attachments }}
{{#each_place_item "submitter_name" "name" "location_type"}}
<div class="place-item place-item-{{ name }}">
<span class="place-label place-label-{{ name }}">{{label}}</span>
<p class="place-value place-value-{{ name }}">{{nlToBr value }}</p>
</div>

{{#each_place_item "submitter_name" "name" "location_type" "fullTitle" "title" "name"}}
<div class="place-item place-item-{{ name }}">
<span class="place-label place-label-{{ name }}">{{ prompt }}</span>

{{#is type "datetime"}}
<p class="place-value place-value-{{ name }}">{{nlToBr content}}</p>
{{/is}}

{{#is type "text"}}
<p class="place-value place-value-{{ name }}">{{nlToBr content}}</p>
{{/is}}

{{#is type "textarea"}}
<p class="place-value place-value-{{ name }}">{{nlToBr content}}</p>
{{/is}}

{{#is type "radio_big_buttons"}}
<ul>
{{#each content}}
{{#if selected}}
<li class="multi-select-response place-value">{{ label }} </li>
{{/if}}
{{/each}}
</ul>
{{/is}}

{{#is type "checkbox_big_buttons"}}
<ul>
{{#each content}}
{{#if selected}}
<li class="multi-select-response place-value">{{ label }} </li>
{{/if}}
{{/each}}
</ul>
{{/is}}

{{#is type "binary_toggle"}}
<ul>
<li class="place-value">
{{#if content.selected}}
{{ content.selectedLabel }}
{{else}}
{{ content.unselectedLabel }}
{{/if}}
</li>
</ul>
{{/is}}

{{#is type "dropdown"}}
{{#each content}}
{{#if selected}}
<ul>
<li class="place-value">
{{nlToBr label}}
</li>
</ul>
{{/if}}
{{/each}}
{{/is}}

<div style="clear:both"></div>
</div>
{{/each_place_item }}
</section>

{{#if survey_config}}
<section class="survey" id="survey"></section>
{{/if}}
<section class="survey" id="survey"></section>
{{/if}}
63 changes: 52 additions & 11 deletions src/sa_web/static/js/handlebars-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,25 +181,66 @@ 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,
wasAnswered = false;

if (fieldType === "text" || fieldType === "textarea" || fieldType === "datetime") {
// case: plain text
content = userInput || "";
if (content !== "") {
wasAnswered = true;
}
} 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]];
}
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: selected
});
});
} 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 = {
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
}
wasAnswered = true;
}

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,
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.value != undefined &&
newItem.value !== "") {
newItem.content != undefined &&
newItem.wasAnswered === true) {
result += options.fn(newItem);
}
}, this);
Expand Down
24 changes: 24 additions & 0 deletions src/sa_web/static/scss/_content.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit b04beab

Please sign in to comment.