address code review comments and jshint the test
authorGil Moskowitz <gmoskowitz@xtuple.com>
Tue, 17 Jun 2014 20:47:36 +0000 (16:47 -0400)
committerGil Moskowitz <gmoskowitz@xtuple.com>
Tue, 17 Jun 2014 20:47:36 +0000 (16:47 -0400)
lib/enyo-x/source/views/grid_box.js
lib/enyo-x/source/views/workspace.js
node-datasource/routes/export.js
test/extensions/all/grid_box.js

index 1d55fee..127853a 100644 (file)
@@ -531,9 +531,7 @@ trailing:true, white:true, strict: false*/
     },
     exportAttr: function (inSender, inEvent) {
       var gridbox = inEvent.originator.parent.parent;
-      this.doExportAttr({ recordType: gridbox.parent.parent.model,
-                          uuid:       gridbox.parent.parent.value.attributes.uuid,
-                          attr:       gridbox.attr });
+      this.doExportAttr({ attr: gridbox.attr });
     },
     refreshLists: function () {
       this.$.aboveGridList.refresh();
index 849c58a..862278f 100644 (file)
@@ -1055,14 +1055,17 @@ trailing:true, white:true, strict: false*/
     },
 
     exportAttr: function (inSender, inEvent) {
-      this.openExportTab('export', inEvent.recordType, inEvent.uuid, inEvent.attr);
+      this.openExportTab('export', inEvent.attr);
       return true;
     },
 
     // export just one attribute of the model displayed by the workspace
-    openExportTab: function (routeName, recordType, id, attr) {
-      var query = { parameters: [{ attribute: "uuid", value: id }],
-                    details: { attr: attr }
+    openExportTab: function (routeName, attr) {
+      var recordType = this.$.workspace.value.recordType,
+          id         = this.$.workspace.value.id,
+          idAttr     = this.$.workspace.value.idAttribute,
+          query = { parameters: [{ attribute: idAttr, value: id }],
+                    details: { attr: attr, id: id }
       };
       // sending the locale information back over the wire saves a call to the db
       window.open(XT.getOrganizationPath() +
index 6312135..8f598ca 100644 (file)
@@ -151,8 +151,9 @@ regexp:true, undef:true, strict:true, trailing:true, white:true */
         var resultAsCsv,
           filename = "export",
           type,
-          number = result.data && result.data.data && result.data.data[0] &&
-                   (result.data.data[0].number || result.data.data[0].name),
+          number = requestDetails.query &&
+                   requestDetails.query.details &&
+                   requestDetails.query.details.id,
           attr = requestDetails.query &&
                  requestDetails.query.details &&
                  requestDetails.query.details.attr
@@ -169,6 +170,8 @@ regexp:true, undef:true, strict:true, trailing:true, white:true */
         }
 
         try {
+          /* export requests have 2 flavors: export a list of records (data.data)
+             or export a list of children of the current record ([0][attr]) */
           if (attr) {
             resultAsCsv = jsonToCsv(result.data.data[0][attr]);
           } else {
index 804009b..09e017d 100644 (file)
                           assert.equal(gridBox.liveModels().length, startingRows += 1);
                         });
 
-                        it('Check export', function() {
-                          function getExportButton(obj) {
+                        it('Check export', function () {
+                          var getExportButton = function (obj) {
                             var result = null;
-                            if ("$" in obj) {
-                              result = obj.$.exportButton
-                                    || _.find(obj.$, getExportButton);
+                            if (_.isObject(obj.$)) {
+                              result = obj.$.exportButton ||
+                                       _.find(obj.$, getExportButton);
                             }
                             return result;
-                          }
+                          };
 
-                          var gridBox = component
-                            , exportButton = getExportButton(gridBox);
+                          var gridBox = component,
+                              exportButton = getExportButton(gridBox);
                           assert.ok(exportButton);
                           // TODO: need to populate before we can export
                           // assert.doesNotThrow(exportButton.doTap());