Skip to content

Commit

Permalink
[#953] Adds JS module for disabling visibility field on dataset creation
Browse files Browse the repository at this point in the history
Essentially we get the current value of the visibility dropdown and then if no
org is selected then we disable the visibilty dropdown and set it to be public.
  • Loading branch information
johnmartin committed Jun 6, 2013
1 parent f83b0c7 commit 972b1c8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
32 changes: 32 additions & 0 deletions ckan/public/base/javascript/modules/dataset-visibility.js
@@ -0,0 +1,32 @@
/* Dataset visibility toggler
* When no organization is selected in the org dropdown then set visibility to
* public always and disable dropdown
*/
this.ckan.module('dataset-visibility', function ($, _) {
return {
currentValue: false,
options: {
organizations: $('#field-organizations'),
visibility: $('#field-private'),
currentValue: null
},
initialize: function() {
$.proxyAll(this, /_on/);
this.options.currentValue = this.options.visibility.val();
this.options.organizations.on('change', this._onOrganizationChange);
this._onOrganizationChange();
},
_onOrganizationChange: function() {
var value = this.options.organizations.val();
if (value) {
this.options.visibility
.prop('disabled', false)
.val(this.options.currentValue);
} else {
this.options.visibility
.prop('disabled', true)
.val('False');
}
}
};
});
1 change: 1 addition & 0 deletions ckan/public/base/javascript/resource.config
Expand Up @@ -36,6 +36,7 @@ ckan =
modules/activity-stream.js
modules/dashboard.js
modules/table-toggle-more.js
modules/dataset-visibility.js

main =
apply_html_class
Expand Down
16 changes: 13 additions & 3 deletions ckan/templates/package/snippets/package_basic_fields.html
Expand Up @@ -57,8 +57,14 @@
{% set dataset_has_organization = data.owner_org or data.group_id %}
{% set organizations_available = h.organizations_available('create_dataset') %}
{% set user_is_sysadmin = h.check_access('sysadmin') %}
{% set show_organizations_selector = organizations_available and (user_is_sysadmin or dataset_is_draft) %}
{% set show_visibility_selector = dataset_has_organization or (organizations_available and (user_is_sysadmin or dataset_is_draft)) %}

{% if organizations_available and (user_is_sysadmin or dataset_is_draft) %}
{% if show_organizations_selector and show_visibility_selector %}
<div data-module="dataset-visibility">
{% endif %}

{% if show_organizations_selector %}
<div class="control-group">
<label for="field-organizations" class="control-label">{{ _('Organization') }}</label>
<div class="controls">
Expand All @@ -74,12 +80,12 @@
</div>
{% endif %}

{% if dataset_has_organization or (organizations_available and (user_is_sysadmin or dataset_is_draft)) %}
{% if show_visibility_selector %}
{% block package_metadata_fields_visibility %}
<div class="control-group">
<label for="field-private" class="control-label">{{ _('Visibility') }}</label>
<div class="controls">
<select id="field-private" name="private" data-module="autocomplete">
<select id="field-private" name="private">
{% for option in [(true, _('Private')), (false, _('Public'))] %}
<option value="{{ option[0] }}" {% if option[0] == data.private %}selected="selected"{% endif %}>{{ option[1] }}</option>
{% endfor %}
Expand All @@ -89,4 +95,8 @@
{% endblock %}
{% endif %}

{% if show_organizations_selector and show_visibility_selector %}
</div>
{% endif %}

{% endblock %}

0 comments on commit 972b1c8

Please sign in to comment.