Code review comment for lp:~bcsaller/juju-gui/export-ui

Revision history for this message
Benjamin Saller (bcsaller) wrote :

Reviewers: mp+162691_code.launchpad.net,

Message:
Please take a look.

Description:
Drag out to export

Dragging the environment icon in the nav to another supporting
GUI app will create DnD export/import chain.

https://code.launchpad.net/~bcsaller/juju-gui/export-ui/+merge/162691

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/9252043/

Affected files:
   A [revision details]
   M app/index.html
   M app/views/topology/importexport.js

Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: <email address hidden>
+New revision: <email address hidden>

Index: app/index.html
=== modified file 'app/index.html'
--- app/index.html 2013-05-04 20:11:20 +0000
+++ app/index.html 2013-05-06 20:31:34 +0000
@@ -83,8 +83,8 @@
                  </span>
                  <span class="nav-container">
                    <span class="nav-section">
- <i class="sprite environment_icon"></i>
- <span id="environment-name"></span>
+ <i class="sprite environment_icon"> </i>
+ <span id="environment-name" draggable="true"></span>
                      <span id="provider-type" class="provider-type"></span>
                    </span>
                  </span>

Index: app/views/topology/importexport.js
=== modified file 'app/views/topology/importexport.js'
--- app/views/topology/importexport.js 2013-05-02 20:13:10 +0000
+++ app/views/topology/importexport.js 2013-05-07 00:32:53 +0000
@@ -55,24 +55,52 @@
                notifications = topo.get('db').notifications,
                env = topo.get('env'),
                fileSources = evt._event.dataTransfer.files;
-
- Y.Array.each(fileSources, function(file) {
- var reader = new FileReader();
- reader.onload = (function(fileData) {
- return function(e) {
- // Import each into the environment
- env.importEnvironment(e.target.result);
- notifications.add({
- title: 'Imported Environment',
- message: 'Import from "' + file.name + '" successful',
- level: 'important'
- });
- };
- })(file);
- reader.readAsText(file);
- });
+ if (fileSources.length) {
+ Y.Array.each(fileSources, function(file) {
+ var reader = new FileReader();
+ reader.onload = (function(fileData) {
+ return function(e) {
+ // Import each into the environment
+ env.importEnvironment(e.target.result);
+ notifications.add({
+ title: 'Imported Environment',
+ message: 'Import from "' + file.name + '" successful',
+ level: 'important'
+ });
+ };
+ })(file);
+ reader.readAsText(file);
+ });
+ } else {
+ env.importEnvironment(evt._event.dataTransfer.getData('Text'));
+ }
            evt.preventDefault();
            evt.stopPropagation();
+ },
+
+ /**
+ * Update lifecycle phase
+ * @method update
+ */
+ update: function() {
+ if (!this._dragHandle) {
+ var env = this.get('component').get('env');
+ this._dragHandle = Y.one('#environment-name')
+ .on('dragstart', function(evt) {
+ env.exportEnvironment(function(r) {
+ var ev = evt._event;
+ ev.dataTransfer.dragEffect = 'copy';
+ var json = JSON.stringify(r.result);
+ ev.dataTransfer.setData('Text', json);
+ });
+ evt.stopPropagation();
+ }, this);
+
+ this.get('component')
+ .recordSubscription(this, this._dragHandle);
+
+ }
+ ImportExportModule.superclass.update.call(this);
          }
        }, {
          ATTRS: {}

« Back to merge proposal