dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #40311
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20421: WIP data entry file uploads implementation. Missing i18n as well as various small fixes
------------------------------------------------------------
revno: 20421
committer: Halvdan Hoem Grelland <halvdanhg@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-09-30 20:50:42 +0200
message:
WIP data entry file uploads implementation. Missing i18n as well as various small fixes
added:
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/filesize.min.js
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/jQuery/jquery.fileupload.min.js
modified:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataValueController.java
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/cacheManifest.vm
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.vm
dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js
dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js
dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/sectionForm.vm
dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/style/dhis-web-dataentry.css
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataValueController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataValueController.java 2015-09-23 11:34:44 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataValueController.java 2015-09-30 18:50:42 +0000
@@ -206,29 +206,6 @@
validateDataSetNotLocked( dataElement, period, organisationUnit );
// ---------------------------------------------------------------------
- // Deal with file resource
- // ---------------------------------------------------------------------
-
- FileResource fileResource = null;
-
- if ( dataElement.getValueType() == ValueType.FILE_RESOURCE )
- {
- fileResource = fileResourceService.getFileResource( value );
-
- if ( fileResource == null || fileResource.getDomain() != FileResourceDomain.DATA_VALUE )
- {
- throw new WebMessageException( WebMessageUtils.notFound( FileResource.class, value ) );
- }
-
- if ( fileResource.isAssigned() )
- {
- throw new WebMessageException( WebMessageUtils.conflict( "File resource is already assigned or is linked to another data value" ) );
- }
-
- fileResource.setAssigned( true );
- }
-
- // ---------------------------------------------------------------------
// Assemble and save data value
// ---------------------------------------------------------------------
@@ -238,8 +215,38 @@
DataValue dataValue = dataValueService.getDataValue( dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo );
+ FileResource fileResource = null;
+
if ( dataValue == null )
{
+ // ---------------------------------------------------------------------
+ // Deal with file resource
+ // ---------------------------------------------------------------------
+
+ if ( dataElement.getValueType() == ValueType.FILE_RESOURCE )
+ {
+ if ( value != null )
+ {
+ fileResource = fileResourceService.getFileResource( value );
+
+ if ( fileResource == null || fileResource.getDomain() != FileResourceDomain.DATA_VALUE )
+ {
+ throw new WebMessageException( WebMessageUtils.notFound( FileResource.class, value ) );
+ }
+
+ if ( fileResource.isAssigned() )
+ {
+ throw new WebMessageException( WebMessageUtils.conflict( "File resource is already assigned or is linked to another data value" ) );
+ }
+
+ fileResource.setAssigned( true );
+ }
+ else
+ {
+ throw new WebMessageException( WebMessageUtils.conflict( "Missing parameter 'value'" ) );
+ }
+ }
+
dataValue = new DataValue( dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo,
StringUtils.trimToNull( value ), storedBy, now, StringUtils.trimToNull( comment ) );
@@ -260,16 +267,13 @@
}
}
- if ( value != null )
+ if ( dataElement.isFileType() )
{
- if ( dataElement.isFileType() )
- {
- fileResourceService.deleteFileResource( dataValue.getValue() );
- }
-
- dataValue.setValue( StringUtils.trimToNull( value ) );
+ fileResourceService.deleteFileResource( dataValue.getValue() );
}
+ dataValue.setValue( StringUtils.trimToNull( value ) );
+
if ( comment != null )
{
dataValue.setComment( StringUtils.trimToNull( comment ) );
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/cacheManifest.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/cacheManifest.vm 2015-01-23 14:07:46 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/cacheManifest.vm 2015-09-30 18:50:42 +0000
@@ -28,6 +28,7 @@
javascripts/jQuery/jquery.utils.js?_rev=$!{buildRevision}
javascripts/jQuery/jquery.metadata.js?_rev=$!{buildRevision}
javascripts/jQuery/jquery.glob.js?_rev=$!{buildRevision}
+javascripts/jQuery/jquery.fileupload.min.js?rev=$!{buildRevision}
javascripts/jQuery/jquery.date.js?_rev=$!{buildRevision}
javascripts/jQuery/jquery.tmpl.js?_rev=$!{buildRevision}
i18nJavaScript.action?_rev=$!{buildRevision}
@@ -35,6 +36,7 @@
javascripts/lists.js?_rev=$!{buildRevision}
javascripts/periodType.js?_rev=$!{buildRevision}
javascripts/date.js?_rev=$!{buildRevision}
+javascripts/filesize.min.js?_rev=$!{buildRevision}
javascripts/dhis2/dhis2.util.js?_rev=$!{buildRevision}
javascripts/dhis2/dhis2.array.js?_rev=$!{buildRevision}
javascripts/dhis2/dhis2.select.js?_rev=$!{buildRevision}
=== added file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/filesize.min.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/filesize.min.js 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/filesize.min.js 2015-09-30 18:50:42 +0000
@@ -0,0 +1,6 @@
+/*
+ 2015 Jason Mulligan
+ @version 3.1.2
+ */
+"use strict";!function(a){var b=/b$/,c={bits:["B","kb","Mb","Gb","Tb","Pb","Eb","Zb","Yb"],bytes:["B","kB","MB","GB","TB","PB","EB","ZB","YB"]},d=function(a){var d=void 0===arguments[1]?{}:arguments[1],e=[],f=!1,g=0,h=void 0,i=void 0,j=void 0,k=void 0,l=void 0,m=void 0,n=void 0,o=void 0,p=void 0,q=void 0,r=void 0;if(isNaN(a))throw new Error("Invalid arguments");return j=d.bits===!0,p=d.unix===!0,i=void 0!==d.base?d.base:2,o=void 0!==d.round?d.round:p?1:2,q=void 0!==d.spacer?d.spacer:p?"":" ",r=void 0!==d.suffixes?d.suffixes:{},n=void 0!==d.output?d.output:"string",h=void 0!==d.exponent?d.exponent:-1,m=Number(a),l=0>m,k=i>2?1e3:1024,l&&(m=-m),0===m?(e[0]=0,e[1]=p?"":"B"):((-1===h||isNaN(h))&&(h=Math.floor(Math.log(m)/Math.log(k))),h>8&&(g=1e3*g*(h-8),h=8),g=2===i?m/Math.pow(2,10*h):m/Math.pow(1e3,h),j&&(g=8*g,g>k&&(g/=k,h++)),e[0]=Number(g.toFixed(h>0?o:0)),e[1]=c[j?"bits":"bytes"][h],!f&&p&&(j&&b.test(e[1])&&(e[1]=e[1].toLowerCase()),e[1]=e[1].charAt(0),"B"===e[1]?(e[0]=Math.floor(e[0]),e[1]=""):j||"k"!==e[1]||(e[1]="K"))),l&&(e[0]=-e[0]),e[1]=r[e[1]]||e[1],"array"===n?e:"exponent"===n?h:"object"===n?{value:e[0],suffix:e[1]}:e.join(q)};"undefined"!=typeof exports?module.exports=d:"function"==typeof define?define(function(){return d}):a.filesize=d}("undefined"!=typeof global?global:window);
+//# sourceMappingURL=filesize.min.js.map
\ No newline at end of file
=== added file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/jQuery/jquery.fileupload.min.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/jQuery/jquery.fileupload.min.js 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/jQuery/jquery.fileupload.min.js 2015-09-30 18:50:42 +0000
@@ -0,0 +1,1 @@
+!function(a){"use strict";"function"==typeof define&&define.amd?define(["jquery","jquery.ui.widget"],a):"object"==typeof exports?a(require("jquery"),require("./vendor/jquery.ui.widget")):a(window.jQuery)}(function(a){"use strict";function b(b){var c="dragover"===b;return function(d){d.dataTransfer=d.originalEvent&&d.originalEvent.dataTransfer;var e=d.dataTransfer;e&&-1!==a.inArray("Files",e.types)&&this._trigger(b,a.Event(b,{delegatedEvent:d}))!==!1&&(d.preventDefault(),c&&(e.dropEffect="copy"))}}a.support.fileInput=!(new RegExp("(Android (1\\.[0156]|2\\.[01]))|(Windows Phone (OS 7|8\\.0))|(XBLWP)|(ZuneWP)|(WPDesktop)|(w(eb)?OSBrowser)|(webOS)|(Kindle/(1\\.0|2\\.[05]|3\\.0))").test(window.navigator.userAgent)||a('<input type="file">').prop("disabled")),a.support.xhrFileUpload=!(!window.ProgressEvent||!window.FileReader),a.support.xhrFormDataFileUpload=!!window.FormData,a.support.blobSlice=window.Blob&&(Blob.prototype.slice||Blob.prototype.webkitSlice||Blob.prototype.mozSlice),a.widget("blueimp.fileupload",{options:{dropZone:a(document),pasteZone:void 0,fileInput:void 0,replaceFileInput:!0,paramName:void 0,singleFileUploads:!0,limitMultiFileUploads:void 0,limitMultiFileUploadSize:void 0,limitMultiFileUploadSizeOverhead:512,sequentialUploads:!1,limitConcurrentUploads:void 0,forceIframeTransport:!1,redirect:void 0,redirectParamName:void 0,postMessage:void 0,multipart:!0,maxChunkSize:void 0,uploadedBytes:void 0,recalculateProgress:!0,progressInterval:100,bitrateInterval:500,autoUpload:!0,messages:{uploadedBytes:"Uploaded bytes exceed file size"},i18n:function(b,c){return b=this.messages[b]||b.toString(),c&&a.each(c,function(a,c){b=b.replace("{"+a+"}",c)}),b},formData:function(a){return a.serializeArray()},add:function(b,c){return b.isDefaultPrevented()?!1:void((c.autoUpload||c.autoUpload!==!1&&a(this).fileupload("option","autoUpload"))&&c.process().done(function(){c.submit()}))},processData:!1,contentType:!1,cache:!1,timeout:0},_specialOptions:["fileInput","dropZone","pasteZone","multipart","forceIframeTransport"],_blobSlice:a.support.blobSlice&&function(){var a=this.slice||this.webkitSlice||this.mozSlice;return a.apply(this,arguments)},_BitrateTimer:function(){this.timestamp=Date.now?Date.now():(new Date).getTime(),this.loaded=0,this.bitrate=0,this.getBitrate=function(a,b,c){var d=a-this.timestamp;return(!this.bitrate||!c||d>c)&&(this.bitrate=(b-this.loaded)*(1e3/d)*8,this.loaded=b,this.timestamp=a),this.bitrate}},_isXHRUpload:function(b){return!b.forceIframeTransport&&(!b.multipart&&a.support.xhrFileUpload||a.support.xhrFormDataFileUpload)},_getFormData:function(b){var c;return"function"===a.type(b.formData)?b.formData(b.form):a.isArray(b.formData)?b.formData:"object"===a.type(b.formData)?(c=[],a.each(b.formData,function(a,b){c.push({name:a,value:b})}),c):[]},_getTotal:function(b){var c=0;return a.each(b,function(a,b){c+=b.size||1}),c},_initProgressObject:function(b){var c={loaded:0,total:0,bitrate:0};b._progress?a.extend(b._progress,c):b._progress=c},_initResponseObject:function(a){var b;if(a._response)for(b in a._response)a._response.hasOwnProperty(b)&&delete a._response[b];else a._response={}},_onProgress:function(b,c){if(b.lengthComputable){var d,e=Date.now?Date.now():(new Date).getTime();if(c._time&&c.progressInterval&&e-c._time<c.progressInterval&&b.loaded!==b.total)return;c._time=e,d=Math.floor(b.loaded/b.total*(c.chunkSize||c._progress.total))+(c.uploadedBytes||0),this._progress.loaded+=d-c._progress.loaded,this._progress.bitrate=this._bitrateTimer.getBitrate(e,this._progress.loaded,c.bitrateInterval),c._progress.loaded=c.loaded=d,c._progress.bitrate=c.bitrate=c._bitrateTimer.getBitrate(e,d,c.bitrateInterval),this._trigger("progress",a.Event("progress",{delegatedEvent:b}),c),this._trigger("progressall",a.Event("progressall",{delegatedEvent:b}),this._progress)}},_initProgressListener:function(b){var c=this,d=b.xhr?b.xhr():a.ajaxSettings.xhr();d.upload&&(a(d.upload).bind("progress",function(a){var d=a.originalEvent;a.lengthComputable=d.lengthComputable,a.loaded=d.loaded,a.total=d.total,c._onProgress(a,b)}),b.xhr=function(){return d})},_isInstanceOf:function(a,b){return Object.prototype.toString.call(b)==="[object "+a+"]"},_initXHRData:function(b){var c,d=this,e=b.files[0],f=b.multipart||!a.support.xhrFileUpload,g="array"===a.type(b.paramName)?b.paramName[0]:b.paramName;b.headers=a.extend({},b.headers),b.contentRange&&(b.headers["Content-Range"]=b.contentRange),f&&!b.blob&&this._isInstanceOf("File",e)||(b.headers["Content-Disposition"]='attachment; filename="'+encodeURI(e.name)+'"'),f?a.support.xhrFormDataFileUpload&&(b.postMessage?(c=this._getFormData(b),b.blob?c.push({name:g,value:b.blob}):a.each(b.files,function(d,e){c.push({name:"array"===a.type(b.paramName)&&b.paramName[d]||g,value:e})})):(d._isInstanceOf("FormData",b.formData)?c=b.formData:(c=new FormData,a.each(this._getFormData(b),function(a,b){c.append(b.name,b.value)})),b.blob?c.append(g,b.blob,e.name):a.each(b.files,function(e,f){(d._isInstanceOf("File",f)||d._isInstanceOf("Blob",f))&&c.append("array"===a.type(b.paramName)&&b.paramName[e]||g,f,f.uploadName||f.name)})),b.data=c):(b.contentType=e.type||"application/octet-stream",b.data=b.blob||e),b.blob=null},_initIframeSettings:function(b){var c=a("<a></a>").prop("href",b.url).prop("host");b.dataType="iframe "+(b.dataType||""),b.formData=this._getFormData(b),b.redirect&&c&&c!==location.host&&b.formData.push({name:b.redirectParamName||"redirect",value:b.redirect})},_initDataSettings:function(a){this._isXHRUpload(a)?(this._chunkedUpload(a,!0)||(a.data||this._initXHRData(a),this._initProgressListener(a)),a.postMessage&&(a.dataType="postmessage "+(a.dataType||""))):this._initIframeSettings(a)},_getParamName:function(b){var c=a(b.fileInput),d=b.paramName;return d?a.isArray(d)||(d=[d]):(d=[],c.each(function(){for(var b=a(this),c=b.prop("name")||"files[]",e=(b.prop("files")||[1]).length;e;)d.push(c),e-=1}),d.length||(d=[c.prop("name")||"files[]"])),d},_initFormSettings:function(b){b.form&&b.form.length||(b.form=a(b.fileInput.prop("form")),b.form.length||(b.form=a(this.options.fileInput.prop("form")))),b.paramName=this._getParamName(b),b.url||(b.url=b.form.prop("action")||location.href),b.type=(b.type||"string"===a.type(b.form.prop("method"))&&b.form.prop("method")||"").toUpperCase(),"POST"!==b.type&&"PUT"!==b.type&&"PATCH"!==b.type&&(b.type="POST"),b.formAcceptCharset||(b.formAcceptCharset=b.form.attr("accept-charset"))},_getAJAXSettings:function(b){var c=a.extend({},this.options,b);return this._initFormSettings(c),this._initDataSettings(c),c},_getDeferredState:function(a){return a.state?a.state():a.isResolved()?"resolved":a.isRejected()?"rejected":"pending"},_enhancePromise:function(a){return a.success=a.done,a.error=a.fail,a.complete=a.always,a},_getXHRPromise:function(b,c,d){var e=a.Deferred(),f=e.promise();return c=c||this.options.context||f,b===!0?e.resolveWith(c,d):b===!1&&e.rejectWith(c,d),f.abort=e.promise,this._enhancePromise(f)},_addConvenienceMethods:function(b,c){var d=this,e=function(b){return a.Deferred().resolveWith(d,b).promise()};c.process=function(b,f){return(b||f)&&(c._processQueue=this._processQueue=(this._processQueue||e([this])).pipe(function(){return c.errorThrown?a.Deferred().rejectWith(d,[c]).promise():e(arguments)}).pipe(b,f)),this._processQueue||e([this])},c.submit=function(){return"pending"!==this.state()&&(c.jqXHR=this.jqXHR=d._trigger("submit",a.Event("submit",{delegatedEvent:b}),this)!==!1&&d._onSend(b,this)),this.jqXHR||d._getXHRPromise()},c.abort=function(){return this.jqXHR?this.jqXHR.abort():(this.errorThrown="abort",d._trigger("fail",null,this),d._getXHRPromise(!1))},c.state=function(){return this.jqXHR?d._getDeferredState(this.jqXHR):this._processQueue?d._getDeferredState(this._processQueue):void 0},c.processing=function(){return!this.jqXHR&&this._processQueue&&"pending"===d._getDeferredState(this._processQueue)},c.progress=function(){return this._progress},c.response=function(){return this._response}},_getUploadedBytes:function(a){var b=a.getResponseHeader("Range"),c=b&&b.split("-"),d=c&&c.length>1&&parseInt(c[1],10);return d&&d+1},_chunkedUpload:function(b,c){b.uploadedBytes=b.uploadedBytes||0;var d,e,f=this,g=b.files[0],h=g.size,i=b.uploadedBytes,j=b.maxChunkSize||h,k=this._blobSlice,l=a.Deferred(),m=l.promise();return this._isXHRUpload(b)&&k&&(i||h>j)&&!b.data?c?!0:i>=h?(g.error=b.i18n("uploadedBytes"),this._getXHRPromise(!1,b.context,[null,"error",g.error])):(e=function(){var c=a.extend({},b),m=c._progress.loaded;c.blob=k.call(g,i,i+j,g.type),c.chunkSize=c.blob.size,c.contentRange="bytes "+i+"-"+(i+c.chunkSize-1)+"/"+h,f._initXHRData(c),f._initProgressListener(c),d=(f._trigger("chunksend",null,c)!==!1&&a.ajax(c)||f._getXHRPromise(!1,c.context)).done(function(d,g,j){i=f._getUploadedBytes(j)||i+c.chunkSize,m+c.chunkSize-c._progress.loaded&&f._onProgress(a.Event("progress",{lengthComputable:!0,loaded:i-c.uploadedBytes,total:i-c.uploadedBytes}),c),b.uploadedBytes=c.uploadedBytes=i,c.result=d,c.textStatus=g,c.jqXHR=j,f._trigger("chunkdone",null,c),f._trigger("chunkalways",null,c),h>i?e():l.resolveWith(c.context,[d,g,j])}).fail(function(a,b,d){c.jqXHR=a,c.textStatus=b,c.errorThrown=d,f._trigger("chunkfail",null,c),f._trigger("chunkalways",null,c),l.rejectWith(c.context,[a,b,d])})},this._enhancePromise(m),m.abort=function(){return d.abort()},e(),m):!1},_beforeSend:function(a,b){0===this._active&&(this._trigger("start"),this._bitrateTimer=new this._BitrateTimer,this._progress.loaded=this._progress.total=0,this._progress.bitrate=0),this._initResponseObject(b),this._initProgressObject(b),b._progress.loaded=b.loaded=b.uploadedBytes||0,b._progress.total=b.total=this._getTotal(b.files)||1,b._progress.bitrate=b.bitrate=0,this._active+=1,this._progress.loaded+=b.loaded,this._progress.total+=b.total},_onDone:function(b,c,d,e){var f=e._progress.total,g=e._response;e._progress.loaded<f&&this._onProgress(a.Event("progress",{lengthComputable:!0,loaded:f,total:f}),e),g.result=e.result=b,g.textStatus=e.textStatus=c,g.jqXHR=e.jqXHR=d,this._trigger("done",null,e)},_onFail:function(a,b,c,d){var e=d._response;d.recalculateProgress&&(this._progress.loaded-=d._progress.loaded,this._progress.total-=d._progress.total),e.jqXHR=d.jqXHR=a,e.textStatus=d.textStatus=b,e.errorThrown=d.errorThrown=c,this._trigger("fail",null,d)},_onAlways:function(a,b,c,d){this._trigger("always",null,d)},_onSend:function(b,c){c.submit||this._addConvenienceMethods(b,c);var d,e,f,g,h=this,i=h._getAJAXSettings(c),j=function(){return h._sending+=1,i._bitrateTimer=new h._BitrateTimer,d=d||((e||h._trigger("send",a.Event("send",{delegatedEvent:b}),i)===!1)&&h._getXHRPromise(!1,i.context,e)||h._chunkedUpload(i)||a.ajax(i)).done(function(a,b,c){h._onDone(a,b,c,i)}).fail(function(a,b,c){h._onFail(a,b,c,i)}).always(function(a,b,c){if(h._onAlways(a,b,c,i),h._sending-=1,h._active-=1,i.limitConcurrentUploads&&i.limitConcurrentUploads>h._sending)for(var d=h._slots.shift();d;){if("pending"===h._getDeferredState(d)){d.resolve();break}d=h._slots.shift()}0===h._active&&h._trigger("stop")})};return this._beforeSend(b,i),this.options.sequentialUploads||this.options.limitConcurrentUploads&&this.options.limitConcurrentUploads<=this._sending?(this.options.limitConcurrentUploads>1?(f=a.Deferred(),this._slots.push(f),g=f.pipe(j)):(this._sequence=this._sequence.pipe(j,j),g=this._sequence),g.abort=function(){return e=[void 0,"abort","abort"],d?d.abort():(f&&f.rejectWith(i.context,e),j())},this._enhancePromise(g)):j()},_onAdd:function(b,c){var d,e,f,g,h=this,i=!0,j=a.extend({},this.options,c),k=c.files,l=k.length,m=j.limitMultiFileUploads,n=j.limitMultiFileUploadSize,o=j.limitMultiFileUploadSizeOverhead,p=0,q=this._getParamName(j),r=0;if(!l)return!1;if(n&&void 0===k[0].size&&(n=void 0),(j.singleFileUploads||m||n)&&this._isXHRUpload(j))if(j.singleFileUploads||n||!m)if(!j.singleFileUploads&&n)for(f=[],d=[],g=0;l>g;g+=1)p+=k[g].size+o,(g+1===l||p+k[g+1].size+o>n||m&&g+1-r>=m)&&(f.push(k.slice(r,g+1)),e=q.slice(r,g+1),e.length||(e=q),d.push(e),r=g+1,p=0);else d=q;else for(f=[],d=[],g=0;l>g;g+=m)f.push(k.slice(g,g+m)),e=q.slice(g,g+m),e.length||(e=q),d.push(e);else f=[k],d=[q];return c.originalFiles=k,a.each(f||k,function(e,g){var j=a.extend({},c);return j.files=f?g:[g],j.paramName=d[e],h._initResponseObject(j),h._initProgressObject(j),h._addConvenienceMethods(b,j),i=h._trigger("add",a.Event("add",{delegatedEvent:b}),j)}),i},_replaceFileInput:function(b){var c=b.fileInput,d=c.clone(!0),e=c.is(document.activeElement);b.fileInputClone=d,a("<form></form>").append(d)[0].reset(),c.after(d).detach(),e&&d.focus(),a.cleanData(c.unbind("remove")),this.options.fileInput=this.options.fileInput.map(function(a,b){return b===c[0]?d[0]:b}),c[0]===this.element[0]&&(this.element=d)},_handleFileTreeEntry:function(b,c){var d,e=this,f=a.Deferred(),g=function(a){a&&!a.entry&&(a.entry=b),f.resolve([a])},h=function(a){e._handleFileTreeEntries(a,c+b.name+"/").done(function(a){f.resolve(a)}).fail(g)},i=function(){d.readEntries(function(a){a.length?(j=j.concat(a),i()):h(j)},g)},j=[];return c=c||"",b.isFile?b._file?(b._file.relativePath=c,f.resolve(b._file)):b.file(function(a){a.relativePath=c,f.resolve(a)},g):b.isDirectory?(d=b.createReader(),i()):f.resolve([]),f.promise()},_handleFileTreeEntries:function(b,c){var d=this;return a.when.apply(a,a.map(b,function(a){return d._handleFileTreeEntry(a,c)})).pipe(function(){return Array.prototype.concat.apply([],arguments)})},_getDroppedFiles:function(b){b=b||{};var c=b.items;return c&&c.length&&(c[0].webkitGetAsEntry||c[0].getAsEntry)?this._handleFileTreeEntries(a.map(c,function(a){var b;return a.webkitGetAsEntry?(b=a.webkitGetAsEntry(),b&&(b._file=a.getAsFile()),b):a.getAsEntry()})):a.Deferred().resolve(a.makeArray(b.files)).promise()},_getSingleFileInputFiles:function(b){b=a(b);var c,d,e=b.prop("webkitEntries")||b.prop("entries");if(e&&e.length)return this._handleFileTreeEntries(e);if(c=a.makeArray(b.prop("files")),c.length)void 0===c[0].name&&c[0].fileName&&a.each(c,function(a,b){b.name=b.fileName,b.size=b.fileSize});else{if(d=b.prop("value"),!d)return a.Deferred().resolve([]).promise();c=[{name:d.replace(/^.*\\/,"")}]}return a.Deferred().resolve(c).promise()},_getFileInputFiles:function(b){return b instanceof a&&1!==b.length?a.when.apply(a,a.map(b,this._getSingleFileInputFiles)).pipe(function(){return Array.prototype.concat.apply([],arguments)}):this._getSingleFileInputFiles(b)},_onChange:function(b){var c=this,d={fileInput:a(b.target),form:a(b.target.form)};this._getFileInputFiles(d.fileInput).always(function(e){d.files=e,c.options.replaceFileInput&&c._replaceFileInput(d),c._trigger("change",a.Event("change",{delegatedEvent:b}),d)!==!1&&c._onAdd(b,d)})},_onPaste:function(b){var c=b.originalEvent&&b.originalEvent.clipboardData&&b.originalEvent.clipboardData.items,d={files:[]};c&&c.length&&(a.each(c,function(a,b){var c=b.getAsFile&&b.getAsFile();c&&d.files.push(c)}),this._trigger("paste",a.Event("paste",{delegatedEvent:b}),d)!==!1&&this._onAdd(b,d))},_onDrop:function(b){b.dataTransfer=b.originalEvent&&b.originalEvent.dataTransfer;var c=this,d=b.dataTransfer,e={};d&&d.files&&d.files.length&&(b.preventDefault(),this._getDroppedFiles(d).always(function(d){e.files=d,c._trigger("drop",a.Event("drop",{delegatedEvent:b}),e)!==!1&&c._onAdd(b,e)}))},_onDragOver:b("dragover"),_onDragEnter:b("dragenter"),_onDragLeave:b("dragleave"),_initEventHandlers:function(){this._isXHRUpload(this.options)&&(this._on(this.options.dropZone,{dragover:this._onDragOver,drop:this._onDrop,dragenter:this._onDragEnter,dragleave:this._onDragLeave}),this._on(this.options.pasteZone,{paste:this._onPaste})),a.support.fileInput&&this._on(this.options.fileInput,{change:this._onChange})},_destroyEventHandlers:function(){this._off(this.options.dropZone,"dragenter dragleave dragover drop"),this._off(this.options.pasteZone,"paste"),this._off(this.options.fileInput,"change")},_setOption:function(b,c){var d=-1!==a.inArray(b,this._specialOptions);d&&this._destroyEventHandlers(),this._super(b,c),d&&(this._initSpecialOptions(),this._initEventHandlers())},_initSpecialOptions:function(){var b=this.options;void 0===b.fileInput?b.fileInput=this.element.is('input[type="file"]')?this.element:this.element.find('input[type="file"]'):b.fileInput instanceof a||(b.fileInput=a(b.fileInput)),b.dropZone instanceof a||(b.dropZone=a(b.dropZone)),b.pasteZone instanceof a||(b.pasteZone=a(b.pasteZone))},_getRegExp:function(a){var b=a.split("/"),c=b.pop();return b.shift(),new RegExp(b.join("/"),c)},_isRegExpOption:function(b,c){return"url"!==b&&"string"===a.type(c)&&/^\/.*\/[igm]{0,3}$/.test(c)},_initDataAttributes:function(){var b=this,c=this.options,d=this.element.data();a.each(this.element[0].attributes,function(a,e){var f,g=e.name.toLowerCase();/^data-/.test(g)&&(g=g.slice(5).replace(/-[a-z]/g,function(a){return a.charAt(1).toUpperCase()}),f=d[g],b._isRegExpOption(g,f)&&(f=b._getRegExp(f)),c[g]=f)})},_create:function(){this._initDataAttributes(),this._initSpecialOptions(),this._slots=[],this._sequence=this._getXHRPromise(!0),this._sending=this._active=0,this._initProgressObject(this),this._initEventHandlers()},active:function(){return this._active},progress:function(){return this._progress},add:function(b){var c=this;b&&!this.options.disabled&&(b.fileInput&&!b.files?this._getFileInputFiles(b.fileInput).always(function(a){b.files=a,c._onAdd(null,b)}):(b.files=a.makeArray(b.files),this._onAdd(null,b)))},send:function(b){if(b&&!this.options.disabled){if(b.fileInput&&!b.files){var c,d,e=this,f=a.Deferred(),g=f.promise();return g.abort=function(){return d=!0,c?c.abort():(f.reject(null,"abort","abort"),g)},this._getFileInputFiles(b.fileInput).always(function(a){if(!d){if(!a.length)return void f.reject();b.files=a,c=e._onSend(null,b),c.then(function(a,b,c){f.resolve(a,b,c)},function(a,b,c){f.reject(a,b,c)})}}),this._enhancePromise(g)}if(b.files=a.makeArray(b.files),b.files.length)return this._onSend(null,b)}return this._getXHRPromise(!1,b&&b.context)}})});
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.vm 2015-06-02 09:55:21 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.vm 2015-09-30 18:50:42 +0000
@@ -47,7 +47,9 @@
<script type="text/javascript" src="../dhis-web-commons/javascripts/jQuery/jquery.date.js?_rev=$!{buildRevision}"></script>
<script type="text/javascript" src="../dhis-web-commons/javascripts/jQuery/jquery.tmpl.js?_rev=$!{buildRevision}"></script>
<script type="text/javascript" src="../dhis-web-commons/javascripts/jQuery/jquery.autogrow.js?_rev=$!{buildRevision}"></script>
+ <script type="text/javascript" src="../dhis-web-commons/javascripts/jQuery/jquery.fileupload.min.js?_rev=$!{buildRevision}"></script>
<script type="text/javascript" src="../dhis-web-commons/javascripts/underscore.min.js?_rev=$!{buildRevision}"></script>
+ <script type="text/javascript" src="../dhis-web-commons/javascripts/filesize.min.js?_rev=$!{buildRevision}"></script>
<script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.util.js?_rev=$!{buildRevision}"></script>
<script type="text/javascript" src="../dhis-web-commons/javascripts/commons.js?_rev=$!{buildRevision}"></script>
<script type="text/javascript" src="../dhis-web-commons/javascripts/commons.ajax.js?_rev=$!{buildRevision}"></script>
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js 2015-09-14 12:58:16 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js 2015-09-30 18:50:42 +0000
@@ -292,6 +292,16 @@
valueSaver.save();
}
+function saveFileResource( dataElementId, optionComboId, fieldId, fileResource )
+{
+ fieldId = '#' + fieldId;
+
+ var periodId = $( '#selectedPeriodId' ).val();
+
+ var valueSaver = new FileResourceValueSaver( dataElementId, periodId, optionComboId, fileResource, fieldId, dhis2.de.cst.colorGreen );
+ valueSaver.save();
+}
+
/**
* Supportive method.
*/
@@ -356,12 +366,19 @@
error: handleError
} );
};
-
+
+ var afterHandleSuccess = function() {};
+
+ this.setAfterHandleSuccess = function( callback ) {
+ afterHandleSuccess = callback;
+ };
+
function handleSuccess()
{
- dhis2.de.storageManager.clearDataValueJSON( dataValue );
+ dhis2.de.storageManager.clearDataValueJSON( dataValue );
markValue( fieldId, resultColor );
$( document ).trigger( dhis2.de.event.dataValueSaved, [ dhis2.de.currentDataSetId, dataValue ] );
+ afterHandleSuccess();
}
function handleError( xhr, textStatus, errorThrown )
@@ -384,3 +401,19 @@
$( fieldId ).css( 'background-color', color );
}
}
+
+function FileResourceValueSaver( de, pe, co, fileResource, fieldId, resultColor )
+{
+ var valueSaver = new ValueSaver( de, pe, co, fileResource.id, fieldId, resultColor );
+
+ valueSaver.setAfterHandleSuccess( function() {
+ var name = fileResource.name, size = '(' + filesize( fileResource.contentLength ) + ')';
+ var $field = $( fieldId );
+
+ $field.find( '.upload-fileinfo-name' ).text( name );
+ $field.find( '.upload-fileinfo-size' ).text( size );
+ $field.find( '.upload-progress-bar' ).toggleClass( 'upload-progress-bar-complete' );
+ } );
+
+ return valueSaver;
+}
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js 2015-09-17 05:52:20 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js 2015-09-30 18:50:42 +0000
@@ -492,7 +492,7 @@
var id = $( this ).attr( 'id' );
// If entry field is a date picker, remove old target field, and change id
- if ( /-dp$/.test( id ) )
+ if( /-dp$/.test( id ) )
{
var dpTargetId = id.substring( 0, id.length - 3 );
$( '#' + dpTargetId ).remove();
@@ -546,17 +546,17 @@
saveVal( dataElementId, optionComboId, id, fakeEvent.target.id );
},
onClose: function() {
- valueBlur(fakeEvent);
+ valueBlur( fakeEvent );
},
onShow: function() {
- valueFocus(fakeEvent);
+ valueFocus( fakeEvent );
},
minDate: null,
maxDate: null
} );
- }
+ }
} );
-
+
$( '.entryselect' ).each( function( i )
{
var id = $( this ).attr( 'id' );
@@ -611,7 +611,7 @@
$( this ).focus( valueFocus );
$( this ).blur( valueBlur );
-
+
$( this ).change( function()
{
saveVal( dataElementId, optionComboId, id );
@@ -627,15 +627,170 @@
var optionComboId = split.optionComboId;
$( this ).unbind( 'click' );
-
+
$( this ).attr( "src", "../images/comment.png" );
$( this ).attr( "title", i18n_view_comment );
-
+
$( this ).css( "cursor", "pointer" );
-
- $( this ).click ( function()
- {
- viewHist( dataElementId, optionComboId );
+
+ $( this ).click( function()
+ {
+ viewHist( dataElementId, optionComboId );
+ } );
+ } );
+
+ $( '.entryfileresource-container' ).each( function()
+ {
+ // TODO Use i18n
+ // TODO Disable when offline
+
+ // Object refs
+ var $container = $( this );
+ var $field = $container.find( '.entryfileresource' );
+ var $button = $container.find( '.upload-button' );
+
+ var $fileInput = $container.find( 'input[type=file]' );
+
+ var $fileinfo = $container.find( '.upload-fileinfo' );
+ var $fileinfoName = $fileinfo.find( '.upload-fileinfo-name' );
+ var $fileinfoSize = $fileinfo.find( '.upload-fileinfo-size' );
+
+ var $progress = $container.find( '.upload-progress' );
+ var $progressBar = $progress.find( '.upload-progress-bar' );
+ var $progressInfo = $progress.find( '.upload-progress-info' );
+
+ // IDs
+ var id = $field.attr( 'id' );
+
+ var split = dhis2.de.splitFieldId( id );
+
+ var dataElementId = split.dataElementId;
+ var optionComboId = split.optionComboId;
+ var orgUnitid = dhis2.de.currentOrganisationUnitId;
+ var periodId = $( '#selectedPeriodId' ).val();
+
+ var formData = {
+ 'de': dataElementId,
+ 'co': optionComboId,
+ 'ou': orgUnitid,
+ 'pe': periodId
+ };
+
+ // Functions
+ var deleteFileDataValue = function()
+ {
+ var postData = formData;
+ postData.value = '';
+
+ $.ajax( {
+ url: '../api/dataValues',
+ type: 'POST',
+ dataType: 'json',
+ data: postData,
+ success: function()
+ {
+ $fileinfoName.text( '' );
+ $fileinfoSize.text( '' );
+ $fileinfo.hide();
+ $field.css( 'background-color', '' );
+ setButtonUpload();
+ },
+ error: function( data )
+ {
+ console.log( data.errorThrown );
+ }
+ } );
+ };
+
+ var setButtonDelete = function()
+ {
+ $button.button( {
+ text: false,
+ icons: {
+ primary: 'fa fa-trash-o'
+ }
+ } );
+ $button.unbind( 'click' );
+ $button.on( 'click', function() {
+ // TODO Use jQuery UI dialog
+ var confirmed = window.confirm( 'Delete the file?' );
+ if ( confirmed ) {
+ deleteFileDataValue();
+ }
+ } );
+ $button.button( 'enable' );
+ };
+
+ var setButtonUpload = function()
+ {
+ $button.button( {
+ text: false,
+ icons: {
+ primary: 'fa fa-upload'
+ }
+ } );
+ $button.unbind( 'click' );
+ $button.on( 'click', function()
+ {
+ $fileInput.click();
+ } );
+ $button.button( 'enable' );
+ };
+
+ var resetAndHideProgress = function() {
+ $progressBar.toggleClass( 'upload-progress-bar-complete', true );
+ $progressBar.css( 'width', 0 );
+ $progress.hide();
+ };
+
+ // Initialize button
+ $button.button( {
+ text: false,
+ icons: {
+ primary: 'fa fa-ban'
+ }
+ } );
+ $button.button( 'disable' );
+
+ $( document ).on( dhis2.de.event.dataValuesLoaded, function() {
+ ( typeof( $field.data( 'value' ) ) == 'undefined' ) ? setButtonUpload() : setButtonDelete();
+ } );
+
+ // Initialize file uploader
+ $fileInput.fileupload( {
+ url: '../api/dataValues/files',
+ paramName: 'file',
+ multipart: true,
+ replaceFileInput: false,
+ progressInterval: 250, /* ms */
+ formData: formData,
+ start: function( e )
+ {
+ $button.button( 'disable' );
+ $progressBar.toggleClass( 'upload-progress-bar-complete', false );
+ $fileinfo.hide();
+ $progress.show();
+ },
+ progress: function( e, data )
+ {
+ var percent = parseInt( data.loaded / data.total * 100, 10 );
+ $progressBar.css( 'width', percent + '%' );
+ $progressInfo.text( percent + '%' );
+ },
+ fail: function( e, data )
+ {
+ setHeaderDelayMessage( "File upload failed!" );
+ console.log( data.errorThrown );
+ setButtonUpload();
+ },
+ done: function( e, data )
+ {
+ saveFileResource( dataElementId, optionComboId, id, data.result.response.fileResource );
+ $fileinfo.show();
+ resetAndHideProgress();
+ setButtonDelete();
+ $button.button( 'enable' );
+ }
} );
} );
}
@@ -1549,6 +1704,8 @@
$( '.entrytrueonly' ).css( 'background-color', dhis2.de.cst.colorWhite );
$( '.entryoptionset' ).css( 'background-color', dhis2.de.cst.colorWhite );
+ $( '.entryfileresource' ).css( 'background-color', dhis2.de.cst.colorWhite );
+
$( '[name="min"]' ).html( '' );
$( '[name="max"]' ).html( '' );
@@ -1658,6 +1815,24 @@
{
dhis2.de.setOptionNameInField( fieldId, value );
}
+ else if ( $( fieldId ).attr( 'class' ) == 'entryfileresource' )
+ {
+ $( fieldId ).data( 'value', value.val );
+ // TODO Consider pre-fetching with dataset
+ $.ajax( {
+ url: '../api/fileResources/' + value.val,
+ success: function( data ) {
+ var name = data.name, size = '(' + filesize( data.contentLength ) + ')';
+
+ $( fieldId ).find( '.upload-fileinfo-name' ).text( name );
+ $( fieldId ).find( '.upload-fileinfo-size' ).text( size );
+ },
+ error: function( data ) {
+ $( fieldId ).find( '.upload-fileinfo-name' ).text( 'Failed loading file meta-data' );
+ $( fieldId ).find( '.upload-fileinfo-size' ).text( + '' );
+ }
+ } );
+ }
else
{
$( fieldId ).val( value.val );
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/sectionForm.vm'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/sectionForm.vm 2015-09-07 03:01:40 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/sectionForm.vm 2015-09-30 18:50:42 +0000
@@ -100,6 +100,25 @@
<td><input name="entrytrueonly" class="entrytrueonly" id="${dataEntryId}" type="checkbox" tabindex="${tabIndex}"#if( $greyedField || !$hasAccess ) disabled="disabled"#end><img class="commentlink" id="${commentId}"></td>
#elseif( "LONG_TEXT" == $dataElement.valueType )
<td><textarea name="entryfield" class="entryfield entryarea" id="${dataEntryId}" tabindex="${tabIndex}" #if( $greyedField || !$hasAccess ) disabled="disabled"#end></textarea></td>
+ #elseif( "FILE_RESOURCE" == $dataElement.valueType )
+ <td>
+ <div class="entryfileresource-container">
+ <div id="${dataEntryId}" class="entryfileresource">
+ <div class="upload-fileinfo">
+ <div class="upload-fileinfo-size"></div>
+ <div class="upload-fileinfo-name"></div>
+ </div>
+ <div class="upload-progress">
+ <div class="upload-progress-bar"></div>
+ <div class="upload-progress-info"></div>
+ </div>
+ </div>
+ <div class="upload-button-group">
+ <button class="upload-button"></button>
+ </div>
+ <input type="file" style="display: none;">
+ </div>
+ </td>
#else
#if( $dataElement.optionSet )
<td><input name="entryoptionset" class="entryoptionset" id="${dataEntryId}" type="text" tabindex="${tabIndex}"#if( $greyedField || !$hasAccess ) disabled="disabled"#end><img class="commentlink" id="${commentId}"></td>
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/style/dhis-web-dataentry.css'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/style/dhis-web-dataentry.css 2015-05-17 14:46:45 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/style/dhis-web-dataentry.css 2015-09-30 18:50:42 +0000
@@ -254,3 +254,107 @@
{
position: absolute;
}
+
+/* FileResource - uploads */
+
+.entryfileresource
+{
+ height: 28px;
+ width: 200px;
+ border: 1px solid #aaa;
+ display: table-cell;
+ overflow: hidden;
+ position: relative;
+}
+/* Upload progress display */
+
+.upload-progress
+{
+ z-index: 2;
+}
+
+.upload-progress-bar
+{
+ height: 100%;
+ width: 0;
+ background-color: yellow;
+ position: absolute;
+ -webkit-transition: width 0.5s;
+ -moz-transition: width 0.5s;
+ -o-transition: width 0.5s;
+ -ms-transition: width 0.5s;
+ transition: width 0.5s;
+ z-index: 3;
+}
+
+.upload-progress-bar-complete
+{
+ width: 0;
+ transition: width 0s;
+}
+
+.upload-progress-info
+{
+ font-weight: bold;
+ left: 45%;
+ top: 15%;
+ height: 100%;
+ width: 100%;
+ position: absolute;
+ z-index: 4;
+}
+
+/* File metadata display */
+
+.upload-fileinfo
+{
+ padding: 5px;
+ position: absolute;
+ max-width: 100%;
+ z-index: 2;
+}
+
+.upload-fileinfo-size
+{
+ /*width: 80px;*/
+ float: right;
+ text-align: right;
+ padding-left: 3px;
+ overflow: hidden;
+ text-overflow: ellipsis;
+}
+
+.upload-fileinfo-name
+{
+ overflow: hidden;
+ text-overflow: ellipsis;
+ float: none;
+ width: auto;
+}
+
+/* File field and button */
+.upload-button-group
+{
+ display: table-cell;
+}
+
+.upload-button
+{
+ margin: 2px 2px 2px 4px;
+ height: 100%;
+}
+
+/* FA icons for jQuery UI icon hack */
+.ui-icon[class*=" fa-"] {
+ background: none repeat scroll 0 0 transparent;
+ text-indent: 0;
+ margin-top: -0.5em;
+}
+
+.ui-button-icon-only .ui-icon[class*=" fa-"] {
+ margin-left: -7px;
+}
+
+.ui-icon.icon-large {
+ margin-top: -0.75em;
+}
\ No newline at end of file