forked from timwis/jkan
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
155 additions
and
1 deletion.
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
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,17 @@ | ||
<form data-hook="organization-form"> | ||
<input type="hidden" id="schema" name="schema" value="{{ schema }}"> | ||
|
||
<fieldset> | ||
{% for field in organization_fields %} | ||
{% assign template = field.form_template | default: "form/text.html" %} | ||
{% assign field_name = field.field_name %} | ||
{% assign value = include.organization[field_name] %} | ||
{% include {{ template }} field=field field_name=field_name value=value %} | ||
{% endfor %} | ||
</fieldset> | ||
|
||
<button type="submit" class="btn btn-primary">Submit</button> | ||
{% if include.organization %} | ||
<button class="btn btn-danger" data-hook="delete-button"><i class="fa fa-trash"></i> Delete organization</button> | ||
{% endif %} | ||
</form> |
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,43 @@ | ||
--- | ||
layout: default | ||
--- | ||
{% include breadcrumbs.html parent="Organizations" %} | ||
{% assign schema = page.schema | default: site.schema %} | ||
{% assign organization_fields = site.data.schemas[schema].organization_fields %} | ||
{% assign organization_system_fields = "title|description|logo" | split: "|" %} | ||
|
||
<div class="alert alert-success" role="alert" data-hook="alert-success" style="display: none;"> | ||
This organization has been <a href="#" data-hook="commit-url">saved</a> and the page is currently regenerating. | ||
</div> | ||
|
||
<div class="alert alert-danger" role="alert" data-hook="alert-error" style="display: none;"> | ||
There was an error saving this page | ||
</div> | ||
|
||
<div class="row" data-hook="read-view"> | ||
{% if page.logo %} | ||
<div class="col-sm-3"> | ||
<a href="{{ page.logo }}" class="thumbnail"><img src="{{ page.logo }}" alt="{{ page.title }} logo"></a> | ||
</div> | ||
<div class="col-sm-9"> | ||
{% else %} | ||
<div class="col-sm-12"> | ||
{% endif %} | ||
<h1> | ||
{{ page.title }} | ||
<a href="https://github.com/{{ site.github.owner_name }}/{{ site.github.project_title }}/edit/gh-pages/{{ page.path }}" class="pull-right btn btn-default edit-organization-btn" role="button" data-hook="edit-button">Edit</a> | ||
</h1> | ||
<p>{{ page.description }}</p> | ||
{% assign dataset_count = site.datasets | where: "organization", page.title | size %} | ||
<a href="{{ site.baseurl }}/datasets/?organization={{ page.slug }}">{{ dataset_count }} datasets</a> | ||
</div> | ||
</div> | ||
|
||
<div class="row" data-hook="edit-view" style="display: none;"> | ||
<div class="col-sm-8 col-sm-offset-2"> | ||
{% include organization-form.html organization=page %} | ||
</div> | ||
<div class="col-sm-2"> | ||
<button class="btn btn-default pull-right" data-hook="cancel-button">Cancel</button> | ||
</div> | ||
</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
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,68 @@ | ||
import {queryByHook} from '../util' | ||
|
||
export default function (opts) { | ||
const elements = { | ||
editButton: queryByHook('edit-button', opts.el), | ||
readView: queryByHook('read-view', opts.el), | ||
editView: queryByHook('edit-view', opts.el), | ||
form: queryByHook('organization-form', opts.el), | ||
cancelButton: queryByHook('cancel-button', opts.el), | ||
deleteButton: queryByHook('delete-button', opts.el), | ||
alert: queryByHook('alert', opts.el), | ||
commitUrl: queryByHook('commit-url', opts.el) | ||
} | ||
|
||
// If user is logged in and a collaborator, show the Edit Dataset button | ||
if (opts.user.username && opts.user.isCollaborator) elements.editButton.show() | ||
opts.user.on('change', (user) => { | ||
if (user.username && user.isCollaborator) elements.editButton.show() | ||
}) | ||
|
||
// Edit/Cancel buttons toggle read/edit views | ||
elements.editButton.add(elements.cancelButton).on('click', (e) => { | ||
switchView() | ||
e.preventDefault() | ||
}) | ||
|
||
// Edit form submission | ||
elements.form.on('submit', function (e) { | ||
const formData = elements.form.serializeJSON({useIntKeysAsArrayIndex: true}) | ||
const yaml = opts.file.formatFrontMatter(formData) | ||
opts.file.save(yaml) | ||
.then((response) => { | ||
switchView() | ||
alert('success', response.commit.html_url) | ||
}).catch((msg) => { | ||
alert('error') | ||
console.error(msg) | ||
}) | ||
e.preventDefault() | ||
}) | ||
|
||
// Delete button | ||
elements.deleteButton.on('click', function (e) { | ||
if (window.confirm('Delete this organization?')) { | ||
opts.file.remove() | ||
.then((response) => { | ||
alert('success', response.commit.html_url) | ||
}).catch((msg) => { | ||
alert('error') | ||
console.error(msg) | ||
}) | ||
} | ||
e.preventDefault() | ||
}) | ||
|
||
function switchView () { | ||
elements.readView.add(elements.editView).toggle() | ||
} | ||
|
||
// Show alert box on page | ||
function alert (type, commitUrl) { | ||
elements.alert.hide() | ||
$('[data-hook~=alert-' + type +']').show() | ||
if (type === 'success' && commitUrl) { | ||
elements.commitUrl.attr('href', commitUrl) | ||
} | ||
} | ||
} |