commit 66f911beb3ff3f8a79e5f725fad94f025d2e9113
parent 97311293b77bf90ac8fd281155985e2fd71e2237
Author: Felicitus <felicitus@felicitus.org>
Date: Wed, 4 Apr 2012 07:55:58 +0200
Added grid plugin and store exporting
Diffstat:
8 files changed, 176 insertions(+), 4 deletions(-)
diff --git a/build.xml b/build.xml
@@ -95,7 +95,7 @@
<include name="resources/**"/>
</fileset>
</copy>
-
+
<echo>Copying Ext Statusbar</echo>
<copy overwrite="false" todir="frontend/js/Ext.ux/">
<fileset dir="${extjs.path}/examples/ux">
@@ -251,6 +251,8 @@
<target name="jsbuilder">
<exec command="php util/gen-jsb3-file.php ./src/frontend/ ${extjs.path}"/>
<exec command="${extjs.path}/jsbuilder/JSBuilder.sh --projectFile ${project.basedir}/partkeepr.jsb3 --deployDir ${project.basedir}/frontend/js" passthru="true"/>
+
+ <exec command="${extjs.path}/jsbuilder/JSBuilder.sh --projectFile ${project.basedir}/3rdparty/Ext.ux.Exporter/Ext.ux.Exporter.jsb --deployDir ${project.basedir}/frontend/js/Ext.ux" passthru="true"/>
</target>
<!-- Checks all JavaScript files for common mistakes. Requires JSLint from http://www.javascriptlint.com -->
diff --git a/src/backend/de/RaumZeitLabor/PartKeepr/TempFile/TempFileService.php b/src/backend/de/RaumZeitLabor/PartKeepr/TempFile/TempFileService.php
@@ -29,6 +29,30 @@ class TempFileService extends Service {
}
/**
+ * Receives a file via the service call.
+ *
+ * Parameters:
+ * - filedata: needs to be base64-encoded.
+ * - filename: The filename
+ */
+ public function jsonUpload () {
+ $data = base64_decode($this->getParameter("filedata"));
+ $filename = $this->getParameter("filename");
+
+ $tempFile = tempnam("/tmp", "PWC");
+ file_put_contents($tempFile, $data);
+
+ $tmpFile = new TempUploadedFile();
+ $tmpFile->replace($tempFile);
+ $tmpFile->setOriginalFilename($filename);
+
+ PartKeepr::getEM()->persist($tmpFile);
+ PartKeepr::getEM()->flush();
+
+ return $tmpFile->serialize();
+ }
+
+ /**
* Processes data via HTTP POST. Reads php://input and creates a temporary image out of it.
*/
public function uploadCam () {
diff --git a/src/backend/de/RaumZeitLabor/PartKeepr/UploadedFile/UploadedFile.php b/src/backend/de/RaumZeitLabor/PartKeepr/UploadedFile/UploadedFile.php
@@ -3,6 +3,7 @@ namespace de\RaumZeitLabor\PartKeepr\UploadedFile;
use de\RaumZeitLabor\PartKeepr\Util\SerializableException,
de\RaumZeitLabor\PartKeepr\Util\BaseEntity,
+ de\RaumZeitLabor\PartKeepr\Util\Serializable,
de\RaumZeitLabor\PartKeepr\PartKeepr,
de\RaumZeitLabor\PartKeepr\UploadedFile\TempUploadedFile,
de\RaumZeitLabor\PartKeepr\Util\Configuration;
@@ -10,7 +11,7 @@ use de\RaumZeitLabor\PartKeepr\Util\SerializableException,
/**
* @MappedSuperclass
*/
-abstract class UploadedFile extends BaseEntity {
+abstract class UploadedFile extends BaseEntity implements Serializable {
/**
* Specifies the type of the file.
*
@@ -284,4 +285,17 @@ abstract class UploadedFile extends BaseEntity {
sprintf(PartKeepr::i18n("Unable to write to directory %s"), $this->getFilePath()));
}
}
+
+ /**
+ * (non-PHPdoc)
+ * @see de\RaumZeitLabor\PartKeepr\Util.Serializable::serialize()
+ */
+ public function serialize () {
+ return array(
+ "id" => $this->getId(),
+ "extension" => $this->getExtension(),
+ "size" => $this->getSize(),
+ "originalFilename" => $this->getOriginalFilename()
+ );
+ }
}
diff --git a/src/frontend/file.php b/src/frontend/file.php
@@ -54,7 +54,14 @@ if ($file == null) {
if (is_object($file)) {
header("Content-Type: ".$file->getMimeType());
- header('Content-Disposition: inline; filename="'.basename($file->getOriginalFilename()).'"');
+
+ if ($_REQUEST["download"] && $_REQUEST["download"] == "true") {
+ header("Content-Description: File Transfer");
+ header('Content-Disposition: attachment; filename="'.basename($file->getOriginalFilename()).'"');
+ } else {
+ header('Content-Disposition: inline; filename="'.basename($file->getOriginalFilename()).'"');
+ }
+
$fp = fopen($file->getFilename(), "rb");
fpassthru($fp);
diff --git a/src/frontend/js/Components/Grid/BaseGrid.js b/src/frontend/js/Components/Grid/BaseGrid.js
@@ -0,0 +1,26 @@
+/**
+ * Defines an abstract grid which includes the grid menu plugin.
+ *
+ */
+Ext.define('PartKeepr.BaseGrid', {
+ extend: 'Ext.grid.Panel',
+ alias: 'widget.BaseGrid',
+
+ /**
+ * Initializes the component
+ */
+ initComponent: function () {
+
+ /**
+ * Check if the plugins already exist (e.g. by a superclass). If yes, assume it is an array, and append
+ * the plugin to it.
+ */
+ if (this.plugins) {
+ this.plugins.push('gridmenu');
+ } else {
+ this.plugins = [ 'gridmenu' ];
+ }
+
+ this.callParent();
+ }
+});+
\ No newline at end of file
diff --git a/src/frontend/js/Components/Grid/GridMenuPlugin.js b/src/frontend/js/Components/Grid/GridMenuPlugin.js
@@ -0,0 +1,96 @@
+/**
+ * Defines a grid menu plugin which appears when a grid is right-clicked.
+ *
+ * Currently only contains an export menu.
+ */
+Ext.define("PartKeepr.GridMenuPlugin", {
+ alias: 'plugin.gridmenu',
+
+ // Private: The assigned grid
+ grid: null,
+
+ /**
+ * Initializes the plugin.
+ * @param grid {Object} The grid to which this plugin is bound
+ */
+ init: function(grid) {
+ this.grid = grid;
+
+ this.menu = new Ext.menu.Menu({
+ floating: true,
+ renderTo: Ext.getBody(),
+ items: [{
+ text: i18n("Export"),
+ icon: 'resources/fugue-icons/icons/application-export.png',
+ menu: [{
+ icon: 'resources/mimetypes/csv.png',
+ text: 'Export as CSV (.csv)',
+ handler: this.exportCSV,
+ scope: this
+ },{
+ icon: 'resources/fugue-icons/icons/blue-document-excel.png',
+ text: 'Export as Excel XML (.xlsx)',
+ handler: this.exportXLSX,
+ scope: this
+ },{
+ icon: 'resources/icons/mediawiki_icon.png',
+ text: 'Export as MediaWiki table (.txt)',
+ handler: this.exportWiki,
+ scope: this
+ }]
+ }]
+ });
+
+ // Show the menu when an item was clicked
+ grid.on("itemcontextmenu", function (view, record, item, index, e, eOpts) {
+ this.menu.showAt(e.xy[0], e.xy[1]);
+ }, this);
+
+ // Show the menu when no item but the grid was clicked
+ grid.on("containercontextmenu", function (view, e, eOpts) {
+ this.menu.showAt(e.xy[0], e.xy[1]);
+ }, this);
+ },
+ /**
+ * Exports the grid to CSV
+ */
+ exportCSV: function () {
+ this.doExport(Ext.ux.exporter.Exporter.exportAny(this.grid, "csv", {}), this.getExportFilename() + ".csv");
+ },
+ /**
+ * Exports the grid to MediaWiki format
+ */
+ exportWiki: function () {
+ this.doExport(Ext.ux.exporter.Exporter.exportAny(this.grid, "wiki", {}), this.getExportFilename() + ".txt");
+ },
+ /**
+ * Exports the grid to XLSX
+ */
+ exportXLSX: function () {
+ this.doExport(Ext.ux.exporter.Exporter.exportAny(this.grid, "excel", {}), this.getExportFilename() + ".xlsx");
+ },
+ /**
+ * Returns the filename without extension for the grid. Defaults to the grid's title
+ * @returns {String} the filename
+ */
+ getExportFilename: function () {
+ return this.grid.title;
+ },
+ /**
+ * Triggers the export. Calls the jsonUpload method and redirects to the uploaded file.
+ *
+ * @param data {String} The data
+ * @param filename {String} The filename
+ */
+ doExport: function (data, filename) {
+ var call = new PartKeepr.ServiceCall("TempFile", "jsonUpload");
+ call.setParameter("filedata", Ext.ux.exporter.Base64.encode(data));
+ call.setParameter("filename", filename);
+ call.setHandler(function (response) {
+ var loc = "file.php?type=temp&download=true&id=TMP:"+response.id;
+
+ window.location.href = loc;
+ });
+ call.doCall();
+ }
+});+
\ No newline at end of file
diff --git a/src/frontend/resources/icons/mediawiki_icon.png b/src/frontend/resources/icons/mediawiki_icon.png
Binary files differ.
diff --git a/src/frontend/templates/index.tpl b/src/frontend/templates/index.tpl
@@ -21,14 +21,15 @@
{% if debug %}
<script type="text/javascript" src="extjs/ext-all-debug.js"></script>
<script type="text/javascript" src="js/partkeepr-debug.js"></script>
+ <script type="text/javascript" src="js/Ext.ux/Ext.ux.formatter-all-debug.js"></script>
{% else %}
<script type="text/javascript" src="extjs/ext-all.js"></script>
<script type="text/javascript" src="js/partkeepr.js"></script>
+ <script type="text/javascript" src="js/Ext.ux/Ext.ux.formatter-all.js"></script>
{% endif %}
<script type="text/javascript" src="js/org.phpjs.lib/php.default.min.js"></script>
<script type="text/javascript" src="js/webcam.js"></script>
-
</head>
<body>
<div id="loading"><span class="logo"></span></div>