Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port fixes and features in Bootstrap 2 mode #3719

Merged
merged 15 commits into from
Aug 14, 2017
4 changes: 2 additions & 2 deletions ckan/public-bs2/base/css/fuchsia.css
Original file line number Diff line number Diff line change
Expand Up @@ -6361,7 +6361,7 @@ textarea {
}
@media (min-width: 980px) {
.form-horizontal .info-block {
padding: 0 0 6px 25px;
padding: 6px 0 6px 0;
}
.form-horizontal .info-inline {
float: right;
Expand Down Expand Up @@ -7273,7 +7273,7 @@ textarea {
display: block;
position: absolute;
top: 50%;
margin-top: -10px;
margin-top: 1px;
right: 10px;
height: 20px;
padding: 0;
Expand Down
4 changes: 2 additions & 2 deletions ckan/public-bs2/base/css/green.css
Original file line number Diff line number Diff line change
Expand Up @@ -6361,7 +6361,7 @@ textarea {
}
@media (min-width: 980px) {
.form-horizontal .info-block {
padding: 0 0 6px 25px;
padding: 6px 0 6px 0;
}
.form-horizontal .info-inline {
float: right;
Expand Down Expand Up @@ -7273,7 +7273,7 @@ textarea {
display: block;
position: absolute;
top: 50%;
margin-top: -10px;
margin-top: 1px;
right: 10px;
height: 20px;
padding: 0;
Expand Down
4 changes: 2 additions & 2 deletions ckan/public-bs2/base/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -6361,7 +6361,7 @@ textarea {
}
@media (min-width: 980px) {
.form-horizontal .info-block {
padding: 0 0 6px 25px;
padding: 6px 0 6px 0;
}
.form-horizontal .info-inline {
float: right;
Expand Down Expand Up @@ -7273,7 +7273,7 @@ textarea {
display: block;
position: absolute;
top: 50%;
margin-top: -10px;
margin-top: 1px;
right: 10px;
height: 20px;
padding: 0;
Expand Down
4 changes: 2 additions & 2 deletions ckan/public-bs2/base/css/maroon.css
Original file line number Diff line number Diff line change
Expand Up @@ -6361,7 +6361,7 @@ textarea {
}
@media (min-width: 980px) {
.form-horizontal .info-block {
padding: 0 0 6px 25px;
padding: 6px 0 6px 0;
}
.form-horizontal .info-inline {
float: right;
Expand Down Expand Up @@ -7273,7 +7273,7 @@ textarea {
display: block;
position: absolute;
top: 50%;
margin-top: -10px;
margin-top: 1px;
right: 10px;
height: 20px;
padding: 0;
Expand Down
4 changes: 2 additions & 2 deletions ckan/public-bs2/base/css/red.css
Original file line number Diff line number Diff line change
Expand Up @@ -6361,7 +6361,7 @@ textarea {
}
@media (min-width: 980px) {
.form-horizontal .info-block {
padding: 0 0 6px 25px;
padding: 6px 0 6px 0;
}
.form-horizontal .info-inline {
float: right;
Expand Down Expand Up @@ -7273,7 +7273,7 @@ textarea {
display: block;
position: absolute;
top: 50%;
margin-top: -10px;
margin-top: 1px;
right: 10px;
height: 20px;
padding: 0;
Expand Down
2 changes: 1 addition & 1 deletion ckan/public-bs2/base/javascript/modules/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ this.ckan.module('autocomplete', function (jQuery) {
label: false,
items: 10,
source: null,
interval: 1000,
interval: 300,
dropdownClass: '',
containerClass: ''
},
Expand Down
5 changes: 3 additions & 2 deletions ckan/public-bs2/base/javascript/modules/follow.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Handles calling the API to follow the current user
*
* action - This being the action that the button should perform. Currently: "follow" or "unfollow"
* type - The being the type of object the user is trying to support. Currently: "user" or "group"
* type - The being the type of object the user is trying to support. Currently: "user", "group" or "dataset"
* id - id of the objec the user is trying to follow
* loading - State management helper
*
Expand Down Expand Up @@ -62,6 +62,7 @@ this.ckan.module('follow', function($) {
_onClickLoaded: function(json) {
var options = this.options;
var sandbox = this.sandbox;
var oldAction = options.action;
options.loading = false;
this.el.removeClass('disabled');
if (options.action == 'follow') {
Expand All @@ -71,7 +72,7 @@ this.ckan.module('follow', function($) {
options.action = 'follow';
this.el.html('<i class="fa fa-plus-circle"></i> ' + this._('Follow')).removeClass('btn-danger').addClass('btn-success');
}
sandbox.publish('follow-' + options.action + '-' + options.id);
sandbox.publish('follow-' + oldAction + '-' + options.id);
}
};
});
91 changes: 91 additions & 0 deletions ckan/public-bs2/base/javascript/modules/followers-counter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/* Updates the Followers counter in the UI when the Follow/Unfollow button
* is clicked.
*
* id - id of the object the user is trying to follow/unfollow.
* num_followers - Number of followers the object has.
*
* Example
*
* <dd data-module="followers-counter"
* data-module-id="object-id"
* data-module-num_followers="6">
* <span>6</span>
* </dd>
*
*/
this.ckan.module('followers-counter', function($) {
'use strict';

return {
options: {
id: null,
num_followers: 0
},

/* Subscribe to events when the Follow/Unfollow button is clicked.
*
* Returns nothing.
*/
initialize: function() {
$.proxyAll(this, /_on/);

this.counterEl = this.$('span');
this.objId = this.options.id;

this.sandbox.subscribe('follow-follow-' + this.objId, this._onFollow);
this.sandbox.subscribe('follow-unfollow-' + this.objId, this._onUnfollow);
},

/* Calls a function to update the counter when the Follow button is clicked.
*
* Returns nothing.
*/
_onFollow: function() {
this._updateCounter({action: 'follow'});
},

/* Calls a function to update the counter when the Unfollow button is clicked.
*
* Returns nothing.
*/
_onUnfollow: function() {
this._updateCounter({action: 'unfollow'});
},

/* Handles updating the UI for Followers counter.
*
* Returns nothing.
*/
_updateCounter: function(options) {
var locale = $('html').attr('lang');
var action = options.action;
var incrementedFollowers;

if (action === 'follow') {
incrementedFollowers = (++this.options.num_followers).toLocaleString(locale);
} else if (action === 'unfollow') {
incrementedFollowers = (--this.options.num_followers).toLocaleString(locale);
}

// Only update the value if it's less than 1000, because for larger
// numbers the change won't be noticeable since the value is converted
// to SI number abbreviated with "k", "m" and so on.
if (this.options.num_followers < 1000) {
this.counterEl.text(incrementedFollowers);
this.counterEl.removeAttr('title');
} else {
this.counterEl.attr('title', incrementedFollowers);
}
},

/* Remove any subscriptions to prevent memory leaks. This function is
* called when a module element is removed from the page.
*
* Returns nothing.
*/
teardown: function() {
this.sandbox.unsubscribe('follow-follow-' + this.objId, this._onFollow);
this.sandbox.unsubscribe('follow-unfollow-' + this.objId, this._onUnfollow);
}
}
});
5 changes: 5 additions & 0 deletions ckan/public-bs2/base/javascript/modules/image-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ this.ckan.module('image-upload', function($) {
* Returns String.
*/
_fileNameFromUpload: function(url) {
// If it's a local CKAN image return the entire URL.
if (/^\/base\/images/.test(url)) {
return url;
}

// remove fragment (#)
url = url.substring(0, (url.indexOf("#") === -1) ? url.length : url.indexOf("#"));
// remove query string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ this.ckan.module('resource-reorder', function($) {
initialize: function() {
jQuery.proxyAll(this, /_on/);

var labelText = this._(this.labelText);
var labelText = this._(this.options.labelText);

this.html_title = $(this.template.title)
.text(labelText)
Expand Down
10 changes: 5 additions & 5 deletions ckan/public-bs2/base/javascript/modules/resource-view-filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ this.ckan.module('resource-view-filters', function (jQuery) {
resourceId = self.options.resourceId,
fields = self.options.fields,
dropdownTemplate = self.options.dropdownTemplate,
addFilterTemplate = '<a href="#">' + self._('Add Filter') + '</a>',
addFilterTemplate = '<a class="btn btn-primary" href="#">' + self._('Add Filter') + '</a>',
filtersDiv = $('<div></div>');

var filters = ckan.views.filters.get();
_appendDropdowns(filtersDiv, resourceId, dropdownTemplate, fields, filters);
var addFilterButton = _buildAddFilterButton(filtersDiv, addFilterTemplate, fields, filters, function (evt) {
var addFilterButton = _buildAddFilterButton(self, filtersDiv, addFilterTemplate,
fields, filters, function (evt) {
// Build filters object with this element's val as key and a placeholder
// value so _appendDropdowns() will create its dropdown
var filters = {};
Expand All @@ -25,9 +26,8 @@ this.ckan.module('resource-view-filters', function (jQuery) {
self.el.append(addFilterButton);
}

function _buildAddFilterButton(el, template, fields, filters, onChangeCallback) {
var self = this,
addFilterButton = $(template),
function _buildAddFilterButton(self, el, template, fields, filters, onChangeCallback) {
var addFilterButton = $(template),
currentFilters = Object.keys(filters),
fieldsNotFiltered = $.grep(fields, function (field) {
return !filters.hasOwnProperty(field);
Expand Down
2 changes: 1 addition & 1 deletion ckan/public-bs2/base/javascript/modules/slug-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ this.ckan.module('slug-preview-target', {

// Watch for updates to the target field and update the hidden slug field
// triggering the "change" event manually.
el.on('keyup.slug-preview', function (event) {
el.on('keyup.slug-preview input.slug-preview', function (event) {
sandbox.publish('slug-target-changed', this.value);
//slug.val(this.value).trigger('change');
});
Expand Down
8 changes: 4 additions & 4 deletions ckan/public-bs2/base/javascript/plugins/jquery.url-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@
'4f0 4f1 4f2 4f3 4f4 4f5 4f6 4f7 4f8 4f9 4fa 4fb 4fc 4fd 4fe 4ff ' +
'50a 50b 50c 50d 50e 50f 51a 51b 51c 51d 53a 53b 53c 53d 53e 53f ' +
'54a 54b 54c 54d 54e 54f 56a 56b 56c 56d 56e 56f 57a 57b 57c 57d ' +
'57e 57f').split(' ');
'57e 57f 5f').split(' ');

var replacement = ('- 0 1 2 3 4 5 6 7 8 9 A B C D E F G H I P Q R S T ' +
'U V W X Y a b c d e f g h i p q r s t u v w x y A a A a A a C c C c ' +
'D d E e E e E e E e G g G g H h H h I i I i IJ ij J j K k k L l L l ' +
'N n N n N n n O o OE oe R r R r R r S s T t T t T t U u U u U u W w ' +
'Y y Y Z b B b b b b C C c D E F f G Y h i I K k A a A a E e E e I i ' +
'R r R r U u U u S s n d 8 8 Z z A a E e O o Y y l n t j db qp < ? ? ' +
'Y y Y Z b B b b b b C C c D E F f G Y h i I K k A a A a E e E e I i ' +
'R r R r U u U u S s n d 8 8 Z z A a E e O o Y y l n t j db qp < ? ? ' +
'B U A E e J j a a a b c e d d e e g g g Y x u h h i i w m n n N o oe ' +
'm o r R R S f f f f t t u Z Z 3 3 ? ? 5 C O B a e i o u c d A ' +
'E H i A B r A E Z H O I E E T r E S I I J jb A B B r D E X 3 N N P ' +
Expand Down Expand Up @@ -154,7 +154,7 @@
'h H h E e E e I X x K k jt jt H h H h H h M m l A a A a AE ae E e ' +
'e e E e X X 3 3 3 3 N n N n O o O o O o E e Y y Y y Y y H h R r bI ' +
'bi F f X x X x H h G g T t Q q W w d r L Iu O y m o N U Y S d h l ' +
'lu d y w 2 n u y un').split(' ');
'lu d y w 2 n u y un _').split(' ');

// Map the Unicode characters to their counterparts in an object.
var map = {};
Expand Down
1 change: 1 addition & 0 deletions ckan/public-bs2/base/javascript/resource.config
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ ckan =
modules/dataset-visibility.js
modules/media-grid.js
modules/image-upload.js
modules/followers-counter.js

main =
apply_html_class
Expand Down
2 changes: 1 addition & 1 deletion ckan/public-bs2/base/less/forms.less
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ textarea {

@media (min-width: 980px) {
.form-horizontal .info-block {
padding: 0 0 6px 25px;
padding: 6px 0 6px 0;
}
.form-horizontal .info-inline {
float: right;
Expand Down
2 changes: 1 addition & 1 deletion ckan/public-bs2/base/less/search.less
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
display: block;
position: absolute;
top: 50%;
margin-top: -10px;
margin-top: 1px;
right: 10px;
height: 20px;
padding: 0;
Expand Down
2 changes: 2 additions & 0 deletions ckan/public-bs2/base/test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<script src="../javascript/modules/image-upload.js"></script>
<script src="../javascript/modules/confirm-action.js"></script>
<script src="../javascript/modules/custom-fields.js"></script>
<script src="../javascript/modules/followers-counter.js"></script>

<!-- Suite -->
<script src="./spec/ckan.spec.js"></script>
Expand All @@ -66,6 +67,7 @@
<script src="./spec/modules/basic-form.spec.js"></script>
<script src="./spec/modules/autocomplete.spec.js"></script>
<script src="./spec/modules/custom-fields.spec.js"></script>
<script src="./spec/modules/followers-counter.spec.js"></script>
<script src="./spec/plugins/jquery.inherit.spec.js"></script>
<script src="./spec/plugins/jquery.proxy-all.spec.js"></script>
<script src="./spec/plugins/jquery.url-helpers.spec.js"></script>
Expand Down
Loading