This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository pollen. See https://gitlab.nuiton.org/chorem/pollen.git commit b6b6b17c465caf98ba52de9002fd718035e63308 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Mon May 29 16:49:11 2017 +0200 vérification de la taille des fichiers, coté client --- pollen-ui-riot-js/src/main/web/conf.js | 18 +------------ pollen-ui-riot-js/src/main/web/i18n.json | 4 +++ pollen-ui-riot-js/src/main/web/js/I18nHelper.js | 2 +- pollen-ui-riot-js/src/main/web/js/UIHelper.js | 30 +++++++++++++++++----- .../src/main/web/tag/poll/Choice.tag.html | 29 +++++++++++++-------- 5 files changed, 49 insertions(+), 34 deletions(-) diff --git a/pollen-ui-riot-js/src/main/web/conf.js b/pollen-ui-riot-js/src/main/web/conf.js index d88f88b..02a7e34 100644 --- a/pollen-ui-riot-js/src/main/web/conf.js +++ b/pollen-ui-riot-js/src/main/web/conf.js @@ -1,20 +1,4 @@ window.pollenConf = { endPoint: "http://localhost:8888/pollen-rest-api", - pollDefaultPageSize: 10, - commentDefaultPageSize: 10, - favoriteListDefaultPageSize: 15, - favoriteListMemberDefaultPageSize: 30, - defaultAlertTimeInfo: 10000, - defaultAlertTimeSuccess: 2000, - defaultAlertTimeWarning: 5000, - defaultAlertTimeError: -1, - defaultDateFormat: "shortDate", - defaultTimeFormat: "shortTime", - defaultDateTimeFormat: "short", - debugI18n: false, - defaultErrorTimeout: 15, - infoMessages: { - fr: [], - en: [] - } + resourceMaxSize: 10000000 // octets => 10 Mo }; diff --git a/pollen-ui-riot-js/src/main/web/i18n.json b/pollen-ui-riot-js/src/main/web/i18n.json index a3b4447..96af58c 100644 --- a/pollen-ui-riot-js/src/main/web/i18n.json +++ b/pollen-ui-riot-js/src/main/web/i18n.json @@ -346,6 +346,8 @@ "choice_time": "Ajouter une heure à la date", "choice_description": "Ajouter un descriptif du choix", "choice_download": "Télécharger", + "choice_fileSizeMax_title": "Fichier trop lourd", + "choice_fileSizeMax_message": "Le fichier « {0} » de taille de {1} ne doit pas dépasser {2}.", "favoriteList_title": "Mes listes de votants", "favoriteList_addFavoriteList": "Ajouter une nouvelle liste de votants", "favoriteList_name": "Nom", @@ -765,6 +767,8 @@ "choice_time": "add hours to date", "choice_description": "add description", "choice_download": "Download", + "choice_fileSizeMax_title": "File to big", + "choice_fileSizeMax_message": "File \"{0}\" for size {1} can't be over {2}.", "favoriteList_title": "My favorite lists", "favoriteList_addFavoriteList": "Add new favorite list", "favoriteList_name": "Name", diff --git a/pollen-ui-riot-js/src/main/web/js/I18nHelper.js b/pollen-ui-riot-js/src/main/web/js/I18nHelper.js index 1b75ff5..5f5e891 100644 --- a/pollen-ui-riot-js/src/main/web/js/I18nHelper.js +++ b/pollen-ui-riot-js/src/main/web/js/I18nHelper.js @@ -55,7 +55,7 @@ module.exports = { }, _l(key, ...params) { - return this.i18nformat(this.__[key], ...params) || key; + return this.i18nformat(this.__[key], params) || key; }, i18nformat(value, params) { diff --git a/pollen-ui-riot-js/src/main/web/js/UIHelper.js b/pollen-ui-riot-js/src/main/web/js/UIHelper.js index db12de5..91aa645 100644 --- a/pollen-ui-riot-js/src/main/web/js/UIHelper.js +++ b/pollen-ui-riot-js/src/main/web/js/UIHelper.js @@ -4,12 +4,12 @@ let moment = require("moment"); module.exports = { getWindowDimensions() { var w = window, - d = document, - e = d.documentElement, - g = d.getElementsByTagName("body")[0], - x = w.innerWidth || e.clientWidth || g.clientWidth, - y = w.innerHeight || e.clientHeight || g.clientHeight; - return { width: x, height: y }; + d = document, + e = d.documentElement, + g = d.getElementsByTagName("body")[0], + x = w.innerWidth || e.clientWidth || g.clientWidth, + y = w.innerHeight || e.clientHeight || g.clientHeight; + return {width: x, height: y}; }, positionDropdown(selector, visible) { @@ -60,5 +60,23 @@ module.exports = { }); }, + checkSize(resource) { + if (resource && resource.size && resource.size > window.pollenConf.resourceMaxSize) { + return this.info( + this.__.fileSizeMax_title, + this._l("fileSizeMax_message", resource.name, this.formatSize(resource.size), this.formatSize(window.pollenConf.resourceMaxSize)), + undefined, + "error").then(() => false); + } + return Promise.resolve(true); + }, + + formatSize(size) { + let unitsSI = ["o", "ko", "Mo", "Go", "To", "Po", "Eo", "Zo", "Yo"]; + let index = Math.min(Math.floor(Math.log10(size) / 3), unitsSI.length - 1); + let value = (size / Math.pow(10, index * 3)).toFixed(2); + return value + " " + unitsSI[index]; + }, + DATETIME_INPUT_PATTERN: "[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}" }; diff --git a/pollen-ui-riot-js/src/main/web/tag/poll/Choice.tag.html b/pollen-ui-riot-js/src/main/web/tag/poll/Choice.tag.html index f3d4845..a5515d0 100644 --- a/pollen-ui-riot-js/src/main/web/tag/poll/Choice.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/poll/Choice.tag.html @@ -163,16 +163,25 @@ require("../components/time-picker.tag.html"); this.onRessourceChange = () => { this.newFile = this.refs.choiceResource.files[0]; - if (this.newFile.type.startsWith("image/")) { - this.newFile.image = true; - let reader = new FileReader(); - reader.onload = (e) => { - // get loaded data and render thumbnail. - this.refs.imagePreview.src = e.target.result; - }; - // read the image file as a data URL. - reader.readAsDataURL(this.refs.choiceResource.files[0]); - } + this.checkSize(this.newFile).then(ok => { + if (ok) { + if (this.newFile.type.startsWith("image/")) { + this.newFile.image = true; + let reader = new FileReader(); + reader.onload = (e) => { + // get loaded data and render thumbnail. + this.refs.imagePreview.src = e.target.result; + }; + // read the image file as a data URL. + reader.readAsDataURL(this.refs.choiceResource.files[0]); + this.update(); + } + } else { + this.refs.choiceResource.value = ""; + delete this.newFile; + this.update(); + } + }); }; this.deleteFile = () => { -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.