[ckan-changes] commit/ckan: rgrp: [js/resource/add][s]: resource upload now results in new row for table (refs #878 and refs #1296).

Bitbucket commits-noreply at bitbucket.org
Fri Sep 9 10:45:50 UTC 2011


1 new changeset in ckan:

http://bitbucket.org/okfn/ckan/changeset/c6f7f5018b4f/
changeset:   c6f7f5018b4f
branch:      feature-1294-ux-improvements-dataset
user:        rgrp
date:        2011-09-09 12:45:20
summary:     [js/resource/add][s]: resource upload now results in new row for table (refs #878 and refs #1296).

* Also refactor existing resource add to use change event on resource model rather than explict method call.
affected #:  2 files (295 bytes)

--- a/ckan/public/scripts/application.js	Fri Sep 09 08:30:40 2011 +0100
+++ b/ckan/public/scripts/application.js	Fri Sep 09 11:45:20 2011 +0100
@@ -384,21 +384,13 @@
   },
 
   events: {
-    'submit form': 'addNewResource',
+    'submit form': 'setResourceInfo',
   },
 
-  addNewResource: function(e) {
+  setResourceInfo: function(e) {
     e.preventDefault();
-    var maxId = 0;
-    var ids = $.map($('.resource-table').find('input'), function(item, idx) {
-      var thisId = parseInt($(item).attr('name').split('__')[1]);
-      maxId=Math.max(maxId, thisId);
-    });
-
     var urlVal=this.el.find('input[name=url]').val();
-    var $newRow = $.tmpl(CKAN.Templates.resourceEntry, { url: urlVal, num: maxId+1 });
-
-    $('.resource-table tbody').append($newRow);
+    this.model.set({url: urlVal, type: this.mode})
   }
 });
 
@@ -440,6 +432,7 @@
     var resource = new CKAN.Model.Resource({
       'dataset': this.model
     });
+    resource.bind('change', this.addNewResource);
     // Open sub-pane
     if (action=='upload-file') {
       this.subView = new CKAN.View.ResourceUpload({
@@ -460,6 +453,20 @@
     }
     this.subView.render();
     return false;
+  },
+
+  addNewResource: function(resource) {
+    var maxId = 0;
+    var ids = $.map($('.resource-table').find('input'), function(item, idx) {
+      var thisId = parseInt($(item).attr('name').split('__')[1]);
+      maxId=Math.max(maxId, thisId);
+    });
+    var tmplData = {
+      resource: resource.toTemplateJSON(),
+      num: maxId+1
+    };
+    var $newRow = $.tmpl(CKAN.Templates.resourceEntry, tmplData);
+    $('.resource-table tbody').append($newRow);
   }
 });
 


--- a/ckan/public/scripts/templates.js	Fri Sep 09 08:30:40 2011 +0100
+++ b/ckan/public/scripts/templates.js	Fri Sep 09 11:45:20 2011 +0100
@@ -73,19 +73,19 @@
 CKAN.Templates.resourceEntry = ' \
   <tr> \
   <td class="resource-url"> \
-    <input name="resources__${num}__url" type="text" value="${url}" class="short" /> \
+    <input name="resources__${num}__url" type="text" value="${resource.url}" class="short" /> \
   </td> \
   <td class="resource-format"> \
-    <input name="resources__${num}__format" type="text" value="" class="autocomplete-format short" /> \
+    <input name="resources__${num}__format" type="text" value="${resource.format}" class="autocomplete-format short" /> \
   </td> \
   <td class="resource-description"> \
-    <input name="resources__${num}__description" type="text" value="" class="medium-width" /> \
+    <input name="resources__${num}__description" type="text" value="${resource.description}" class="medium-width" /> \
   </td> \
   <td class="resource-hash"> \
-    <input name="resources__${num}__hash" type="text" value="" class="short" /> \
+    <input name="resources__${num}__hash" type="text" value="${resource.hash}" class="short" /> \
   </td> \
   <td class="resource-id"> \
-    <input name="resources__${num}__id" type="hidden" value="" /> \
+    <input name="resources__${num}__id" type="hidden" value="${resource.id}" /> \
   </td> \
 </tr> \
 ';

Repository URL: https://bitbucket.org/okfn/ckan/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.




More information about the ckan-changes mailing list