Skip to content

Commit

Permalink
Metadata editor / Add thumbnail with drag and drop fails #769
Browse files Browse the repository at this point in the history
Issue was related to having same ids set for upload thumbnail and resources. Setting the url options fixed that.

Misc improvements:
* Clean duplicated ids between directives
* Add missing translation
* Restrict to one file only (to be done for the drop zone)
* Fix UFO setting wrong link for upload resources
* Clear form after upload
  • Loading branch information
François Prunayre committed Mar 3, 2015
1 parent 2849d0b commit cfc5b0b
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 78 deletions.
12 changes: 6 additions & 6 deletions schemas/iso19139/src/main/plugin/iso19139/update-fixed-info.xsl
Expand Up @@ -203,11 +203,11 @@
<gmd:linkage>
<gmd:URL>
<xsl:choose>
<xsl:when test="/root/env/config/downloadservice/simple='true'">
<xsl:value-of select="concat($serviceUrl,'/resources.get?uuid=',/root/env/uuid,'&amp;fname=',$fname,'&amp;access=private')"/>
<xsl:when test="/root/env/system/downloadservice/simple='true'">
<xsl:value-of select="concat($serviceUrl,'resources.get?uuid=',/root/env/uuid,'&amp;fname=',$fname,'&amp;access=private')"/>
</xsl:when>
<xsl:when test="/root/env/config/downloadservice/withdisclaimer='true'">
<xsl:value-of select="concat($serviceUrl,'/file.disclaimer?uuid=',/root/env/uuid,'&amp;fname=',$fname,'&amp;access=private')"/>
<xsl:when test="/root/env/system/downloadservice/withdisclaimer='true'">
<xsl:value-of select="concat($serviceUrl,'file.disclaimer?uuid=',/root/env/uuid,'&amp;fname=',$fname,'&amp;access=private')"/>
</xsl:when>
<xsl:otherwise> <!-- /root/env/config/downloadservice/leave='true' -->
<xsl:value-of select="gmd:linkage/gmd:URL"/>
Expand Down Expand Up @@ -257,10 +257,10 @@
<xsl:copy>
<xsl:attribute name="src">
<xsl:choose>
<xsl:when test="/root/env/config/downloadservice/simple='true'">
<xsl:when test="/root/env/system/downloadservice/simple='true'">
<xsl:value-of select="concat($serviceUrl,'/resources.get?uuid=',/root/env/uuid,'&amp;fname=',.,'&amp;access=private')"/>
</xsl:when>
<xsl:when test="/root/env/config/downloadservice/withdisclaimer='true'">
<xsl:when test="/root/env/system/downloadservice/withdisclaimer='true'">
<xsl:value-of select="concat($serviceUrl,'/file.disclaimer?uuid=',/root/env/uuid,'&amp;fname=',.,'&amp;access=private')"/>
</xsl:when>
<xsl:otherwise> <!-- /root/env/config/downloadservice/leave='true' -->
Expand Down
Expand Up @@ -159,8 +159,6 @@
scope.loaded = false;
scope.layers = null;
scope.gnCurrentEdit = gnCurrentEdit;

scope.processing = false;
scope.map = null;

function loadLayers() {
Expand Down Expand Up @@ -225,12 +223,22 @@
return scope.searchObj.params.version = gnCurrentEdit.version;
};

var resetForm = function () {
if (scope.params) {
scope.params.url = '';
scope.params.thumbnail_url = '';
scope.params.thumbnail_desc = '';
}
scope.clear(scope.queue);
};

/**
* Onlinesrc uploaded with success, close the popup,
* refresh the metadata form.
* Callback of the submit().
*/
var uploadOnlinesrcDone = function(evt, data) {
var uploadThumbnailDone = function(evt, data) {
resetForm();
gnEditor.refreshEditorForm();
gnOnlinesrc.reload = true;
$(scope.popupid).modal('hide');
Expand All @@ -239,14 +247,17 @@
/**
* Onlinesrc uploaded with error, broadcast it.
*/
var uploadOnlineSrcError = function(data) {
var uploadThumbnailError = function(data) {
};

// upload directive options
scope.onlinesrcUploadOptions = {
scope.thumbnailUploadOptions = {
autoUpload: false,
done: uploadOnlinesrcDone,
fail: uploadOnlineSrcError
url: 'md.thumbnail.upload',
//maxNumberOfFiles: 1,
//acceptFileTypes: /(\.|\/)(gif|jpe?g|png|tif?f)$/i,
done: uploadThumbnailDone,
fail: uploadThumbnailError
};

/**
Expand All @@ -257,14 +268,13 @@
scope.addThumbnail = function() {
if (scope.mode == 'upload') {
getVersion();
gnEditor.save(false, true)
return gnEditor.save(false, true)
.then(function(data) {
scope.submit();
});
} else if (scope.mode == 'thumbnailMaker') {
getVersion();
scope.processing = true;
gnEditor.save(false, true)
return gnEditor.save(false, true)
.then(function(data) {
scope.action =
'md.thumbnail.generate?_content_type=json&';
Expand All @@ -273,7 +283,7 @@
headers: {'Content-Type':
'application/x-www-form-urlencoded'}
}).success(function(data) {
uploadOnlinesrcDone();
uploadThumbnailDone();
scope.processing = false;
}).error(function(data, status, headers, config) {
$rootScope.$broadcast('StatusUpdated', {
Expand All @@ -286,12 +296,13 @@
},
timeout: 0,
type: 'danger'});
scope.processing = false;
});
});
} else {
gnOnlinesrc.addThumbnailByURL(scope.params,
scope.popupid);
return gnOnlinesrc.addThumbnailByURL(scope.params,
scope.popupid).then(function () {
resetForm();
});
}
};

Expand Down Expand Up @@ -358,12 +369,22 @@

scope.onlinesrcService = gnOnlinesrc;

var resetForm = function () {
if (scope.params) {
scope.params.desc = '';
scope.params.url = '';
scope.params.name = '';
scope.params.protocol = '';
}
scope.clear(scope.queue);
};

/**
* Onlinesrc uploaded with success, close the popup,
* refresh the metadata.
*/
var uploadOnlinesrcDone = function(data) {
scope.clear(scope.queue);
resetForm();
gnEditor.refreshEditorForm();
gnOnlinesrc.reload = true;
$(scope.popupid).modal('hide');
Expand All @@ -377,7 +398,8 @@

scope.onlinesrcUploadOptions = {
autoUpload: false,
// TODO: acceptFileTypes: /(\.|\/)(xml|skos|rdf)$/i,
url: 'resource.upload.and.link',
// TODO: acceptFileTypes: /(\.|\/)(xml|skos|rdf)$/i,
done: uploadOnlinesrcDone,
fail: uploadOnlineSrcError
};
Expand All @@ -389,9 +411,12 @@
*/
scope.addOnlinesrc = function() {
if (scope.mode == 'upload') {
scope.submit();
return scope.submit();
} else {
gnOnlinesrc.addOnlinesrc(scope.params, scope.popupid);
return gnOnlinesrc.addOnlinesrc(scope.params, scope.popupid).
then(function() {
resetForm();
});
}
};

Expand Down
Expand Up @@ -254,7 +254,7 @@
* @param {string} popupid id of the popup to close after process.
*/
addOnlinesrc: function(params, popupid) {
runProcess(this,
return runProcess(this,
setParams('onlinesrc-add', params)).then(function() {
closePopup(popupid);
});
Expand All @@ -274,7 +274,7 @@
* @param {string} popupid id of the popup to close after process.
*/
addThumbnailByURL: function(params, popupid) {
runProcess(this,
return runProcess(this,
setParams('thumbnail-add', params)).then(function() {
closePopup(popupid);
});
Expand Down Expand Up @@ -332,14 +332,6 @@
}
},

/**
* Open onlinesrc url into a new window
* On onlinesrc list click.
*/
openLink: function(url) {
window.open(url, '_blank');
},

/**
* @ngdoc method
* @name gnOnlinesrc#linkToService
Expand Down
@@ -1,8 +1,9 @@
<div>
<form id="gn-upload-onlinesrc" class="form-horizontal" role="form"
method="POST" enctype="multipart/form-data" action="resource.upload.and.link"
method="POST" enctype="multipart/form-data"
action="resource.upload.and.link"
data-file-upload="onlinesrcUploadOptions">

<div class="onlinesrc-container">
<div class="form-group" >
<div class="btn-group col-sm-offset-2 col-sm-10">
Expand Down Expand Up @@ -38,33 +39,40 @@
<div class="panel panel-default">
<div class="panel-body">

<span
class="btn btn-success btn-block fileinput-button" ng-class="{disabled: disabled}">
<i class="fa fa-plus fa fa-white"/>
<span data-translate="">chooseOnlinesrc</span>
<input type="file" id="gn-onlinesrc-file" name="filename" multiple="false"
data-ng-disabled="disabled"/>
</span>

<ul>
<li data-ng-repeat="file in queue">{{file.name}} ({{file.type}} / {{file.size | formatFileSize}}) <i
class="fa fa-trash-o" data-ng-click="clear(file)"/>
</li>
</ul>
<span
class="btn btn-success btn-block fileinput-button"
data-ng-class="{disabled: disabled}">
<i class="fa fa-plus fa fa-white"/>
<span data-translate="">chooseOnlinesrc</span>
<input type="file" id="gn-onlinesrc-file"
name="filename"
data-ng-disabled="disabled"/>
</span>

<ul>
<li data-ng-repeat="file in queue">
{{file.name}} ({{file.type}} / {{file.size | formatFileSize}})
<i class="fa fa-trash-o" data-ng-click="clear(file)"/>
</li>
</ul>
<div class="checkbox">
<label>overwrite <input type="checkbox" name="overwrite">
<label>
<span data-translate="">overwriteFile</span>
<input type="checkbox" name="overwrite">
</label>
</div>
<input name="process" value="onlinesrc-add" data-ng-hide="true"/>
<input name="id" data-ng-model="metadataId" data-ng-hide="true"/>
<input name="id" data-ng-model="metadataId" data-ng-hide="true"/>
</div>
</div>
</div>
</div>

<!-- Name text Field -->
<div class="form-group" data-ng-show="mode == 'url' && schema !== 'dublin-core'">
<label for="onlinesrcName" class="col-sm-2 control-label">Name</label>
<label for="onlinesrcName"
class="col-sm-2 control-label"
data-translate="">onlineResourceName</label>
<div class="col-sm-10">
<input ng-model="params.name" name="name" class="" type="text"
id="onlinesrcName" placeholder="Name">
Expand All @@ -74,7 +82,7 @@
<!-- Protocol Combo -->
<div class="form-group" data-ng-show="mode == 'url' && schema !== 'dublin-core'">
<label class="col-sm-2 control-label">
<span data-translate="">Protocol</span>
<span data-translate="">protocol</span>
</label>
<div class="col-sm-10">
<div data-schema-info-combo="element"
Expand All @@ -85,7 +93,8 @@

<!-- Description Text area -->
<div class="form-group" data-ng-hide="schema === 'dublin-core'">
<label for="onlinesrcDescr" class="col-sm-2 control-label">Description</label>
<label for="onlinesrcDescr" class="col-sm-2 control-label"
data-translate="">Description</label>
<div class="col-sm-10">
<textarea rows="3" data-ng-model="params.desc"
class="form-control input-sm" id="onlinesrcDescr"
Expand All @@ -109,8 +118,9 @@
</div>
</form>
<div class="">
<button type="button" class="btn navbar-btn btn-success"
data-ng-click="addOnlinesrc()">
<button type="button"
class="btn navbar-btn btn-success"
data-ng-click="addOnlinesrc()">
<i class="fa fa-archive" />
<i class="icon-external-link"></i>&nbsp;
<span data-translate="">addOnlinesrc</span>
Expand Down

0 comments on commit cfc5b0b

Please sign in to comment.