partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit f804b4a4a9ea1a15c2565b7ef3f3f48f547f2f30
parent 0440f19e9d34e2ccb75a0497ba1c132f538f70f8
Author: Timo A. Hummel <timo@netraver.de>
Date:   Wed,  8 Jun 2011 22:09:55 +0200

Added display of maximum upload size and available image formats

Diffstat:
Dfrontend/index.html | 140-------------------------------------------------------------------------------
Afrontend/index.php | 149+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mfrontend/js/Components/Manufacturer/ManufacturerEditor.js | 2+-
Mfrontend/js/Dialogs/FileUploadDialog.js | 97++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------
Mfrontend/js/PartDB2.js | 23+++++++++++++++++++++++
5 files changed, 244 insertions(+), 167 deletions(-)

diff --git a/frontend/index.html b/frontend/index.html @@ -1,139 +0,0 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" - "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> -<html> - <head> - <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> - <title>PartDB2</title> - - <link rel="icon" href="favicon.ico"/> - - <!-- Include the ExtJS JavaScript Library --> - <script type="text/javascript" src="extjs/bootstrap.js"></script> - <script type="text/javascript" src="extjs/ext-all-debug.js"></script> - - <script type="text/javascript" src="js/Ext.ux/statusbar/StatusBar.js"></script> - <script type="text/javascript" src="js/Ext.ux/SearchField.js"></script> - - <!-- Include the ExtJS CSS Theme --> - <link rel="stylesheet" type="text/css" href="extjs/resources/css/ext-all.css"/> - - <link rel="stylesheet" type="text/css" href="js/Ext.ux/statusbar/css/statusbar.css"/> - - <link rel="stylesheet" type="text/css" href="css/PartDB2.css"/> - - <script type="text/javascript" src="js/bugfixes.js"></script> - <script type="text/javascript" src="js/Util/i18n.js"></script> - - <script type="text/javascript" src="js/org.phpjs.lib/php.default.min.js"></script> - - <script type="text/javascript" src="js/Dialogs/ExceptionWindow.js"></script> - <script type="text/javascript" src="js/Dialogs/FileUploadDialog.js"></script> - - <script type="text/javascript" src="js/Ext.ux/ClearableComboBox.js"></script> - <script type="text/javascript" src="js/Ext.ux/TabCloseMenu.js"></script> - <script type="text/javascript" src="js/Ext.ux/Ext.ux.CheckboxValue.js"></script> - - <script type="text/javascript" src="js/Components/Widgets/CategoryComboBox.js"></script> - <script type="text/javascript" src="js/Components/Widgets/StorageLocationComboBox.js"></script> - <script type="text/javascript" src="js/Components/Widgets/FootprintComboBox.js"></script> - <script type="text/javascript" src="js/Components/Widgets/ManufacturerComboBox.js"></script> - <script type="text/javascript" src="js/Components/Widgets/DistributorComboBox.js"></script> - <script type="text/javascript" src="js/Components/Widgets/PartUnitComboBox.js"></script> - - <script type="text/javascript" src="js/Util/ServiceCall.js"></script> - - <script type="text/javascript" src="js/org.jerrymouse.util.locale/locale.js"></script> - <script type="text/javascript" src="js/org.jerrymouse.util.locale/locales/en_US.js"></script> - <script type="text/javascript" src="js/org.jerrymouse.util.locale/locales/de_DE.js"></script> - - <script type="text/javascript" src="js/PartDB2.js"></script> - - <script type="text/javascript" src="js/Models/Footprint.js"></script> - <script type="text/javascript" src="js/Models/StorageLocation.js"></script> - <script type="text/javascript" src="js/Models/Distributor.js"></script> - <script type="text/javascript" src="js/Models/Manufacturer.js"></script> - <script type="text/javascript" src="js/Models/ManufacturerICLogo.js"></script> - <script type="text/javascript" src="js/Models/User.js"></script> - <script type="text/javascript" src="js/Models/Category.js"></script> - <script type="text/javascript" src="js/Models/Part.js"></script> - <script type="text/javascript" src="js/Models/PartUnit.js"></script> - <script type="text/javascript" src="js/Models/PartDistributor.js"></script> - <script type="text/javascript" src="js/Models/PartManufacturer.js"></script> - - <script type="text/javascript" src="js/Models/Message.js"></script> - - <script type="text/javascript" src="js/Dialogs/Auth/LoginDialog.js"></script> - - <script type="text/javascript" src="js/Components/Statusbar.js"></script> - <script type="text/javascript" src="js/Components/MenuBar.js"></script> - <script type="text/javascript" src="js/Components/ConnectionButton.js"></script> - <script type="text/javascript" src="js/Components/TimeDisplay.js"></script> - <script type="text/javascript" src="js/Components/MessageLog.js"></script> - - <script type="text/javascript" src="js/Components/Editor/EditorGrid.js"></script> - <script type="text/javascript" src="js/Components/Editor/EditorComponent.js"></script> - <script type="text/javascript" src="js/Components/Editor/Editor.js"></script> - - <script type="text/javascript" src="js/Components/CategoryStore.js"></script> - <script type="text/javascript" src="js/Components/CategoryTree.js"></script> - - <script type="text/javascript" src="js/Components/Footprint/FootprintGrid.js"></script> - <script type="text/javascript" src="js/Components/Footprint/FootprintEditor.js"></script> - <script type="text/javascript" src="js/Components/Footprint/FootprintEditorComponent.js"></script> - - <script type="text/javascript" src="js/Components/StorageLocation/StorageLocationGrid.js"></script> - <script type="text/javascript" src="js/Components/StorageLocation/StorageLocationEditor.js"></script> - <script type="text/javascript" src="js/Components/StorageLocation/StorageLocationEditorComponent.js"></script> - - <script type="text/javascript" src="js/Components/Manufacturer/ManufacturerGrid.js"></script> - <script type="text/javascript" src="js/Components/Manufacturer/ManufacturerEditor.js"></script> - <script type="text/javascript" src="js/Components/Manufacturer/ManufacturerEditorComponent.js"></script> - - <script type="text/javascript" src="js/Components/Distributor/DistributorGrid.js"></script> - <script type="text/javascript" src="js/Components/Distributor/DistributorEditor.js"></script> - <script type="text/javascript" src="js/Components/Distributor/DistributorEditorComponent.js"></script> - - <script type="text/javascript" src="js/Components/CategoryEditor/CategoryEditorForm.js"></script> - <script type="text/javascript" src="js/Components/CategoryEditor/CategoryEditorWindow.js"></script> - <script type="text/javascript" src="js/Components/CategoryEditor/CategoryEditorTree.js"></script> - - <script type="text/javascript" src="js/Components/User/UserEditor.js"></script> - <script type="text/javascript" src="js/Components/User/UserEditorComponent.js"></script> - <script type="text/javascript" src="js/Components/User/UserGrid.js"></script> - - <script type="text/javascript" src="js/Components/PartUnit/PartUnitEditor.js"></script> - <script type="text/javascript" src="js/Components/PartUnit/PartUnitEditorComponent.js"></script> - <script type="text/javascript" src="js/Components/PartUnit/PartUnitGrid.js"></script> - - <script type="text/javascript" src="js/Components/Statistics/CurrentStatisticsDialog.js"></script> - - <script type="text/javascript" src="js/Components/Part/PartsManager.js"></script> - <script type="text/javascript" src="js/Components/Part/PartsGrid.js"></script> - <script type="text/javascript" src="js/Components/Part/PartDistributorGrid.js"></script> - <script type="text/javascript" src="js/Components/Part/PartManufacturerGrid.js"></script> - <script type="text/javascript" src="js/Components/Part/PartEditorWindow.js"></script> - <script type="text/javascript" src="js/Components/Part/PartEditor.js"></script> - <script type="text/javascript" src="js/Components/Part/PartDisplay.js"></script> - <script type="text/javascript" src="js/Components/Part/PartStockWindow.js"></script> - - </head> -<body> - -<script type="text/javascript"> -/* -Ext.onReady(function(){ - Ext.setLocale('en_US'); - - Ext.QuickTips.init(); - - var mainWindow = new org.jerrymouse.gui.widgets.MainWindow(); - - var o = new org.jerrymouse.gui.login.dialog(); - o.show(); - - -});*/ - -</script> -</body> -</html>- \ No newline at end of file diff --git a/frontend/index.php b/frontend/index.php @@ -0,0 +1,148 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" + "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> +<html> + <head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> + <title>PartDB2</title> + + <link rel="icon" href="favicon.ico"/> + + <!-- Include the ExtJS JavaScript Library --> + <script type="text/javascript" src="extjs/bootstrap.js"></script> + <script type="text/javascript" src="extjs/ext-all-debug.js"></script> + + <script type="text/javascript" src="js/Ext.ux/statusbar/StatusBar.js"></script> + <script type="text/javascript" src="js/Ext.ux/SearchField.js"></script> + + <!-- Include the ExtJS CSS Theme --> + <link rel="stylesheet" type="text/css" href="extjs/resources/css/ext-all.css"/> + + <link rel="stylesheet" type="text/css" href="js/Ext.ux/statusbar/css/statusbar.css"/> + + <link rel="stylesheet" type="text/css" href="css/PartDB2.css"/> + + <script type="text/javascript" src="js/bugfixes.js"></script> + <script type="text/javascript" src="js/Util/i18n.js"></script> + + <script type="text/javascript" src="js/org.phpjs.lib/php.default.min.js"></script> + + <script type="text/javascript" src="js/Dialogs/ExceptionWindow.js"></script> + <script type="text/javascript" src="js/Dialogs/FileUploadDialog.js"></script> + + <script type="text/javascript" src="js/Ext.ux/ClearableComboBox.js"></script> + <script type="text/javascript" src="js/Ext.ux/TabCloseMenu.js"></script> + + <script type="text/javascript" src="js/Components/Widgets/CategoryComboBox.js"></script> + <script type="text/javascript" src="js/Components/Widgets/StorageLocationComboBox.js"></script> + <script type="text/javascript" src="js/Components/Widgets/FootprintComboBox.js"></script> + <script type="text/javascript" src="js/Components/Widgets/ManufacturerComboBox.js"></script> + <script type="text/javascript" src="js/Components/Widgets/DistributorComboBox.js"></script> + <script type="text/javascript" src="js/Components/Widgets/PartUnitComboBox.js"></script> + + <script type="text/javascript" src="js/Util/ServiceCall.js"></script> + + <script type="text/javascript" src="js/org.jerrymouse.util.locale/locale.js"></script> + <script type="text/javascript" src="js/org.jerrymouse.util.locale/locales/en_US.js"></script> + <script type="text/javascript" src="js/org.jerrymouse.util.locale/locales/de_DE.js"></script> + + <script type="text/javascript" src="js/PartDB2.js"></script> + + <script type="text/javascript" src="js/Models/Footprint.js"></script> + <script type="text/javascript" src="js/Models/StorageLocation.js"></script> + <script type="text/javascript" src="js/Models/Distributor.js"></script> + <script type="text/javascript" src="js/Models/Manufacturer.js"></script> + <script type="text/javascript" src="js/Models/ManufacturerICLogo.js"></script> + <script type="text/javascript" src="js/Models/User.js"></script> + <script type="text/javascript" src="js/Models/Category.js"></script> + <script type="text/javascript" src="js/Models/Part.js"></script> + <script type="text/javascript" src="js/Models/PartUnit.js"></script> + <script type="text/javascript" src="js/Models/PartDistributor.js"></script> + <script type="text/javascript" src="js/Models/PartManufacturer.js"></script> + + <script type="text/javascript" src="js/Models/Message.js"></script> + + <script type="text/javascript" src="js/Dialogs/Auth/LoginDialog.js"></script> + + <script type="text/javascript" src="js/Components/Statusbar.js"></script> + <script type="text/javascript" src="js/Components/MenuBar.js"></script> + <script type="text/javascript" src="js/Components/ConnectionButton.js"></script> + <script type="text/javascript" src="js/Components/TimeDisplay.js"></script> + <script type="text/javascript" src="js/Components/MessageLog.js"></script> + + <script type="text/javascript" src="js/Components/Editor/EditorGrid.js"></script> + <script type="text/javascript" src="js/Components/Editor/EditorComponent.js"></script> + <script type="text/javascript" src="js/Components/Editor/Editor.js"></script> + + <script type="text/javascript" src="js/Components/CategoryStore.js"></script> + <script type="text/javascript" src="js/Components/CategoryTree.js"></script> + + <script type="text/javascript" src="js/Components/Footprint/FootprintGrid.js"></script> + <script type="text/javascript" src="js/Components/Footprint/FootprintEditor.js"></script> + <script type="text/javascript" src="js/Components/Footprint/FootprintEditorComponent.js"></script> + + <script type="text/javascript" src="js/Components/StorageLocation/StorageLocationGrid.js"></script> + <script type="text/javascript" src="js/Components/StorageLocation/StorageLocationEditor.js"></script> + <script type="text/javascript" src="js/Components/StorageLocation/StorageLocationEditorComponent.js"></script> + + <script type="text/javascript" src="js/Components/Manufacturer/ManufacturerGrid.js"></script> + <script type="text/javascript" src="js/Components/Manufacturer/ManufacturerEditor.js"></script> + <script type="text/javascript" src="js/Components/Manufacturer/ManufacturerEditorComponent.js"></script> + + <script type="text/javascript" src="js/Components/Distributor/DistributorGrid.js"></script> + <script type="text/javascript" src="js/Components/Distributor/DistributorEditor.js"></script> + <script type="text/javascript" src="js/Components/Distributor/DistributorEditorComponent.js"></script> + + <script type="text/javascript" src="js/Components/CategoryEditor/CategoryEditorForm.js"></script> + <script type="text/javascript" src="js/Components/CategoryEditor/CategoryEditorWindow.js"></script> + <script type="text/javascript" src="js/Components/CategoryEditor/CategoryEditorTree.js"></script> + + <script type="text/javascript" src="js/Components/User/UserEditor.js"></script> + <script type="text/javascript" src="js/Components/User/UserEditorComponent.js"></script> + <script type="text/javascript" src="js/Components/User/UserGrid.js"></script> + + <script type="text/javascript" src="js/Components/PartUnit/PartUnitEditor.js"></script> + <script type="text/javascript" src="js/Components/PartUnit/PartUnitEditorComponent.js"></script> + <script type="text/javascript" src="js/Components/PartUnit/PartUnitGrid.js"></script> + + <script type="text/javascript" src="js/Components/Statistics/CurrentStatisticsDialog.js"></script> + + <script type="text/javascript" src="js/Components/Part/PartsManager.js"></script> + <script type="text/javascript" src="js/Components/Part/PartsGrid.js"></script> + <script type="text/javascript" src="js/Components/Part/PartDistributorGrid.js"></script> + <script type="text/javascript" src="js/Components/Part/PartManufacturerGrid.js"></script> + <script type="text/javascript" src="js/Components/Part/PartEditorWindow.js"></script> + <script type="text/javascript" src="js/Components/Part/PartEditor.js"></script> + <script type="text/javascript" src="js/Components/Part/PartDisplay.js"></script> + <script type="text/javascript" src="js/Components/Part/PartStockWindow.js"></script> + + </head> +<body> + +<?php +// @todo put that somewhere else. This is only a stupid hack. +function return_bytes ($size_str) +{ + switch (substr ($size_str, -1)) + { + case 'M': case 'm': return (int)$size_str * 1048576; + case 'K': case 'k': return (int)$size_str * 1024; + case 'G': case 'g': return (int)$size_str * 1073741824; + default: return $size_str; + } +} + +$maxPostSize = return_bytes(ini_get("post_max_size")); +$maxFilesize = return_bytes(ini_get("upload_max_filesize")); + +$maxUploadSize = ($maxPostSize < $maxFilesize) ? $maxPostSize : $maxFilesize; + +$imagick = new Imagick(); +?> +<script type="text/javascript"> + +PartDB2.setMaxUploadSize(<?php echo $maxUploadSize; ?>); +PartDB2.setAvailableImageFormats(<?php echo json_encode($imagick->queryFormats()); ?>); + +</script> +</body> +</html>+ \ No newline at end of file diff --git a/frontend/js/Components/Manufacturer/ManufacturerEditor.js b/frontend/js/Components/Manufacturer/ManufacturerEditor.js @@ -110,7 +110,7 @@ Ext.define('PartDB2.ManufacturerEditor', { }); }, uploadImage: function () { - var j = Ext.create("PartDB2.FileUploadDialog"); + var j = Ext.create("PartDB2.FileUploadDialog", { imageUpload: true }); j.on("fileUploaded", Ext.bind(this.onFileUploaded, this)); j.show(); }, diff --git a/frontend/js/Dialogs/FileUploadDialog.js b/frontend/js/Dialogs/FileUploadDialog.js @@ -1,10 +1,53 @@ Ext.define('PartDB2.FileUploadDialog', { extend: 'Ext.window.Window', - title: i18n("Image Upload"), + + title: i18n("File Upload"), + fileFieldLabel: i18n("File"), + uploadButtonText: i18n('Select File...'), + initComponent: function () { this.addEvents("fileUploaded"); + this.uploadButton = Ext.create("Ext.button.Button", + { + text: i18n('Upload'), + handler: Ext.bind(function() { + var form = this.form.getForm(); + if(form.isValid()){ + form.submit({ + url: 'rest.php/TempImage', + params: { + call: "upload", + session: PartDB2.getApplication().getSession() + }, + success: Ext.bind(function(fp, o) { + this.fireEvent("fileUploaded", o.result.response.id); + this.close(); + },this), + failure: function(form, action) { + } + }); + } + }, this) + }); + + this.tbButtons = [ this.uploadButton ]; + + if (this.imageUpload) { + this.title = i18n("Image Upload"); + this.fileFieldLabel = i18n("Image"); + this.uploadButtonText = i18n("Select Image..."); + + this.fileFormatButton = Ext.create("Ext.button.Button", { + text: i18n("Available Formats"), + handler: this.showAvailableFormats, + scope: this + }); + + this.tbButtons.push(this.fileFormatButton); + } + this.form = Ext.create('Ext.form.Panel', { width: 400, bodyPadding: 10, @@ -12,40 +55,42 @@ Ext.define('PartDB2.FileUploadDialog', { items: [{ xtype: 'filefield', name: 'userfile', - fieldLabel: 'Photo', + fieldLabel: this.fileFieldLabel, labelWidth: 50, msgTarget: 'side', allowBlank: false, anchor: '100%', - buttonText: 'Select Image...' + buttonText: this.uploadButtonText + },{ + html: sprintf(i18n("Maximum upload size: %s"), PartDB2.bytesToSize(PartDB2.getMaxUploadSize())), + border: false }], - buttons: [{ - text: 'Upload', - handler: Ext.bind(function() { - var form = this.form.getForm(); - if(form.isValid()){ - form.submit({ - url: 'rest.php/TempImage', - params: { - call: "upload", - session: PartDB2.getApplication().getSession() - }, - waitMsg: 'Uploading your photo...', - success: Ext.bind(function(fp, o) { - this.fireEvent("fileUploaded", o.result.response.id); - this.close(); - },this), - failure: function(form, action) { - - } - }); - } - }, this) - }] + buttons: this.tbButtons }); this.items = this.form; this.callParent(); + }, + /** + * Shows a tooltip for all available image formats. + */ + showAvailableFormats: function () { + if (!this.tip) { + this.tip = Ext.create("Ext.tip.ToolTip", { + title: i18n("Available Image Formats"), + anchor: 'left', + width: 200, + height: 300, + autoScroll: true, + target: this.fileFormatButton.getEl(), + closable: true, + html: "FOO"+implode("<br>", PartDB2.getAvailableImageFormats()), + autoHide: false + }); + } + + + this.tip.show(); } }); diff --git a/frontend/js/PartDB2.js b/frontend/js/PartDB2.js @@ -258,6 +258,29 @@ PartDB2.getBasePath = function () { return "rest.php"; }; +PartDB2.setMaxUploadSize = function (size) { + PartDB2.maxUploadSize = size; +}; + +PartDB2.getMaxUploadSize = function () { + return PartDB2.maxUploadSize; +}; + +PartDB2.bytesToSize = function (bytes) { + var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB']; + if (bytes == 0) return 'n/a'; + var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); + return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i]; +}; + +PartDB2.setAvailableImageFormats = function (formats) { + PartDB2.imageFormats = formats; +}; + +PartDB2.getAvailableImageFormats = function () { + return PartDB2.imageFormats; +}; + PartDB2.serializeRecords = function (records) { var finalData = [];