-
Notifications
You must be signed in to change notification settings - Fork 6
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 #17 from abgov/Clone
Clone functionality
- Loading branch information
Showing
10 changed files
with
310 additions
and
32 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
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,44 @@ | ||
$(function() { | ||
/* This submits dataset clone request via Ajax. | ||
* It has to be done this way because the dataset view page has javascript tabs, | ||
* unlike vanilla CKAN. | ||
* */ | ||
$('#id-clone-ds-form button[type=submit]').click(function(e) { | ||
console.log('clone clicked...'); | ||
var url = $('#id-clone-ds-form').attr('action'); | ||
var titleInp = $('#field-title'); | ||
var urlInp = $('#field-name'); | ||
$('#id-clone-ds-form .top-error-msg').text('').hide(); | ||
titleInp.parent().removeClass('error').find('span.error-block').remove(); | ||
urlInp.parent().removeClass('error').find('span.error-block').remove(); | ||
$.post(url, | ||
{ title: $('#field-title').val(), | ||
name: $('#field-name').val() }, | ||
function(data) { | ||
if (data.status == 'success') | ||
window.location.href = data.redirect_url; | ||
else if (data.status == 'error') { | ||
if (data.errorMessage) { | ||
$('#id-clone-ds-form .top-error-msg').text(data.errorMessage).show(); | ||
} | ||
else { | ||
if (data.errors.title) | ||
titleInp.after('<span class="error-block">'+data.errors.title[0]+'</span>') | ||
.parent().addClass('error'); | ||
if (data.errors.name) { | ||
// URL input is initially hidden. Need to show. | ||
var editBtn = titleInp.parent().find('.btn-mini'); | ||
if (editBtn.length) | ||
$(editBtn[0]).click(); | ||
|
||
urlInp.after('<span class="error-block">'+data.errors.name[0]+'</span>') | ||
.parent().addClass('error'); | ||
} | ||
} | ||
} | ||
else | ||
; // TODO: Unexpected server response | ||
}); | ||
e.preventDefault(); | ||
}); | ||
}); |
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
25 changes: 25 additions & 0 deletions
25
ckanext/open_alberta/templates/package/snippets/clone_form.html
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,25 @@ | ||
{% import 'macros/form.html' as form %} | ||
|
||
<h2>{% block page_heading %}{{ _('Clone') }} {{ h.dataset_display_name(pkg) }}{% endblock %}</h2> | ||
|
||
<form id="id-clone-ds-form" class="dataset-form form-horizontal" method="post" action="{{ h.url_for('clone', id=pkg.name) }}"> | ||
<div class="top-error-msg">Unexpected error message goes here...</div> | ||
{% block package_basic_fields_title %} | ||
{{ form.input('title', id='field-title', label=_('Title'), placeholder=_('New Title'), | ||
attrs={'data-module': 'slug-preview-target'}, is_required=True) }} | ||
{% endblock %} | ||
|
||
{% block package_basic_fields_url %} | ||
{% set prefix = h.url_for(controller='package', action='read', id='') %} | ||
{% set domain = h.url_for(controller='package', action='read', id='', qualified=true) %} | ||
{% set domain = domain|replace("http://", "")|replace("https://", "") %} | ||
{% set attrs = {'data-module': 'slug-preview-slug', 'data-module-prefix': domain, 'data-module-placeholder': '<dataset>'} %} | ||
|
||
{{ form.prepend('name', id='field-name', label=_('URL'), prepend=prefix, placeholder=_('New URL'), | ||
attrs=attrs, is_required=true) }} | ||
{% endblock %} | ||
|
||
<div class="form-actions"> | ||
<button class="btn btn-primary" type="submit" name="save">{{ _('Clone') }}</button> | ||
</div> | ||
</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
Oops, something went wrong.