commit 58bc00b52c6bf00242ee0b78c709fd1b552bab62
parent 93394fbfe5bfd15eedb5cc757bd74fcb600a6839
Author: Felicitus <felicitus@felicitus.org>
Date: Sun, 2 Aug 2015 16:17:56 +0200
Migrated part attachment image display
Diffstat:
3 files changed, 103 insertions(+), 142 deletions(-)
diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/PartDisplay.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/PartDisplay.js
@@ -163,7 +163,7 @@ Ext.define('PartKeepr.PartDisplay', {
for (i in recordData) {
if (recordData[i] !== null) {
- values[i] = htmlentities(recordData[i]);
+ values[i] = htmlentities(recordData[i]); // phpjs
} else {
values[i] = recordData[i];
}
diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/PartImageDisplay.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/PartImageDisplay.js
@@ -3,141 +3,102 @@
* Provides a display of all part images with scroll-through functionality.
*/
Ext.define('PartKeepr.PartImageDisplay', {
- extend: 'Ext.panel.Panel',
-
- displayedImageId: 0,
- maxImageWidth: 200,
- maxImageHeight: 150,
-
- layout: 'hbox',
- border: false,
-
- /**
- * Initializes the component and creates all widgets.
- */
- initComponent: function () {
- this.prevButton = Ext.create("Ext.button.Button", {
- text: '<',
- width: 20,
- height: this.maxImageHeight,
- handler: this.onPreviousClick,
- scope: this
- });
-
- this.nextButton = Ext.create("Ext.button.Button", {
- text: '>',
- width: 20,
- height: this.maxImageHeight,
- handler: this.onNextClick,
- scope: this
- });
-
- this.imageDisplay = Ext.create("Ext.container.Container", {
- height: this.maxImageHeight,
- width: this.maxImageWidth,
- style: 'align: center'
- });
-
- this.items = [ this.prevButton, this.imageDisplay, this.nextButton ];
-
- this.tpl = new Ext.XTemplate('<img src="{image}"/>');
-
- this.callParent();
- },
- /**
- * Sets the stored when a new part is selected.
- * @param store The store
- */
- setStore: function (store) {
- var imageSet = false;
-
- this.store = store;
-
- this.displayedImageId = 0;
-
- var id = this.getImageToDisplayForward(0);
-
- if (id !== -1) {
- this.setImage(id);
- imageSet = true;
-
- }
-
- if (!imageSet) {
- this.tpl.overwrite(this.imageDisplay.getEl(), { image: 'image.php?type=partattachment&id=0&w='+this.maxImageWidth+'&h='+this.maxImageHeight});
- }
- },
- /**
- * Sets the image
- * @param id The attachment ID to set
- */
- setImage: function (id) {
- this.tpl.overwrite(this.imageDisplay.getEl(), { image: 'image.php?type=partattachment&m=fitexact&w='+this.maxImageWidth+'&h='+this.maxImageHeight+'&id='+id});
- this.displayedImageId = id;
- },
- /**
- * Handler for the "next" button
- */
- onNextClick: function () {
- var imgId = this.getImageToDisplayForward(this.displayedImageId);
-
- if (imgId !== -1) {
- this.setImage(imgId);
- }
- },
- /**
- * Handler for the "previous" button
- */
- onPreviousClick: function () {
- var imgId = this.getImageToDisplayBackward(this.displayedImageId);
-
- if (imgId !== -1) {
- this.setImage(imgId);
- }
-
- },
- /**
- * Returns the next image in the attachment store
- * @param startId The start ID
- * @returns int An attachment id, or -1 of none was found
- */
- getImageToDisplayForward: function (startId) {
- var startIdx = this.store.findExact("id", startId);
-
- if (startIdx === -1) {
- startIdx = 0;
- } else {
- startIdx++;
- }
-
- for (var i=startIdx;i<this.store.count();i++) {
- if (this.store.getAt(i).get("image")) {
- return this.store.getAt(i).get("id");
- }
- }
-
- return -1;
- },
- /**
- * Returns the previous image in the attachment store
- * @param startId The start ID
- * @returns int An attachment id, or -1 of none was found
- */
- getImageToDisplayBackward: function (startId) {
- var startIdx = this.store.findExact("id", startId);
-
- if (startIdx >= this.store.count()) {
- startIdx = this.store.count()-1;
- } else {
- startIdx--;
- }
-
- for (var i=startIdx;i>-1;i--) {
- if (this.store.getAt(i).get("image")) {
- return this.store.getAt(i).get("id");
- }
- }
-
- return -1;
- }
+ extend: 'Ext.panel.Panel',
+
+ displayedImageIndex: 0,
+ maxImageWidth: 200,
+ maxImageHeight: 150,
+
+ layout: 'hbox',
+ border: false,
+
+ /**
+ * Initializes the component and creates all widgets.
+ */
+ initComponent: function ()
+ {
+
+ this.store = Ext.create("Ext.data.ChainedStore");
+
+ this.prevButton = Ext.create("Ext.button.Button", {
+ text: '<',
+ width: 20,
+ height: this.maxImageHeight,
+ handler: this.onPreviousClick,
+ scope: this
+ });
+
+ this.nextButton = Ext.create("Ext.button.Button", {
+ text: '>',
+ width: 20,
+ height: this.maxImageHeight,
+ handler: this.onNextClick,
+ scope: this
+ });
+
+ this.imageDisplay = Ext.create("Ext.container.Container", {
+ height: this.maxImageHeight,
+ width: this.maxImageWidth,
+ style: 'align: center'
+ });
+
+ this.items = [this.prevButton, this.imageDisplay, this.nextButton];
+
+ this.tpl = new Ext.XTemplate('<img src="{image}/getFile"/>');
+
+ this.callParent();
+ },
+ /**
+ * Sets the stored when a new part is selected.
+ * @param store The store
+ */
+ setStore: function (store)
+ {
+ this.store.setSource(store);
+
+ this.store.setRemoteFilter(false);
+
+ this.store.addFilter({
+ property: "isImage",
+ operator: "=",
+ value: true
+ });
+
+ this.displayedImageIndex = 0;
+ this.setImage();
+ },
+ /**
+ * Sets the image
+ * @param id The attachment ID to set
+ */
+ setImage: function ()
+ {
+ var image = this.store.getAt(this.displayedImageIndex);
+
+ if (image) {
+ this.tpl.overwrite(this.imageDisplay.getEl(), {image: image.getId()});
+ }
+ },
+ /**
+ * Handler for the "next" button
+ */
+ onNextClick: function ()
+ {
+ if (this.displayedImageIndex < this.store.getCount()) {
+ this.displayedImageIndex++;
+ }
+
+ this.setImage();
+ },
+ /**
+ * Handler for the "previous" button
+ */
+ onPreviousClick: function ()
+ {
+ if (this.displayedImageIndex > 0) {
+ this.displayedImageIndex--;
+ }
+
+ this.setImage();
+ }
});
\ No newline at end of file
diff --git a/src/PartKeepr/PartBundle/Entity/PartAttachment.php b/src/PartKeepr/PartBundle/Entity/PartAttachment.php
@@ -3,6 +3,7 @@ namespace PartKeepr\PartBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use PartKeepr\UploadedFileBundle\Entity\UploadedFile;
+use Symfony\Component\Serializer\Annotation\Groups;
/**
* Holds a part attachment
@@ -14,7 +15,7 @@ class PartAttachment extends UploadedFile
/**
* Defines if the attachment is an image.
* @ORM\Column(type="boolean",nullable=true)
- *
+ * @Groups({"default"})
* @var boolean
*/
private $isImage;
@@ -62,9 +63,8 @@ class PartAttachment extends UploadedFile
*
* @return True if the attachment is an image, false otherwise
*/
- public function isImage()
+ public function getIsImage()
{
- //@todo: Reimplement check if attachment is an image
- return false;
+ return $this->isImage;
}
}