-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from timwis/edit-categories
Edit categories
- Loading branch information
Showing
17 changed files
with
209 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
- name: Arts / Culture / History | ||
- name: Budget / Finance | ||
- name: Economy | ||
- name: Education | ||
- name: Elections / Politics | ||
- name: Environment | ||
- name: Food | ||
- name: Health / Human Services | ||
- name: Parks / Recreation | ||
- name: Planning / Zoning | ||
- name: Public Safety | ||
- name: Real Estate / Land Records | ||
- name: Transportation | ||
- name: Uncategorized |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<div class="editable-list-item" data-hook="item"> | ||
<fieldset> | ||
{% for field in category_fields %} | ||
{% assign template = field.form_template | default: "form/text.html" %} | ||
{% capture field_name %}categories[][{{ field.field_name }}]{% endcapture %} | ||
{% assign value = category[field[field_name]] %} | ||
{% include {{ template }} field=field field_name=field_name value=value %} | ||
{% endfor %} | ||
</fieldset> | ||
<button type="button" class="btn btn-danger btn-sm" data-hook="remove-item-btn"><i class="fa fa-minus"></i> Remove</button> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
<div class="resource-row" data-hook="resource-row"> | ||
<fieldset class="resource-fieldset"> | ||
<div class="editable-list-item" data-hook="item"> | ||
<fieldset> | ||
{% for field in resource_fields %} | ||
{% assign template = field.form_template | default: "form/text.html" %} | ||
{% capture field_name %}resources[][{{ field.field_name }}]{% endcapture %} | ||
{% assign value = resource[field[field_name]] %} | ||
{% include {{ template }} field=field field_name=field_name value=value %} | ||
{% endfor %} | ||
</fieldset> | ||
<button type="button" class="btn btn-danger btn-sm" data-hook="remove-resource-btn" title="Remove resource" data-toggle="tooltip"><i class="fa fa-minus"></i> Remove Resource</button> | ||
<button type="button" class="btn btn-danger btn-sm" data-hook="remove-item-btn"><i class="fa fa-minus"></i> Remove Resource</button> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
<div class="form-group"> | ||
<label for="{{ include.field_name }}[]">{{ include.field.label }}</label> | ||
<select class="form-control select2" id="{{ include.field_name }}[]" name="{{ include.field_name }}[]" multiple="multiple" style="width: 100%"> | ||
{% for category in site.category_list %} | ||
<option{% if include.value == category or include.value contains category %} selected="selected"{% endif %}>{{ category }}</option> | ||
{% for category in site.data.categories %} | ||
<option{% if include.value == category.name or include.value contains category.name %} selected="selected"{% endif %}>{{ category.name }}</option> | ||
{% endfor %} | ||
</select> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import jsyaml from 'js-yaml' | ||
|
||
import Form from './form' | ||
|
||
export default class extends Form { | ||
_formatData (formData) { | ||
return jsyaml.safeDump(formData.categories || []) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,13 @@ | ||
import $ from 'jquery' | ||
import 'select2' | ||
import 'jquery-serializejson' | ||
import notie from 'notie' | ||
|
||
import {queryByHook} from '../util' | ||
|
||
export default class { | ||
constructor (opts) { | ||
const elements = { | ||
tmplResourceRow: queryByHook('tmpl-resource-row'), | ||
select2: $('.select2', opts.el), | ||
resourceRows: queryByHook('resource-rows', opts.el), | ||
addResourceBtn: queryByHook('add-resource-btn', opts.el), | ||
deleteBtn: queryByHook('delete-dataset-btn', opts.el) | ||
select2: $('.select2', opts.el) | ||
} | ||
const TmplResourceRow = elements.tmplResourceRow.html() | ||
|
||
// Initialize select2 plugin | ||
elements.select2.select2() | ||
|
||
// Add resource button | ||
elements.addResourceBtn.on('click', function (e) { | ||
elements.resourceRows.append(TmplResourceRow) | ||
}) | ||
|
||
// "Remove resource" buttons | ||
elements.resourceRows.on('click', '[data-hook~=remove-resource-btn]', (e) => { | ||
notie.confirm('Delete this resource?', 'Yes', 'Cancel', () => { | ||
$(e.currentTarget).closest('[data-hook~=resource-row]').remove() | ||
}) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* Usage: | ||
* <div data-component="editable-list" data-item-label="category"> | ||
* <div data-hook="items"> | ||
* <div data-hook="item"> | ||
* <button data-hook="remove-item-btn">Remove</button> | ||
* </div> | ||
* </div> | ||
* <button data-hook="add-items-btn">Add</button> | ||
* <script type="text/template" data-hook="item-template"> | ||
* </script> | ||
* </div> | ||
*/ | ||
import $ from 'jquery' | ||
import notie from 'notie' | ||
|
||
import {queryByHook} from '../util' | ||
|
||
export default class { | ||
constructor (opts) { | ||
const elements = { | ||
itemTemplate: queryByHook('item-template', opts.el), | ||
items: queryByHook('items', opts.el), | ||
addBtn: queryByHook('add-item-btn', opts.el) | ||
} | ||
const ItemTemplate = elements.itemTemplate.html() | ||
const itemLabel = opts.el.data('item-label') || 'item' | ||
|
||
// Add button | ||
elements.addBtn.on('click', function (e) { | ||
elements.items.append(ItemTemplate) | ||
}) | ||
|
||
// "Remove resource" buttons | ||
elements.items.on('click', '[data-hook~=remove-item-btn]', (e) => { | ||
notie.confirm(`Delete this ${itemLabel}?`, 'Yes', 'Cancel', () => { | ||
$(e.currentTarget).closest('[data-hook~=item]').remove() | ||
}) | ||
}) | ||
} | ||
} |
Oops, something went wrong.