[ckan-changes] commit/ckanjs: 6 new changesets

Bitbucket commits-noreply at bitbucket.org
Fri May 13 17:32:08 UTC 2011


6 new changesets in ckanjs:

http://bitbucket.org/okfn/ckanjs/changeset/84c408d7b322/
changeset:   r62:84c408d7b322
user:        rgrp
date:        2011-05-09 20:54:29
summary:     [templates,refactor][s]: move templates out of app/index.html into lib/templates so can be reused from e.g. tests.
affected #:  4 files (14.2 KB)

--- a/app/index.html	Sun May 08 20:18:04 2011 +0100
+++ b/app/index.html	Mon May 09 19:54:29 2011 +0100
@@ -28,7 +28,8 @@
   <!-- defines localConfig --><script src="configlocal.js"></script>
 
-  <script src="../lib//model.js"></script>
+  <script src="../lib/templates.js"></script>
+  <script src="../lib/model.js"></script><script src="../lib/view.js"></script><script src="../lib/ui.js"></script>
 
@@ -136,232 +137,6 @@
   </div><!-- #main --></div><!-- #wrapper -->
-
-<!-- templates -->
-
-<script id="tmpl-package-summary" type="x-jquery-tmpl">
-  <li class="package" package-id="${package.id}">
-    <div class="header">
-      <span class="title" >
-        <a href="${package.ckan_url}" ckan-attrname="title" class="editable">${package.displaytitle}</a>
-      </span>
-      <div class="search_meta">
-        {{if package.resources.length}}
-        <ul class="package_formats">
-          {{each package.resources}}
-            <li>${$value.format}</li>
-          {{/each}}
-        </ul>
-        {{/if}}
-      </div>
-    </div>
-    <div class="extract editable-area">
-      {{html package.snippet()}}
-    </div>
-    <div class="package-tags">
-      {{if package.tags.length}}
-      <ul class="package-tags">
-        {{each package.tags}}
-          <li>${$value}</li>
-        {{/each}}
-      </ul>
-      {{/if}}
-    </div>
-    <ul class="actions">
-      <li>
-        <a href="${urls.packageView}">
-          More »</a>
-      </li>
-      <li>
-        <a href="${urls.packageEdit}">Edit »</a>
-      </li>
-    </ul>
-  </li>
-</script>
-
-<script id="tmpl-package-full" type="x-jquery-tmpl">
-  <div class="package" package-id="${package.id}">
-    <h2 class="title" >
-      <a href="${package.ckan_url}" ckan-attrname="title" class="editable">${package.displaytitle}</a>
-    </h2>
-    <div class="extract editable-area">
-      {{html package.notesHtml}}
-    </div>
-    <div class="package-tags">
-      {{if package.tags.length}}
-      <ul class="package-tags">
-        {{each package.tags}}
-          <li>${$value}</li>
-        {{/each}}
-      </ul>
-      {{/if}}
-    </div>
-  </div>
-</script>
-
-<script id="tmpl-package-form" type="x-jquery-tmpl">
-  <form class="package" action="" method="POST">
-  <fieldset>
-    <legend>
-      <h3>Basics</h3>
-    </legend>
-    <dl>
-      <dt>
-        <label class="field_opt" for="Package--title">
-          Title
-        </label>
-      </dt>
-      <dd>
-        <input id="Package--title" name="Package--title" type="text" value="${title}" placeholder="A title (not a description) .."/>
-      </dd>
-
-      <dt>
-        <label class="field_req" for="Package--name">
-          'Slug'
-        </label>
-      </dt>
-      <dd>
-        <input id="Package--name" maxlength="100" name="Package--name" type="text" value="${name}" placeholder="A shortish name usable in urls ..." />
-        <img src="img/help.png"
-          class="help"
-          title="A unique lowercase name for the package for use in urls and thefore only containing alphanumeric characters plus - and _"
-          >
-      </dd>
-
-      <dt>
-        <label class="field_opt" for="Package--url">
-          Data Home Page
-        </label>
-      </dt>
-      <dd>
-        <input id="Package--url" name="Package--url" type="text" value="${url}" placeholder="http://mydataset.com/about/" />
-      </dd>
-
-      <dt>
-        <label class="field_opt" for="Package--license_id">
-          Licence
-        </label>
-      </dt>
-      <dd>
-        <select id="Package--license_id" name="Package--license_id">
-          <option selected="selected" value=""></option>
-          <option value="notspecified">Other::License Not Specified</option>
-        </select>
-      </dd>
-
-      <dt>
-        <label class="field_opt" for="Package--notes">
-          Description and Notes
-        </label>
-        You can use <a href="http://daringfireball.net/projects/markdown/syntax">Markdown formatting</a>
-      </dt>
-      <dd>
-        <div class="previewable-textarea">
-          <ul class="tabs">
-            <li><a href="#" action="write" class="selected">Write</a></li>
-            <li><a href="#" action="preview">Preview</a></li>
-          </ul>
-          <textarea id="Package--notes" name="Package--notes" placeholder="Start with a summary sentence ...">${notes}</textarea>
-          <div id="Package--notes-preview" class="preview" style="display: none;">
-          <div>
-        </div>
-      </dd>
-
-      <dt>
-        <label class="field_opt" for="Package--tags">
-          Tags
-        </label>
-      </dt>
-      <dd>
-        <input class="tagComplete" data-tagcomplete-queryparam="incomplete" data-tagcomplete-url="/api/2/util/tag/autocomplete" id="Package--tags" name="Package--tags" type="text" value="${tags}" placeholder="e.g. pollution rivers water-quality" />
-      </dd>
-    </dl>
-  </fieldset>
-
-    <div class="submit">
-      <input id="save" name="save" type="submit" value="Save" />
-    </div>
-    <p class="hints">
-    <strong>Important:</strong> By submitting content, you agree to release your contributions
-      under the open license specified on the <a href="http://ckan.net/license">license page</a>. Please <strong>refrain</strong> from editing if you are <strong>not</strong> happy to do this.
-    </p>
-  </form>
-</script>
-
-<script id="tmpl-resource-form" type="x-jquery-tmpl">
-  <h2>Add a Resource (File, API, ...)</h2>
-  <form class="resource" action="" method="POST">
-    <dl>
-      <dt>
-        <label class="field_opt" for="Resource--url">
-          Resource URL
-        </label>
-      </dt>
-      <dd>
-        <input id="Resource--url" name="Resource--url" type="text" value="${url}" placeholder="http://mydataset.com/file.csv" />
-      </dd>
-    </dl>
-
-  <fieldset>
-    <legend>
-      <h3>A Bit More Info</h3>
-    </legend>
-    <dl>
-      <dt>
-        <label class="field_opt" for="Resource--description">
-          Description
-        </label>
-      </dt>
-      <dd>
-        <input id="Resource--description" name="Resource--description" type="text" value="${description}" placeholder="A short description ..."/>
-      </dd>
-
-      <dt>
-        <label class="field_opt" for="Resource--kind">
-          Kind
-        </label>
-      </dt>
-      <dd>
-        <select id="Resource--license_id" name="Resource--license_id">
-          <option selected="selected" value="file">File</option>
-          <option value="api">API</option>
-          <option value="index">Index (or Listing)</option>
-          <option value="example">Example</option>
-        </select>
-      </dd>
-
-      <dt>
-        <label class="field_opt" for="Resource--format">
-          Format
-        </label>
-      </dt>
-      <dd>
-        <input id="Resource--format" name="Resource--format" type="text" value="${format}" placeholder="e.g. csv, zip:csv (zipped csv), sparql"/>
-      </dd>
-
-      <dt>
-        <label class="field_opt" for="Resource--license_id">
-          Licence
-        </label>
-      </dt>
-      <dd>
-        <select id="Resource--license_id" name="Resource--license_id">
-          <option selected="selected" value=""></option>
-          <option value="notspecified">Other::License Not Specified</option>
-        </select>
-      </dd>
-  </fieldset>
-
-    <div class="submit">
-      <input id="save" name="save" type="submit" value="Save" />
-    </div>
-    <p class="hints">
-    <strong>Important:</strong> By submitting content, you agree to release your contributions
-      under the open license specified on the <a href="http://ckan.net/license">license page</a>. Please <strong>refrain</strong> from editing if you are <strong>not</strong> happy to do this.
-    </p>
-  </form>
-</script>
-
 </body></html>
 


--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/templates.js	Mon May 09 19:54:29 2011 +0100
@@ -0,0 +1,226 @@
+var CKAN = CKAN || {};
+
+CKAN.Templates = {
+  packageSummary: '  \
+  <li class="package" package-id="${package.id}"> \
+    <div class="header"> \
+      <span class="title" > \
+        <a href="${package.ckan_url()}" ckan-attrname="title" class="editable">${package.displaytitle()}</a> \
+      </span> \
+      <div class="search_meta"> \
+        {{if package.resources.length}} \
+        <ul class="package_formats"> \
+          {{each package.resources}} \
+            <li>${$value.format}</li> \
+          {{/each}} \
+        </ul> \
+        {{/if}} \
+      </div> \
+    </div> \
+    <div class="extract editable-area"> \
+      {{html package.snippet()}} \
+    </div> \
+    <div class="package-tags"> \
+      {{if package.tags.length}} \
+      <ul class="package-tags"> \
+        {{each package.tags}} \
+          <li>${$value}</li> \
+        {{/each}} \
+      </ul> \
+      {{/if}} \
+    </div> \
+    <ul class="actions"> \
+      <li> \
+        <a href="${urls.packageView}"> \
+          More »</a> \
+      </li> \
+      <li> \
+        <a href="${urls.packageEdit}">Edit »</a> \
+      </li> \
+    </ul> \
+  </li> \
+  ',
+
+  packageFull: ' \
+  <div class="package" package-id="${package.id}"> \
+    <h2 class="title" > \
+      <a href="${package.ckan_url}" ckan-attrname="title" class="editable">${package.displaytitle}</a> \
+    </h2> \
+    <div class="extract editable-area"> \
+      {{html package.notesHtml}} \
+    </div> \
+    <div class="package-tags"> \
+      {{if package.tags.length}} \
+      <ul class="package-tags"> \
+        {{each package.tags}} \
+          <li>${$value}</li> \
+        {{/each}} \
+      </ul> \
+      {{/if}} \
+    </div> \
+  </div> \
+  ',
+
+  packageForm: ' \
+  <form class="package" action="" method="POST"> \
+  <fieldset> \
+    <legend> \
+      <h3>Basics</h3> \
+    </legend> \
+    <dl> \
+      <dt> \
+        <label class="field_opt" for="Package--title"> \
+          Title \
+        </label> \
+      </dt> \
+      <dd> \
+        <input id="Package--title" name="Package--title" type="text" value="${title}" placeholder="A title (not a description) .."/> \
+      </dd> \
+ \
+      <dt> \
+        <label class="field_req" for="Package--name"> \
+          Slug \
+        </label> \
+      </dt> \
+      <dd> \
+        <input id="Package--name" maxlength="100" name="Package--name" type="text" value="${name}" placeholder="A shortish name usable in urls ..." /> \
+        <img src="img/help.png" \
+          class="help" \
+          title="A unique lowercase name for the package for use in urls and thefore only containing alphanumeric characters plus - and _" \
+          > \
+      </dd> \
+ \
+      <dt> \
+        <label class="field_opt" for="Package--url"> \
+          Data Home Page \
+        </label> \
+      </dt> \
+      <dd> \
+        <input id="Package--url" name="Package--url" type="text" value="${url}" placeholder="http://mydataset.com/about/" /> \
+      </dd> \
+ \
+      <dt> \
+        <label class="field_opt" for="Package--license_id"> \
+          Licence \
+        </label> \
+      </dt> \
+      <dd> \
+        <select id="Package--license_id" name="Package--license_id"> \
+          <option selected="selected" value=""></option> \
+          <option value="notspecified">Other::License Not Specified</option> \
+        </select> \
+      </dd> \
+ \
+      <dt> \
+        <label class="field_opt" for="Package--notes"> \
+          Description and Notes \
+        </label> \
+        You can use <a href="http://daringfireball.net/projects/markdown/syntax">Markdown formatting</a> \
+      </dt> \
+      <dd> \
+        <div class="previewable-textarea"> \
+          <ul class="tabs"> \
+            <li><a href="#" action="write" class="selected">Write</a></li> \
+            <li><a href="#" action="preview">Preview</a></li> \
+          </ul> \
+          <textarea id="Package--notes" name="Package--notes" placeholder="Start with a summary sentence ...">${notes}</textarea> \
+          <div id="Package--notes-preview" class="preview" style="display: none;"> \
+          <div> \
+        </div> \
+      </dd> \
+ \
+      <dt> \
+        <label class="field_opt" for="Package--tags"> \
+          Tags \
+        </label> \
+      </dt> \
+      <dd> \
+        <input class="tagComplete" data-tagcomplete-queryparam="incomplete" data-tagcomplete-url="/api/2/util/tag/autocomplete" id="Package--tags" name="Package--tags" type="text" value="${tags}" placeholder="e.g. pollution rivers water-quality" /> \
+      </dd> \
+    </dl> \
+  </fieldset> \
+ \
+    <div class="submit"> \
+      <input id="save" name="save" type="submit" value="Save" /> \
+    </div> \
+    <p class="hints"> \
+    <strong>Important:</strong> By submitting content, you agree to release your contributions \
+      under the open license specified on the <a href="http://ckan.net/license">license page</a>. Please <strong>refrain</strong> from editing if you are <strong>not</strong> happy to do this. \
+    </p> \
+  </form> \
+  ',
+
+  resourceForm: ' \
+  <h2>Add a Resource (File, API, ...)</h2> \
+  <form class="resource" action="" method="POST"> \
+    <dl> \
+      <dt> \
+        <label class="field_opt" for="Resource--url"> \
+          Resource URL \
+        </label> \
+      </dt> \
+      <dd> \
+        <input id="Resource--url" name="Resource--url" type="text" value="${url}" placeholder="http://mydataset.com/file.csv" /> \
+      </dd> \
+    </dl> \
+ \
+  <fieldset> \
+    <legend> \
+      <h3>A Bit More Info</h3> \
+    </legend> \
+    <dl> \
+      <dt> \
+        <label class="field_opt" for="Resource--description"> \
+          Description \
+        </label> \
+      </dt> \
+      <dd> \
+        <input id="Resource--description" name="Resource--description" type="text" value="${description}" placeholder="A short description ..."/> \
+      </dd> \
+ \
+      <dt> \
+        <label class="field_opt" for="Resource--kind"> \
+          Kind \
+        </label> \
+      </dt> \
+      <dd> \
+        <select id="Resource--license_id" name="Resource--license_id"> \
+          <option selected="selected" value="file">File</option> \
+          <option value="api">API</option> \
+          <option value="index">Index (or Listing)</option> \
+          <option value="example">Example</option> \
+        </select> \
+      </dd> \
+ \
+      <dt> \
+        <label class="field_opt" for="Resource--format"> \
+          Format \
+        </label> \
+      </dt> \
+      <dd> \
+        <input id="Resource--format" name="Resource--format" type="text" value="${format}" placeholder="e.g. csv, zip:csv (zipped csv), sparql"/> \
+      </dd> \
+ \
+      <dt> \
+        <label class="field_opt" for="Resource--license_id"> \
+          Licence \
+        </label> \
+      </dt> \
+      <dd> \
+        <select id="Resource--license_id" name="Resource--license_id"> \
+          <option selected="selected" value=""></option> \
+          <option value="notspecified">Other::License Not Specified</option> \
+        </select> \
+      </dd> \
+  </fieldset> \
+ \
+    <div class="submit"> \
+      <input id="save" name="save" type="submit" value="Save" /> \
+    </div> \
+    <p class="hints"> \
+    <strong>Important:</strong> By submitting content, you agree to release your contributions \
+      under the open license specified on the <a href="http://ckan.net/license">license page</a>. Please <strong>refrain</strong> from editing if you are <strong>not</strong> happy to do this. \
+    </p> \
+  </form> \
+  '
+};


--- a/lib/view.js	Sun May 08 20:18:04 2011 +0100
+++ b/lib/view.js	Mon May 09 19:54:29 2011 +0100
@@ -62,7 +62,7 @@
 
   my.PackageCreateView = Backbone.View.extend({
     render: function() {
-      var tmpl = $('#tmpl-package-form').tmpl(this.model.toJSON());
+      var tmpl = $.tmpl(CKAN.Templates.packageForm, this.model.toJSON());
       $(this.el).html(tmpl);
       return this;
     },
@@ -123,7 +123,7 @@
           packageEdit: CKAN.UI.workspace.url('package', 'edit', this.model.id)
         }
       }
-      this.el = $('#tmpl-package-summary').tmpl(tmplData);
+      this.el = $.tmpl(CKAN.Templates.packageSummary, tmplData);
       // have to redelegate as element set up here ...
       this.delegateEvents();
       return this;
@@ -138,7 +138,7 @@
       var tmplData = {
         package: this.model.toJSON(),
       }
-      this.el = $('#tmpl-package-full').tmpl(tmplData);
+      this.el = $.tmpl(CKAN.Templates.packageFull, tmplData);
       // have to redelegate as element set up here ...
       this.delegateEvents();
       return this;
@@ -220,7 +220,7 @@
 
   my.ResourceEditView = Backbone.View.extend({
     render: function() {
-      var tmpl = $('#tmpl-resource-form').tmpl(this.model.toJSON());
+      var tmpl = $.tmpl(CKAN.Templates.resourceForm, this.model.toJSON());
       $(this.el).html(tmpl);
       return this;
     },


--- a/test/index.html	Sun May 08 20:18:04 2011 +0100
+++ b/test/index.html	Mon May 09 19:54:29 2011 +0100
@@ -12,9 +12,12 @@
   <script src="../vendor/showdown/showdown.js"></script><script type="text/javascript" src="../vendor/qunit/qunit.js"></script>
+  <!--
   <script type="text/javascript" src="../vendor/sinon/sinon-1.0.0.js"></script><script type="text/javascript" src="../vendor/sinon/sinon-qunit-1.0.0.js"></script>
+  -->
 
+  <script type="text/javascript" src="../lib/templates.js"></script><script type="text/javascript" src="../lib/model.js"></script><script type="text/javascript" src="../lib/view.js"></script><script type="text/javascript" src="../lib/ui.js"></script>


http://bitbucket.org/okfn/ckanjs/changeset/abcafed4fcd7/
changeset:   r63:abcafed4fcd7
user:        rgrp
date:        2011-05-09 22:52:23
summary:     [test/fixtures][xs]: fix left in comma typos in json/javascript.
affected #:  1 file (4 bytes)

--- a/test/fixtures.js	Mon May 09 19:54:29 2011 +0100
+++ b/test/fixtures.js	Mon May 09 21:52:23 2011 +0100
@@ -12,10 +12,10 @@
     version: null,
     license_id: "cc-nc",
     resources: [ ],
-    tags: [,
+    tags: [
       "russian"
     ],
-    groups: [,
+    groups: [
       "david"
     ],
     name: "warandpeace",
@@ -66,11 +66,11 @@
         size: "345"
       }
     ],
-    tags: [,
+    tags: [
       "russian",
       "tolstoy"
     ],
-    groups: [,
+    groups: [
       "david",
       "roger"
     ],


http://bitbucket.org/okfn/ckanjs/changeset/673126e618ab/
changeset:   r64:673126e618ab
user:        rgrp
date:        2011-05-09 22:55:23
summary:     [tests,templates,model/Package][s]: fix and extend view tests refactoring templates and template date in process.

* view tests were failing now that tepmlates were actually being called (post templates refactor). Fixed this and extended.
* model/Package,templates: render model data down so it can be used as simple attributes in template (e.g. package.notesHtml rather than package.notesHtml)
affected #:  6 files (1002 bytes)

--- a/lib/model.js	Mon May 09 21:52:23 2011 +0100
+++ b/lib/model.js	Mon May 09 21:55:23 2011 +0100
@@ -33,13 +33,19 @@
       return out;
     },
 
-    notesHtml: function() {
+    toTemplateJSON: function() {
+      var out = this.toJSON();
+      out.ckan_url = CKAN.Model.url + '/package/' + this.get('name');
+      var title = this.get('title');
+      out.displaytitle = title ? title : 'No title ...';
       var notes = this.get('notes');
-      return showdown.makeHtml(notes ? notes : '');
+      out.notesHtml = showdown.makeHtml(notes ? notes : '');
+      out.snippet = this.makeSnippet(out.notesHtml);
+      return out;
     },
 
-    snippet: function() {
-      var out = $(this.notesHtml()).text();
+    makeSnippet: function(notesHtml) {
+      var out = $(notesHtml).text();
       if (out.length > 190) {
         out = out.slice(0, 190) + ' ...';
       }


--- a/lib/templates.js	Mon May 09 21:52:23 2011 +0100
+++ b/lib/templates.js	Mon May 09 21:55:23 2011 +0100
@@ -5,7 +5,7 @@
   <li class="package" package-id="${package.id}"> \
     <div class="header"> \
       <span class="title" > \
-        <a href="${package.ckan_url()}" ckan-attrname="title" class="editable">${package.displaytitle()}</a> \
+        <a href="${package.ckan_url}" ckan-attrname="title" class="editable">${package.displaytitle}</a> \
       </span> \
       <div class="search_meta"> \
         {{if package.resources.length}} \
@@ -18,7 +18,7 @@
       </div> \
     </div> \
     <div class="extract editable-area"> \
-      {{html package.snippet()}} \
+      {{html package.snippet}} \
     </div> \
     <div class="package-tags"> \
       {{if package.tags.length}} \


--- a/lib/view.js	Mon May 09 21:52:23 2011 +0100
+++ b/lib/view.js	Mon May 09 21:55:23 2011 +0100
@@ -117,7 +117,7 @@
 
     render: function() {
       var tmplData = {
-        package: this.model.toJSON(),
+        package: this.model.toTemplateJSON(),
         urls: {
           packageView: CKAN.UI.workspace.url('package', 'view', this.model.id),
           packageEdit: CKAN.UI.workspace.url('package', 'edit', this.model.id)
@@ -188,13 +188,6 @@
         self.collection.count = data.count;
 
         $(data.results).each(function(idx, item) {
-          item.ckan_url = CKAN.Model.url + '/package/' + item.name;
-
-          item.displaytitle = item.title ? item.title : 'No title ...';
-
-          // for templating (to be ckan compatible)
-          item.package = item;
-
           var pkg = new CKAN.Model.Package(item);
           self.collection.add(pkg);
         });


--- a/test/index.html	Mon May 09 21:52:23 2011 +0100
+++ b/test/index.html	Mon May 09 21:55:23 2011 +0100
@@ -12,10 +12,8 @@
   <script src="../vendor/showdown/showdown.js"></script><script type="text/javascript" src="../vendor/qunit/qunit.js"></script>
-  <!--
   <script type="text/javascript" src="../vendor/sinon/sinon-1.0.0.js"></script><script type="text/javascript" src="../vendor/sinon/sinon-qunit-1.0.0.js"></script>
-  --><script type="text/javascript" src="../lib/templates.js"></script><script type="text/javascript" src="../lib/model.js"></script>


--- a/test/test_model.js	Mon May 09 21:52:23 2011 +0100
+++ b/test/test_model.js	Mon May 09 21:55:23 2011 +0100
@@ -13,5 +13,7 @@
   var pkg = new CKAN.Model.Package(indata);
 
   equals(pkg.get('title'), indata.title);
-  equals(pkg.notesHtml(), '<h2>Xyz</h2>');
+  var out = pkg.toTemplateJSON();
+  equals(out.notesHtml, '<h2>Xyz</h2>');
+  equals(out.displaytitle, indata.title);
 });


--- a/test/test_view.js	Mon May 09 21:52:23 2011 +0100
+++ b/test/test_view.js	Mon May 09 21:55:23 2011 +0100
@@ -2,6 +2,18 @@
 
 CKAN.UI.initialize()
 
+test("PackageSummaryView", function () {
+  var pkg = new CKAN.Model.Package(packages[1]);
+  var view = new CKAN.View.PackageSummaryView({
+    model: pkg
+  });
+  view.render();
+  var tmpl = $(view.el);
+  console.log(tmpl.html());
+  var title = tmpl.find('.title a').text();
+  equals(title, 'A Novel By Tolstoy');
+});
+
 test("PackageSearchView", function () {
   var coll = new CKAN.Model.PackageCollection()
 
@@ -11,6 +23,8 @@
   });
   var pkg = new CKAN.Model.Package(packages[1]);
   coll.add([pkg]);
+  searchView.render();
 
-  searchView.render();
+  var title = $('.packages li .title a').text();
+  equals(title, 'A Novel By Tolstoy');
 });


http://bitbucket.org/okfn/ckanjs/changeset/41984eb693b5/
changeset:   r65:41984eb693b5
user:        rgrp
date:        2011-05-11 00:33:08
summary:     [view/package][xs]: small change to package full view to have element passed in by creator of view rather than created internally.
affected #:  2 files (131 bytes)

--- a/lib/ui.js	Mon May 09 21:55:23 2011 +0100
+++ b/lib/ui.js	Tue May 10 23:33:08 2011 +0100
@@ -89,10 +89,14 @@
     },
 
     packageView: function(id) {
+      var $viewpage = $('#view-page');
       var self = this;
       function _show(model) {
-        var newView = new CKAN.View.PackageFullView({model: model});
-        $('#view-page').html(newView.render().el);
+        var newView = new CKAN.View.PackageFullView({
+          model: model,
+          el: $viewpage
+        });
+        newView.render();
         self.switchView('view');
       }
       this._findPackage(id, _show)


--- a/lib/view.js	Mon May 09 21:55:23 2011 +0100
+++ b/lib/view.js	Tue May 10 23:33:08 2011 +0100
@@ -136,11 +136,9 @@
 
     render: function() {
       var tmplData = {
-        package: this.model.toJSON(),
+        package: this.model.toTemplateJSON(),
       }
-      this.el = $.tmpl(CKAN.Templates.packageFull, tmplData);
-      // have to redelegate as element set up here ...
-      this.delegateEvents();
+      this.el.html($.tmpl(CKAN.Templates.packageFull, tmplData));
       return this;
     }
   });


http://bitbucket.org/okfn/ckanjs/changeset/f716a98043cc/
changeset:   r66:f716a98043cc
user:        rgrp
date:        2011-05-12 02:45:13
summary:     [css,lib/view][xs]: minor improvements to package form.
affected #:  2 files (555 bytes)

--- a/app/css/ckanjs.css	Tue May 10 23:33:08 2011 +0100
+++ b/app/css/ckanjs.css	Thu May 12 01:45:13 2011 +0100
@@ -132,8 +132,6 @@
 }
 
 div.previewable-textarea {
-  margin: -10px 0 10px 0;
-  padding: 5px;
   background: #EEE;
   -webkit-border-radius: 5px;
   -moz-border-radius: 5px;
@@ -142,7 +140,7 @@
   border-bottom-right-radius: 5px 5px;
   border-bottom-left-radius: 5px 5px;
   border: 1px solid #CCC;
-  padding: 10px 11px 0 10px;
+  padding: 0 5px 0 10px;
 }
 
 form ul.tabs li a {
@@ -170,7 +168,7 @@
 }
 
 div.preview {
-  min-height: 40px;
+  min-height: 80px;
   background: white;
   border: 1px solid #CCC;
   margin-bottom: 5px;


--- a/lib/view.js	Tue May 10 23:33:08 2011 +0100
+++ b/lib/view.js	Thu May 12 01:45:13 2011 +0100
@@ -99,7 +99,7 @@
       var textarea = div.find('textarea');
       var preview = div.find('.preview');
       if (action=='preview') {
-        preview.html(this.model.notesHtml());
+        preview.html(this.model.toTemplateJSON().notesHtml);
         textarea.hide();
         preview.show();
       } else {
@@ -134,12 +134,31 @@
     initialize: function() {
     },
 
+    events: {
+      'click .action-add-resource': 'showResourceAdd'
+    },
+
     render: function() {
       var tmplData = {
         package: this.model.toTemplateJSON(),
       }
       this.el.html($.tmpl(CKAN.Templates.packageFull, tmplData));
       return this;
+    },
+
+    showResourceAdd: function(e) {
+      e.preventDefault();
+      var $el = this.el.find('.add-resource-form');
+      var newResource = new CKAN.Model.Package({});
+      newResource.bind('change', this.handleNewResourceSave);
+      var resourceView = new my.ResourceEditView({
+        el: $el,
+        model: newResource
+      });
+      resourceView.render();
+    },
+
+    handleNewResourceSave: function(e) {
     }
   });
 


http://bitbucket.org/okfn/ckanjs/changeset/01e0501d5a7f/
changeset:   r67:01e0501d5a7f
user:        rgrp
date:        2011-05-12 03:19:58
summary:     [package/view][m]: implement inline addition of resources (though no save to server yet).

* tests: really starting to get the hang of this.
affected #:  4 files (1.9 KB)

--- a/lib/templates.js	Thu May 12 01:45:13 2011 +0100
+++ b/lib/templates.js	Thu May 12 02:19:58 2011 +0100
@@ -58,6 +58,32 @@
       </ul> \
       {{/if}} \
     </div> \
+    <div class="resources subsection"> \
+      <h3>Downloads & Resources</h3> \
+      <table> \
+        <tr> \
+          <th>Description</th> \
+          <th>Format</th> \
+          <th>Hash</th> \
+        </tr> \
+        {{each package.resources}} \
+        <tr> \
+          <td> \
+            {{if $value.description}} \
+            <a href="${$value.url}" target="_blank">${$value.description}</a> \
+            {{else}} \
+            <a href="${$value.url}" target="_blank">Download (no description)</a> \
+            {{/if}} \
+          </td> \
+          <td>${$value.format}</td> \
+        </tr> \
+        {{/each}} \
+      </table> \
+      <div class="add-resource"> \
+        <a href="#" class="action-add-resource">Add a resource</a> \
+        <div class="add-resource-form"></div> \
+      </div> \
+    </div> \
   </div> \
   ',
 
@@ -70,16 +96,16 @@
     <dl> \
       <dt> \
         <label class="field_opt" for="Package--title"> \
-          Title \
+          Title * \
         </label> \
       </dt> \
       <dd> \
-        <input id="Package--title" name="Package--title" type="text" value="${title}" placeholder="A title (not a description) .."/> \
+        <input id="Package--title" name="Package--title" type="text" value="${title}" placeholder="A title (not a description) ..."/> \
       </dd> \
  \
       <dt> \
         <label class="field_req" for="Package--name"> \
-          Slug \
+          Slug * \
         </label> \
       </dt> \
       <dd> \
@@ -92,7 +118,7 @@
  \
       <dt> \
         <label class="field_opt" for="Package--url"> \
-          Data Home Page \
+          Home Page \
         </label> \
       </dt> \
       <dd> \


--- a/lib/view.js	Thu May 12 01:45:13 2011 +0100
+++ b/lib/view.js	Thu May 12 02:19:58 2011 +0100
@@ -150,15 +150,20 @@
       e.preventDefault();
       var $el = this.el.find('.add-resource-form');
       var newResource = new CKAN.Model.Package({});
-      newResource.bind('change', this.handleNewResourceSave);
+      var self = this;
+      function handleNewResourceSave(model) {
+        var res = self.model.get('resources');
+        res.push(model.toJSON());
+        self.model.set({resources: res});
+        $el.hide();
+        self.render();
+      }
+      newResource.bind('change', handleNewResourceSave);
       var resourceView = new my.ResourceEditView({
         el: $el,
         model: newResource
       });
       resourceView.render();
-    },
-
-    handleNewResourceSave: function(e) {
     }
   });
 
@@ -240,7 +245,8 @@
     },
 
     saveData: function() {
-      this.model.save(this.getData(), {
+      // only set rather than save as can only save resources as part of a package atm
+      this.model.set(this.getData(), {
         error: function(model, error) {
           var msg = 'Failed to save, possibly due to invalid data ';
           msg += JSON.stringify(error);


--- a/test/index.html	Thu May 12 01:45:13 2011 +0100
+++ b/test/index.html	Thu May 12 02:19:58 2011 +0100
@@ -31,27 +31,27 @@
   <h2 id="qunit-userAgent"></h2><ol id="qunit-tests"></ol>
 
-  <!-- search form -->
-  <div id="search-page" class="page-view">
-    <form id="search-form">
-      <input type="search" name="q" placeholder="Search ..." class="search" />
-      <input type="submit" name="submit" value="Search" />
-    </form>
+  <div class="fixture">
+    <!-- search form -->
+    <div id="search-page" class="page-view">
+      <form id="search-form">
+        <input type="search" name="q" placeholder="Search ..." class="search" />
+        <input type="submit" name="submit" value="Search" />
+      </form>
 
-    <div class="dialog">
-    </div>
+      <div class="dialog">
+      </div>
 
-    <div class="results" style="display: none;">
-      <h3>Results</h3>
-      <p>
-      <strong><span class="count"></span></strong> results found.
-      </p>
+      <div class="results" style="display: none;">
+        <h3>Results</h3>
+        <p>
+        <strong><span class="count"></span></strong> results found.
+        </p>
 
-      <ul class="packages">
-      </ul>
+        <ul class="packages">
+        </ul>
+      </div></div></div>
-
-
 </body></html>


--- a/test/test_view.js	Thu May 12 01:45:13 2011 +0100
+++ b/test/test_view.js	Thu May 12 02:19:58 2011 +0100
@@ -9,11 +9,33 @@
   });
   view.render();
   var tmpl = $(view.el);
-  console.log(tmpl.html());
   var title = tmpl.find('.title a').text();
   equals(title, 'A Novel By Tolstoy');
 });
 
+test("PackageFullView", function () {
+  var pkg = new CKAN.Model.Package(packages[0]);
+  var $view = $('<div />').appendTo($('.fixture'));
+  var view = new CKAN.View.PackageFullView({
+    el: $view,
+    model: pkg
+  });
+  view.render();
+  var tmpl = $(view.el);
+  var title = tmpl.find('.title a').text();
+  equals(title, 'A Wonderful Story');
+
+  $('.action-add-resource').click();
+  var out = tmpl.find('form.resource');
+  equals(out.length, 1, 'Did not find resource form');
+  tmpl.find('form input[name=Resource--url]').val('http://xyz.org');
+  tmpl.find('form.resource').submit();
+  equals(pkg.get('resources').length, 1);
+
+  var out = $view.find('.resources table tr:last td:first').text();
+  ok(out.indexOf('Download (no description)')!=-1, 'Did not find required string');
+});
+
 test("PackageSearchView", function () {
   var coll = new CKAN.Model.PackageCollection()

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

--

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