Skip to content

Commit

Permalink
[#1506][editresources][s]: Name box dynamically updates in keeping wi…
Browse files Browse the repository at this point in the history
…th server side logic.
  • Loading branch information
teajaymars committed Feb 24, 2012
1 parent 0bfb273 commit daf506b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
22 changes: 17 additions & 5 deletions ckan/public/scripts/application.js
Expand Up @@ -606,6 +606,7 @@ CKAN.Utils = function($, my) {
};

return my;

}(jQuery, CKAN.Utils || {});


Expand Down Expand Up @@ -732,8 +733,17 @@ CKAN.View.ResourceEditList = Backbone.View.extend({
};

// == Inner Functions: Update the name as you type == //
var setName = function(newName) {
newName = newName || ('<em>'+CKAN.Strings.noNameBrackets+'</em>');
var setName = function(name,description) {
var newName = name;
if (!newName) {
newName = description;
if (!newName) {
newName = '[no name] ' + resource.attributes.id;
}
else if (newName.length>45) {
newName = description.substring(0,45)+'...';
}
}
// Need to structurally modify the DOM to force a re-render of text
$link = $li.find('.js-resource-edit-name');
$link.html('<span>'+newName+'</span>');
Expand All @@ -755,15 +765,17 @@ CKAN.View.ResourceEditList = Backbone.View.extend({
}

var nameBox = $table.find('input.js-resource-edit-name');
CKAN.Utils.bindInputChanges(nameBox,function(e) { setName($(e.target).val()); });
var descriptionBox = $table.find('textarea.js-resource-edit-description');
var formatBox = $table.find('input.js-resource-edit-format');
CKAN.Utils.bindInputChanges(formatBox,function(e) { setFormat($(e.target).val()); });
CKAN.Utils.bindInputChanges(nameBox, function() { setName(nameBox.val(),descriptionBox.val()); });
CKAN.Utils.bindInputChanges(descriptionBox, function() { setName(nameBox.val(),descriptionBox.val()); });
CKAN.Utils.bindInputChanges(formatBox, function() { setFormat(formatBox.val()); });

$li.find('.js-resource-edit-open').click(openTable);
// TODO
$li.find('.js-resource-edit-delete').click(deleteResource);
// Initialise name
setName(resource.attributes.name);
setName(resource.attributes.name,resource.attributes.description);
setFormat(resource.attributes.format);
},

Expand Down
2 changes: 1 addition & 1 deletion ckan/public/scripts/templates.js
Expand Up @@ -91,7 +91,7 @@ CKAN.Templates.resourceDetails = ' \
<tr> \
<td class="dataset-label" property="rdfs:label">'+CKAN.Strings.description+'</td> \
<td class="dataset-details" property="rdf:value"> \
<textarea name="resources__${num}__description" type="text">${resource.description}</textarea> \
<textarea class="js-resource-edit-description" name="resources__${num}__description" type="text">${resource.description}</textarea> \
</td> \
</tr> \
<tr> \
Expand Down

0 comments on commit daf506b

Please sign in to comment.