Skip to content

Commit

Permalink
[#1277] Added javascript call the package_resource_reorder api call t…
Browse files Browse the repository at this point in the history
…o handle actual reordering
  • Loading branch information
johnmartin committed Nov 26, 2013
1 parent 596caaa commit 4938ac9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 23 deletions.
54 changes: 32 additions & 22 deletions ckan/public/base/javascript/modules/resource-reorder.js
@@ -1,14 +1,9 @@
/* Module for the resource form. Handles validation and updating the form
* with external data such as from a file upload.
/* Module for reordering resources
*/
this.ckan.module('resource-reorder', function($, _) {
return {
options: {
form: {
method: 'POST',
file: 'file',
params: []
},
id: false,
i18n: {
label: _('Reorder resources'),
save: _('Save order'),
Expand Down Expand Up @@ -36,6 +31,7 @@ this.ckan.module('resource-reorder', function($, _) {
].join('\n')
},
is_reordering: false,
cache: false,

initialize: function() {
jQuery.proxyAll(this, /_on/);
Expand Down Expand Up @@ -63,6 +59,8 @@ this.ckan.module('resource-reorder', function($, _) {
.hide()
.appendTo($('.resource-item', this.el));

this.cache = this.el.html();

this.el
.sortable()
.sortable('disable');
Expand All @@ -85,26 +83,38 @@ this.ckan.module('resource-reorder', function($, _) {

_onHandleCancel: function() {
if (this.is_reordering) {
this.html_form_actions
.add(this.html_handles)
.add(this.html_title)
.hide();
this.el
.removeClass('reordering')
.sortable('disable');
$('.page_primary_action').show();
this.reset();
this.is_reordering = false;
this.el.html(this.cache)
.sortable()
.sortable('disable');
this.html_handles = $('.handle', this.el);
}
},

_onHandleSave: function() {
if (!$('.save', this.html_form_actions).hasClass('disabled')) {
var order = [];
$('.resource-item', this.el).each(function() {
order.push($(this).data('id'));
});
console.log(order);
}
var order = [];
$('.resource-item', this.el).each(function() {
order.push($(this).data('id'));
});
this.sandbox.client.call('POST', 'package_resource_reorder', {
id: this.options.id,
order: order
});
this.cache = this.el.html();
this.reset();
this.is_reordering = false;
},

reset: function() {
this.html_form_actions
.add(this.html_handles)
.add(this.html_title)
.hide();
this.el
.removeClass('reordering')
.sortable('disable');
$('.page_primary_action').show();
}

};
Expand Down
3 changes: 3 additions & 0 deletions ckan/public/base/less/dataset.less
Expand Up @@ -131,6 +131,9 @@
}
}
}
.resource-item .handle {
display: none;
}

// Dataset Forms

Expand Down
2 changes: 1 addition & 1 deletion ckan/templates/package/resources.html
Expand Up @@ -10,7 +10,7 @@

{% block primary_content_inner %}
{% if pkg.resources %}
<ul class="resource-list"{% if has_reorder %} data-module="resource-reorder"{% endif %}>
<ul class="resource-list"{% if has_reorder %} data-module="resource-reorder" data-module-id="{{ pkg.id }}"{% endif %}>
{% for resource in pkg.resources %}
{% snippet 'package/snippets/resource_item.html', pkg=pkg, res=resource, url_is_edit=true %}
{% endfor %}
Expand Down

0 comments on commit 4938ac9

Please sign in to comment.