diff --git a/ckan/public/scripts/application.js b/ckan/public/scripts/application.js index a19b0e18a20..2f3efa81b5c 100644 --- a/ckan/public/scripts/application.js +++ b/ckan/public/scripts/application.js @@ -150,12 +150,15 @@ CKAN.View.UrlEditor = Backbone.View.extend({ new RegExp('-*$', 'g')]; // Default options - if (!this.options.apiUrl) + if (!this.options.apiUrl) { this.options.apiUrl = CKAN.SITE_URL + '/api/2/util/is_slug_valid'; - if (!this.options.MAX_SLUG_LENGTH) + } + if (!this.options.MAX_SLUG_LENGTH) { this.options.MAX_SLUG_LENGTH = 90; - if (!this.options.editMode) + } + if (!this.options.editMode) { this.options.editMode = false; + } if (this.options.editMode) { this.originalUrl = this.urlInput.val(); @@ -201,9 +204,9 @@ CKAN.View.UrlEditor = Backbone.View.extend({ /* Called when the title changes */ titleChanged: function() { - if (this.disableTitleChanged) return; + if (this.disableTitleChanged) { return; } var title = this.titleInput.val(); - if (title == this.lastTitle) return; + if (title == this.lastTitle) { return; } this.lastTitle = title; slug = this.titleToSlug(title); @@ -214,8 +217,8 @@ CKAN.View.UrlEditor = Backbone.View.extend({ /* Called when the url is changed */ urlChanged: function() { var slug = this.urlInput.val(); - if (this.updateTimer) clearTimeout(this.updateTimer); - if (slug.length==0) { + if (this.updateTimer) { clearTimeout(this.updateTimer); } + if (slug.length) { this.urlSuffix.html('...'); } else { @@ -260,7 +263,7 @@ CKAN.View.UrlEditor = Backbone.View.extend({ } else { this.validMsg.html(''+CKAN.Strings.urlIsNotAvailable+''); } - }, + } }); @@ -335,7 +338,7 @@ CKAN.View.ResourceEditor = Backbone.View.extend({ * Open the 'Add New Resource' special-case panel on the right. */ openAddPanel: function(e) { - if (e) e.preventDefault(); + if (e) { e.preventDefault(); } var panel = this.el.find('.resource-panel'); var addLi = this.el.find('.resource-list-add li'); this.el.find('.resource-list li').removeClass('active'); @@ -349,7 +352,7 @@ CKAN.View.ResourceEditor = Backbone.View.extend({ * Close the panel on the right. */ closePanel: function(e) { - if (e) e.preventDefault(); + if (e) { e.preventDefault(); } this.el.find('.resource-list li').removeClass('active'); this.el.find('.resource-panel').hide(); }, @@ -367,7 +370,7 @@ CKAN.View.ResourceEditor = Backbone.View.extend({ $.each(table.find('input,textarea,select'), function(input_index, input) { var name = $(input).attr('name'); if (name) { - name = name.replace(/(resources__)\d+(.*)/, '$1'+index+'$2') + name = name.replace(/(resources__)\d+(.*)/, '$1'+index+'$2'); $(input).attr('name',name); } }); @@ -383,7 +386,7 @@ CKAN.View.ResourceEditor = Backbone.View.extend({ var name = $(input).attr('name') || ''; var splitName=name.split('__'); if (splitName.length>1) { - var myId = parseInt(splitName[1]) + var myId = parseInt(splitName[1],10); maxId = Math.max(myId, maxId); } }); @@ -433,14 +436,14 @@ CKAN.View.Resource = Backbone.View.extend({ num: this.options.position, resource_icon: '/images/icons/page_white.png', resourceTypeOptions: [ - ['file', 'Data File'] - , ['api', 'API'] - , ['visualization', 'Visualization'] - , ['image', 'Image'] - , ['metadata', 'Metadata'] - , ['documentation', 'Documentation'] - , ['code', 'Code'] - , ['example', 'Example'] + ['file', 'Data File'], + ['api', 'API'], + ['visualization', 'Visualization'], + ['image', 'Image'], + ['metadata', 'Metadata'], + ['documentation', 'Documentation'], + ['code', 'Code'], + ['example', 'Example'] ] }; // Generate DOM elements @@ -484,7 +487,7 @@ CKAN.View.Resource = Backbone.View.extend({ var errorText = ''; var newLine = false; $.each(v,function(index,value) { - if (newLine) errorText += '
'; + if (newLine) { errorText += '
'; } errorText += value; newLine = true; }); @@ -550,7 +553,7 @@ CKAN.View.Resource = Backbone.View.extend({ * Closes all other panels on the right and opens my editor panel. */ openMyPanel: function(e) { - if (e) e.preventDefault(); + if (e) { e.preventDefault(); } // Close all tables var panel = this.table.parents('.resource-panel'); panel.find('.resource-details').hide(); @@ -579,7 +582,7 @@ CKAN.View.Resource = Backbone.View.extend({ var self = this; $.each(this.raw_resource, function(key,value) { // Skip the known keys - if (self.reservedWord(key)) return; + if (self.reservedWord(key)) { return; } self.addDynamicExtra(key,value); }); this.table.find('.add-resource-extra').click(function(e) { @@ -603,7 +606,7 @@ CKAN.View.Resource = Backbone.View.extend({ var _key = inputKey.val(); var key = _key.trim().replace(/\s+/g,''); // Don't allow you to create an extra called mimetype (etc) - if (self.reservedWord(key)) key=''; + if (self.reservedWord(key)) { key=''; } // Set or unset the field's name if (key.length) { var newName = 'resources__'+self.options.position+'__'+key; @@ -626,32 +629,31 @@ CKAN.View.Resource = Backbone.View.extend({ setExtraName(); }, reservedWord: function(word) { - return word=='cache_last_updated' - || word=='cache_url' - || word=='dataset' - || word=='description' - || word=='displaytitle' - || word=='extras' - || word=='format' - || word=='hash' - || word=='id' - || word=='last_modified' - || word=='mimetype' - || word=='mimetype_inner' - || word=='name' - || word=='package_id' - || word=='position' - || word=='resource_group_id' - || word=='resource_type' - || word=='revision_id' - || word=='revision_timestamp' - || word=='size' - || word=='size_extra' - || word=='state' - || word=='url' - || word=='webstore_last_updated' - || word=='webstore_url' - ; + return word=='cache_last_updated' || + word=='cache_url' || + word=='dataset' || + word=='description' || + word=='displaytitle' || + word=='extras' || + word=='format' || + word=='hash' || + word=='id' || + word=='last_modified' || + word=='mimetype' || + word=='mimetype_inner' || + word=='name' || + word=='package_id' || + word=='position' || + word=='resource_group_id' || + word=='resource_type' || + word=='revision_id' || + word=='revision_timestamp' || + word=='size' || + word=='size_extra' || + word=='state' || + word=='url' || + word=='webstore_last_updated' || + word=='webstore_url'; }, /* * Called when my model is destroyed. Remove me from the page. @@ -663,7 +665,7 @@ CKAN.View.Resource = Backbone.View.extend({ onDatastoreEnabledChange: function(e) { var isChecked = this.table.find('.js-datastore-enabled-checkbox').prop('checked'); var webstore_url = isChecked ? 'enabled' : null; - this.model.set({webstore_url: webstore_url});; + this.model.set({webstore_url: webstore_url}); this.table.find('.js-datastore-enabled-text').val(webstore_url); } }); @@ -686,7 +688,7 @@ CKAN.View.ResourceAddTabs = Backbone.View.extend({ reset: function() { this.el.find('button').removeClass('depressed'); - if (this.subView != null) { + if (this.subView) { this.subView.remove(); this.subView = null; } @@ -751,20 +753,17 @@ CKAN.View.ResourceAddLink = Backbone.View.extend({ }, render: function() { + var tmpl = null; if (this.mode=='file') { - var tmpl = $.tmpl(CKAN.Templates.resourceAddLinkFile); + tmpl = $.tmpl(CKAN.Templates.resourceAddLinkFile); } else if (this.mode=='api') { - var tmpl = $.tmpl(CKAN.Templates.resourceAddLinkApi); + tmpl = $.tmpl(CKAN.Templates.resourceAddLinkApi); } $(this.el).html(tmpl); return this; }, - events: { - 'submit form': 'setResourceInfo', - }, - setResourceInfo: function(e) { e.preventDefault(); @@ -798,6 +797,10 @@ CKAN.View.ResourceAddLink = Backbone.View.extend({ } else { this.model.set({url: urlVal, resource_type: this.mode}); } + }, + + events: { + 'submit form': 'setResourceInfo' } }); @@ -809,12 +812,12 @@ CKAN.View.ResourceAddLink = Backbone.View.extend({ CKAN.Utils = function($, my) { // Animate the appearance of an element by expanding its height my.animateHeight = function(element, animTime) { - if (!animTime) animTime = 350; + if (!animTime) { animTime = 350; } element.show(); var finalHeight = element.height(); element.height(0); element.animate({height:finalHeight}, animTime); - } + }; my.bindInputChanges = function(input, callback) { input.keyup(callback); @@ -826,7 +829,7 @@ CKAN.Utils = function($, my) { my.setupWelcomeBanner = function(banner) { var cookieName = 'ckan_killtopbar'; - var isKilled = ($.cookie(cookieName)!=null); + var isKilled = ($.cookie(cookieName)!==null); if (!isKilled) { banner.show(); // Bind to the close button @@ -884,14 +887,13 @@ CKAN.Utils = function($, my) { var field_name_regex = /^(\S+)__(\d+)__(\S+)$/; var split = old_name.match(field_name_regex); - var new_name = split[1] + '__' + (parseInt(split[2]) + 1) + '__' + split[3] + var new_name = split[1] + '__' + (parseInt(split[2],10) + 1) + '__' + split[3]; - input_box.attr('name', new_name) - input_box.attr('id', new_name) + input_box.attr('name', new_name); + input_box.attr('id', new_name); parent_dd.before( - '' + - '
' + ui.item.label + '
' + '' + '
' + ui.item.label + '
' ); } }); @@ -901,15 +903,14 @@ CKAN.Utils = function($, my) { // // Requires: jquery-ui autocomplete my.setupTagAutocomplete = function(elements) { - elements - // don't navigate away from the field on tab when selecting an item - .bind( "keydown", function( event ) { - if ( event.keyCode === $.ui.keyCode.TAB && - $( this ).data( "autocomplete" ).menu.active ) { + // don't navigate away from the field on tab when selecting an item + elements.bind( "keydown", + function( event ) { + if ( event.keyCode === $.ui.keyCode.TAB && $( this ).data( "autocomplete" ).menu.active ) { event.preventDefault(); } - }) - .autocomplete({ + } + ).autocomplete({ minLength: 1, source: function(request, callback) { // here request.term is whole list of tags so need to get last @@ -920,9 +921,7 @@ CKAN.Utils = function($, my) { var tags = $.map(data.ResultSet.Result, function(value, idx) { return value.Name; }); - callback( - $.ui.autocomplete.filter(tags, _realTerm) - ); + callback( $.ui.autocomplete.filter(tags, _realTerm) ); }); }, focus: function() { @@ -979,7 +978,7 @@ CKAN.Utils = function($, my) { callback(data); }); }, - select: function(event, ui) { + select: function(event, ui) { var input_box = $(this); input_box.val(''); var parent_dd = input_box.parent('dd'); @@ -987,9 +986,9 @@ CKAN.Utils = function($, my) { var field_name_regex = /^(\S+)__(\d+)__(\S+)$/; var split = old_name.match(field_name_regex); - var new_name = split[1] + '__' + (parseInt(split[2]) + 1) + '__' + split[3] - input_box.attr('name', new_name) - input_box.attr('id', new_name) + var new_name = split[1] + '__' + (parseInt(split[2],10) + 1) + '__' + split[3]; + input_box.attr('name', new_name); + input_box.attr('id', new_name); parent_dd.before( '' + @@ -1069,7 +1068,7 @@ CKAN.Utils = function($, my) { e.preventDefault(); var $target = $(e.target); // Extract neighbouring elements - var markdownEditor=$target.closest('.markdown-editor') + var markdownEditor=$target.closest('.markdown-editor'); markdownEditor.find('button').removeClass('depressed'); var textarea = markdownEditor.find('.markdown-input'); var preview = markdownEditor.find('.markdown-preview'); @@ -1081,8 +1080,8 @@ CKAN.Utils = function($, my) { $.post(CKAN.SITE_URL + "/api/util/markdown", { q: raw_markdown }, function(data) { preview.html(data); } ); - preview.width(textarea.width()) - preview.height(textarea.height()) + preview.width(textarea.width()); + preview.height(textarea.height()); textarea.hide(); preview.show(); } else { @@ -1101,13 +1100,13 @@ CKAN.Utils = function($, my) { my.setupNotesExtract = function() { var notes = $('#content div.notes'); var paragraphs = notes.find('#notes-extract > *'); - if (paragraphs.length==0) { + if (paragraphs.length===0) { notes.hide(); } else if (paragraphs.length > 1) { var remainder = notes.find('#notes-remainder'); $.each(paragraphs,function(i,para) { - if (i > 0) remainder.append($(para).remove()); + if (i > 0) { remainder.append($(para).remove()); } }); var finalHeight = remainder.height(); remainder.height(0); @@ -1115,10 +1114,12 @@ CKAN.Utils = function($, my) { notes.find('#notes-toggle button').click( function(event){ notes.find('#notes-toggle button').toggle(); - if ($(event.target).hasClass('more')) + if ($(event.target).hasClass('more')) { remainder.animate({'height':finalHeight}); - else + } + else { remainder.animate({'height':0}); + } return false; } ); @@ -1129,18 +1130,18 @@ CKAN.Utils = function($, my) { var boundToUnload = false; return function($form) { var flashWarning = function() { - if (boundToUnload) return; + if (boundToUnload) { return; } boundToUnload = true; // Bind to the window departure event window.onbeforeunload = function () { return CKAN.Strings.youHaveUnsavedChanges; }; - } + }; // Hook form modifications to flashWarning $form.find('input,select').live('change', function(e) { $target = $(e.target); // Entering text in the 'add' box does not represent a change - if ($target.closest('.resource-add').length==0) { + if ($target.closest('.resource-add').length===0) { flashWarning(); } }); @@ -1230,10 +1231,10 @@ CKAN.DataPreview = function ($, my) { } ]; var dataExplorer = new recline.View.DataExplorer({ - el: my.$dialog - , model: dataset - , views: views - , config: { + el: my.$dialog, + model: dataset, + views: views, + config: { readOnly: true } }); @@ -1319,8 +1320,8 @@ CKAN.DataPreview = function ($, my) { // Cannot reliably preview this item - with no mimetype/format information, // can't guarantee it's not a remote binary file such as an executable. my.showError({ - title: 'Preview not available for data type: ' + resourceData.formatNormalized - , message: '' + title: 'Preview not available for data type: ' + resourceData.formatNormalized, + message: '' }); } }; @@ -1386,9 +1387,9 @@ CKAN.DataPreview = function ($, my) { my.showError = function (error) { var _html = _.template( - '
<%= title %>
<%= message %>
' - , error - ); + '
<%= title %>
<%= message %>
', + error + ); my.$dialog.html(_html); };