auguriaInteractiveImage - Version 0.0.1

Version Notes

First version of the extension. Free Auguria_Core extension required.

Download this release

Release Info

Developer Auguria
Extension auguriaInteractiveImage
Version 0.0.1
Comparing to
See all releases


Version 0.0.1

Files changed (33) hide show
  1. app/code/community/Auguria/InteractiveImage/Block/Adminhtml/Catalog/Product/Helper/Form/Image/Interactive.php +82 -0
  2. app/code/community/Auguria/InteractiveImage/Block/Adminhtml/Catalog/Product/Helper/Form/Image/Interactive/Panel/Area/Default.php +11 -0
  3. app/code/community/Auguria/InteractiveImage/Block/Adminhtml/Catalog/Product/Helper/Form/Image/Interactive/Panel/Areas.php +98 -0
  4. app/code/community/Auguria/InteractiveImage/Block/Adminhtml/Catalog/Product/Helper/Form/Image/Interactive/Popin.php +50 -0
  5. app/code/community/Auguria/InteractiveImage/Block/Catalog/Product/Image.php +186 -0
  6. app/code/community/Auguria/InteractiveImage/Helper/Config.php +24 -0
  7. app/code/community/Auguria/InteractiveImage/Helper/Data.php +33 -0
  8. app/code/community/Auguria/InteractiveImage/Model/Catalog/Product/Attribute/Backend/Image.php +94 -0
  9. app/code/community/Auguria/InteractiveImage/controllers/Adminhtml/Auguria/InteractiveImage/ImageController.php +111 -0
  10. app/code/community/Auguria/InteractiveImage/controllers/Checkout/Cart/AjaxController.php +164 -0
  11. app/code/community/Auguria/InteractiveImage/controllers/Checkout/CartController.php +164 -0
  12. app/code/community/Auguria/InteractiveImage/etc/adminhtml.xml +30 -0
  13. app/code/community/Auguria/InteractiveImage/etc/config.xml +111 -0
  14. app/code/community/Auguria/InteractiveImage/etc/jstranslator.xml +14 -0
  15. app/code/community/Auguria/InteractiveImage/etc/system.xml +45 -0
  16. app/code/community/Auguria/InteractiveImage/sql/auguria_interactiveimage_setup/install-0.0.1.php +37 -0
  17. app/design/adminhtml/default/default/layout/auguria/interactive_image.xml +35 -0
  18. app/design/adminhtml/default/default/template/auguria/interactiveimage/catalog/product/helper/form/image/interactive/panel/area/default.phtml +46 -0
  19. app/design/adminhtml/default/default/template/auguria/interactiveimage/catalog/product/helper/form/image/interactive/panel/areas.phtml +25 -0
  20. app/design/adminhtml/default/default/template/auguria/interactiveimage/catalog/product/helper/form/image/interactive/popin.phtml +35 -0
  21. app/design/frontend/base/default/layout/auguria/interactive_image.xml +26 -0
  22. app/design/frontend/base/default/template/auguria/interactiveimage/catalog/product/image.phtml +126 -0
  23. app/etc/modules/Auguria_InteractiveImage.xml +20 -0
  24. app/locale/en_US/Auguria_InteractiveImage.csv +0 -0
  25. app/locale/fr_FR/Auguria_InteractiveImage.csv +14 -0
  26. js/auguria/interactiveimage/cart.js +11 -0
  27. js/auguria/interactiveimage/image.js +357 -0
  28. js/auguria/interactiveimage/jquery-1.10.2.min.js +7 -0
  29. js/auguria/interactiveimage/jquery.maphilight.min.js +1 -0
  30. js/auguria/interactiveimage/kinetic-v4.5.4.min.js +4 -0
  31. package.xml +28 -0
  32. skin/adminhtml/default/default/auguria/interactiveimage/image.css +25 -0
  33. skin/frontend/base/default/css/auguria/interactiveimage/image.css +20 -0
app/code/community/Auguria/InteractiveImage/Block/Adminhtml/Catalog/Product/Helper/Form/Image/Interactive.php ADDED
@@ -0,0 +1,82 @@
1
+ <?php
2
+ /**
3
+ * @category Auguria
4
+ * @package Auguria_InteractiveImage
5
+ * @author Auguria
6
+ * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3)
7
+ */
8
+
9
+ class Auguria_InteractiveImage_Block_Adminhtml_Catalog_Product_Helper_Form_Image_Interactive extends Mage_Adminhtml_Block_Catalog_Product_Helper_Form_Image
10
+ {
11
+ /**
12
+ * Override getValue method
13
+ *
14
+ * @return string : path of the image
15
+ */
16
+ public function getValue()
17
+ {
18
+ $array = $this->getJsonValue();
19
+
20
+ return $array['image_path'];
21
+ }
22
+
23
+ /**
24
+ * Get json value
25
+ *
26
+ * @param bool $asArray
27
+ * @return mixed|array|string
28
+ */
29
+ public function getJsonValue($asArray = true)
30
+ {
31
+ $string = $this->getData('value');
32
+
33
+ if($asArray){
34
+ return Mage::helper('core')->jsonDecode($string);
35
+ }
36
+
37
+ return $string;
38
+ }
39
+
40
+ /**
41
+ * Get areas value
42
+ *
43
+ * @param bool $asArray
44
+ * @return mixed|array|string
45
+ */
46
+ public function getAreas($asArray = true)
47
+ {
48
+ $attributeValue = $this->getJsonValue();
49
+ $areas = is_array($attributeValue) && array_key_exists('areas', $attributeValue) ? $attributeValue['areas'] : array();
50
+
51
+ if($asArray){
52
+ return $areas;
53
+ }else{
54
+ return Mage::helper('core')->jsonEncode($areas);
55
+ }
56
+ }
57
+
58
+ /**
59
+ * Return element html code
60
+ *
61
+ * @return string
62
+ */
63
+ public function getElementHtml()
64
+ {
65
+ $html = parent::getElementHtml();
66
+
67
+ $areas = $this->getAreas(false); // json encoded
68
+ $imageUrl = $this->_getUrl();
69
+
70
+ $params = $this->getJsonValue(false); // json encoded
71
+ $parameters = $params ? $params : '\'\'';
72
+
73
+ $html .= '
74
+ <div class="clear"></div>
75
+ <input type="hidden" id="' . $this->getName() . '_areas" name="product['. $this->getName() . '][areas]" value="' . $areas . '"/>
76
+ <script type="text/javascript">var interactiveImage = new InteractiveImage(\'' . $imageUrl . '\', ' . $parameters . ');</script>
77
+ <button type="button" onclick="interactiveImage.display();return false;">' . Mage::helper('auguria_interactiveimage')->__('Define areas') . '</button>
78
+ ';
79
+
80
+ return $html;
81
+ }
82
+ }
app/code/community/Auguria/InteractiveImage/Block/Adminhtml/Catalog/Product/Helper/Form/Image/Interactive/Panel/Area/Default.php ADDED
@@ -0,0 +1,11 @@
1
+ <?php
2
+ /**
3
+ * @category Auguria
4
+ * @package Auguria_InteractiveImage
5
+ * @author Auguria
6
+ * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3)
7
+ */
8
+
9
+ class Auguria_InteractiveImage_Block_Adminhtml_Catalog_Product_Helper_Form_Image_Interactive_Panel_Area_Default extends Mage_Core_Block_Template
10
+ {
11
+ }
app/code/community/Auguria/InteractiveImage/Block/Adminhtml/Catalog/Product/Helper/Form/Image/Interactive/Panel/Areas.php ADDED
@@ -0,0 +1,98 @@
1
+ <?php
2
+ /**
3
+ * @category Auguria
4
+ * @package Auguria_InteractiveImage
5
+ * @author Auguria
6
+ * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3)
7
+ */
8
+
9
+ class Auguria_InteractiveImage_Block_Adminhtml_Catalog_Product_Helper_Form_Image_Interactive_Panel_Areas extends Mage_Core_Block_Template
10
+ {
11
+ protected $_areas;
12
+
13
+ protected $_areaRenders = array();
14
+
15
+ public function __construct()
16
+ {
17
+ parent::__construct();
18
+ $this->addAreaRenderer(
19
+ 'default',
20
+ 'auguria_interactiveimage/adminhtml_catalog_product_helper_form_image_interactive_panel_area_default',
21
+ 'auguria/interactiveimage/catalog/product/helper/form/image/interactive/panel/area/default.phtml'
22
+ );
23
+ }
24
+
25
+ /**
26
+ * Retrieve area
27
+ *
28
+ * @return array
29
+ */
30
+ public function getAreas()
31
+ {
32
+ return $this->_areas;
33
+ }
34
+
35
+ /**
36
+ * Set area
37
+ *
38
+ * @param array $area
39
+ * @return Auguria_InteractiveImage_Block_Adminhtml_Catalog_Product_Helper_Form_Image_Interactive_Panel_Areas
40
+ */
41
+ public function setAreas(array $areas = null)
42
+ {
43
+ $this->_areas = $areas;
44
+ return $this;
45
+ }
46
+
47
+ /**
48
+ * Add area renderer to renderers array
49
+ *
50
+ * @param string $type
51
+ * @param string $block
52
+ * @param string $template
53
+ * @return Auguria_InteractiveImage_Block_Adminhtml_Catalog_Product_Helper_Form_Image_Interactive_Panel_Areas
54
+ */
55
+ public function addAreaRenderer($type, $block, $template)
56
+ {
57
+ $this->_areaRenders[$type] = array(
58
+ 'block' => $block,
59
+ 'template' => $template,
60
+ 'renderer' => null
61
+ );
62
+ return $this;
63
+ }
64
+
65
+ /**
66
+ * Get area render by given type
67
+ *
68
+ * @param string $type
69
+ * @return array
70
+ */
71
+ public function getAreaRender($type)
72
+ {
73
+ if (isset($this->_areaRenders[$type])) {
74
+ return $this->_areaRenders[$type];
75
+ }
76
+
77
+ return $this->_areaRenders['default'];
78
+ }
79
+
80
+ /**
81
+ * Get option html block
82
+ *
83
+ * @param array $area
84
+ */
85
+ public function getAreaHtml(array $area)
86
+ {
87
+ $renderer = $this->_areaRenders[$area['render']];
88
+
89
+ if (is_null($renderer['renderer'])) {
90
+ $renderer['renderer'] = $this->getLayout()->createBlock($renderer['block'])
91
+ ->setTemplate($renderer['template']);
92
+ }
93
+
94
+ return $renderer['renderer']
95
+ ->setInteractiveArea($area) // "area" reserved name
96
+ ->toHtml();
97
+ }
98
+ }
app/code/community/Auguria/InteractiveImage/Block/Adminhtml/Catalog/Product/Helper/Form/Image/Interactive/Popin.php ADDED
@@ -0,0 +1,50 @@
1
+ <?php
2
+ /**
3
+ * @category Auguria
4
+ * @package Auguria_InteractiveImage
5
+ * @author Auguria
6
+ * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3)
7
+ */
8
+
9
+ class Auguria_InteractiveImage_Block_Adminhtml_Catalog_Product_Helper_Form_Image_Interactive_Popin extends Mage_Core_Block_Template
10
+ {
11
+ /**
12
+ * Get edition interface parameters
13
+ *
14
+ * @var null|array
15
+ */
16
+ protected $_params = null;
17
+
18
+ /**
19
+ * Initialise parameters
20
+ *
21
+ * @param array $params
22
+ * @return Auguria_InteractiveImage_Block_Adminhtml_Catalog_Product_Helper_Form_Image_Interactive_Popin
23
+ */
24
+ public function setParams(array $params)
25
+ {
26
+ $this->_params = $params;
27
+ return $this;
28
+ }
29
+
30
+ /**
31
+ * Get parameters
32
+ *
33
+ * @return null|array
34
+ */
35
+ public function getParams()
36
+ {
37
+ return $this->_params;
38
+ }
39
+
40
+ /**
41
+ * Get image properties
42
+ *
43
+ * @return array
44
+ */
45
+ public function getImage()
46
+ {
47
+ return array('url' => $this->_params['image_url'], 'size' => getimagesize($this->_params['image_url']));
48
+ }
49
+
50
+ }
app/code/community/Auguria/InteractiveImage/Block/Catalog/Product/Image.php ADDED
@@ -0,0 +1,186 @@
1
+ <?php
2
+ /**
3
+ * @category Auguria
4
+ * @package Auguria_InteractiveImage
5
+ * @author Auguria
6
+ * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3)
7
+ */
8
+
9
+ class Auguria_InteractiveImage_Block_Catalog_Product_Image extends Mage_Core_Block_Template
10
+ {
11
+ protected $_imageUrl;
12
+ protected $_imageSize;
13
+ protected $_areas;
14
+ protected $_products;
15
+ protected $_productsBySku;
16
+ protected $_positions;
17
+
18
+ /**
19
+ * Get image url
20
+ *
21
+ * @return string
22
+ */
23
+ public function getInteractiveImage()
24
+ {
25
+ if(!$this->_imageUrl){
26
+ $values = Mage::helper('core')->jsonDecode($this->getProduct()->getData('auguria_interactiveimage_image'));
27
+ // image
28
+ if(!empty($values['image_path'])){
29
+ $this->_imageUrl = Mage::getSingleton('catalog/product_media_config')->getBaseMediaUrl() . '/' . $values['image_path'];
30
+
31
+ $sizes = getimagesize($this->_imageUrl);
32
+ $this->_imageSize = array('width' => $sizes[0], 'height' => $sizes[1]);
33
+ }
34
+
35
+ // areas
36
+ if(!empty($values['areas'])){
37
+ $this->_areas = Mage::helper('core')->jsonDecode($values['areas']);
38
+ }
39
+ }
40
+
41
+ return $this->_imageUrl;
42
+ }
43
+
44
+ /**
45
+ * Get image size
46
+ *
47
+ * @return null|array
48
+ */
49
+ public function getInteractiveImageSize()
50
+ {
51
+ return $this->_imageSize;
52
+ }
53
+
54
+ /**
55
+ * Get areas
56
+ *
57
+ * @return array
58
+ */
59
+ public function getAreas()
60
+ {
61
+ return $this->_areas;
62
+ }
63
+
64
+ /**
65
+ * Retrieve current product model
66
+ *
67
+ * @return Mage_Catalog_Model_Product
68
+ */
69
+ public function getProduct()
70
+ {
71
+ return Mage::registry('product');
72
+ }
73
+
74
+ /**
75
+ * Get area coords
76
+ *
77
+ * @param array $area
78
+ * @return array
79
+ */
80
+ public function getCoords($area)
81
+ {
82
+ $coords = array();
83
+
84
+ if($area['type'] == 'rect'){
85
+ $x2 = $area['size']['x'] + $area['size']['width'];
86
+ $y2 = $area['size']['y'] + $area['size']['height'];
87
+ $coords['area'] = $area['size']['x'] . ',' . $area['size']['y'] . ',' . $x2 . ',' . $y2;
88
+ $coords['tooltip'] = array('top' => -($this->_imageSize['height'] - $area['size']['y']), 'left' => $x2 + 10);
89
+ }
90
+
91
+ return $coords;
92
+ }
93
+
94
+ /**
95
+ * Get product associated with areas
96
+ *
97
+ * @return Mage_Catalog_Model_Resource_Product_Collection
98
+ */
99
+ public function getProducts()
100
+ {
101
+ if(!$this->_products){
102
+ $ids = array();
103
+
104
+ $product = Mage::getSingleton('catalog/product');
105
+ if($this->_areas){
106
+ foreach ($this->_areas as $_area){
107
+ $ids[] = $product->getIdBySku($_area['sku']);
108
+ $this->_positions[$_area['sku']] = $_area['position'];
109
+ }
110
+ }
111
+
112
+ $this->_products = Mage::getResourceModel('catalog/product_collection')
113
+ ->addAttributeToSelect(array('name', 'sku'))
114
+ ->addFieldToFilter('entity_id', array('in' => $ids))
115
+ ->addFinalPrice()
116
+ ->addStoreFilter(Mage::app()->getStore());
117
+
118
+ // get easily product by without reload them
119
+ foreach ($this->_products as $_product){
120
+ $this->_productsBySku[$_product->getSku()] = $_product;
121
+ }
122
+ }
123
+
124
+ return $this->_products;
125
+ }
126
+
127
+ /**
128
+ * Get product by sku
129
+ *
130
+ * @param string $sku
131
+ * @return Mage_Catalog_Model_Product
132
+ */
133
+ public function getProductBySku($sku)
134
+ {
135
+ return is_array($this->_productsBySku) && array_key_exists($sku, $this->_productsBySku) ? $this->_productsBySku[$sku] : null;
136
+ }
137
+
138
+ /**
139
+ * Get product position by sku
140
+ *
141
+ * @param string $sku
142
+ */
143
+ public function getPositionBySku($sku)
144
+ {
145
+ return $this->_positions[$sku];
146
+ }
147
+
148
+ /**
149
+ * Retrieve url for direct adding product to cart
150
+ *
151
+ * @param string $sku
152
+ * @param array $additional
153
+ * @return string
154
+ */
155
+ public function getAddToCartUrl($sku, $additional = array())
156
+ {
157
+ if ($this->getRequest()->getParam('wishlist_next')){
158
+ $additional['wishlist_next'] = 1;
159
+ }
160
+
161
+ $addUrlKey = Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED;
162
+ $addUrlValue = Mage::getUrl('*/*/*', array('_use_rewrite' => true, '_current' => true));
163
+ $additional[$addUrlKey] = Mage::helper('core')->urlEncode($addUrlValue);
164
+
165
+ // no product load
166
+ $product = Mage::getModel('catalog/product');
167
+ $id = Mage::getModel('catalog/product')->getIdBySku($sku);
168
+ $product->setId($id);
169
+
170
+ return $this->helper('checkout/cart')->getAddUrl($product, $additional);
171
+ }
172
+
173
+ /**
174
+ * Retrieve url for direct adding product to cart
175
+ *
176
+ * @return string
177
+ */
178
+ public function getMassAddToCartUrl()
179
+ {
180
+ $addUrlKey = Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED;
181
+ $addUrlValue = Mage::getUrl('*/*/*', array('_use_rewrite' => true, '_current' => true));
182
+ $additional[$addUrlKey] = Mage::helper('core')->urlEncode($addUrlValue);
183
+
184
+ return Mage::getUrl('image/checkout_cart/add', $additional);
185
+ }
186
+ }
app/code/community/Auguria/InteractiveImage/Helper/Config.php ADDED
@@ -0,0 +1,24 @@
1
+ <?php
2
+ /**
3
+ * @category Auguria
4
+ * @package Auguria_InteractiveImage
5
+ * @author Auguria
6
+ * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3)
7
+ */
8
+
9
+ class Auguria_InteractiveImage_Helper_Config extends Mage_Core_Helper_Abstract {
10
+
11
+ /* PATH TO CONFIGURATION */
12
+ const XML_PATH_INTERACTIVE_IMAGE_USE_AJAX = 'auguria_interactiveimage/general/use_ajax';
13
+
14
+ /**
15
+ * Check if ajax must be used
16
+ *
17
+ * @return bool
18
+ */
19
+ public function useAjax()
20
+ {
21
+ return Mage::helper('core')->isModuleEnabled('Auguria_CartAjax') && Mage::getStoreConfigFlag(self::XML_PATH_INTERACTIVE_IMAGE_USE_AJAX);
22
+ }
23
+
24
+ }
app/code/community/Auguria/InteractiveImage/Helper/Data.php ADDED
@@ -0,0 +1,33 @@
1
+ <?php
2
+ /**
3
+ * @category Auguria
4
+ * @package Auguria_InteractiveImage
5
+ * @author Auguria
6
+ * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3)
7
+ */
8
+
9
+ class Auguria_InteractiveImage_Helper_Data extends Mage_Core_Helper_Abstract {
10
+
11
+ /**
12
+ * Get the full image path by attribute path saved
13
+ *
14
+ * @param string $attributeImagePath
15
+ * @return string
16
+ */
17
+ public function getFullImagePath($attributeImagePath)
18
+ {
19
+ return Mage::getBaseDir('media') . DS . 'catalog' . DS . 'product' . DS . $attributeImagePath;
20
+ }
21
+
22
+ /**
23
+ * Get the full image url by attribute path saved
24
+ *
25
+ * @param string $attributeImagePath
26
+ * @return string
27
+ */
28
+ public function getFullImageUrl($attributeImagePath)
29
+ {
30
+ return Mage::getBaseUrl('media') . 'catalog/product/' . $attributeImagePath;
31
+ }
32
+
33
+ }
app/code/community/Auguria/InteractiveImage/Model/Catalog/Product/Attribute/Backend/Image.php ADDED
@@ -0,0 +1,94 @@
1
+ <?php
2
+ /**
3
+ * @category Auguria
4
+ * @package Auguria_Core
5
+ * @author Auguria
6
+ * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3)
7
+ */
8
+
9
+ class Auguria_InteractiveImage_Model_Catalog_Product_Attribute_Backend_Image extends Auguria_Core_Model_Attribute_Backend_Image_Abstract
10
+ {
11
+ /**
12
+ * Default format/value for the attribute
13
+ *
14
+ * @var array
15
+ */
16
+ protected $_defaultValue = array('image_path' => '', 'areas' => array());
17
+
18
+ /**
19
+ * Save uploaded file
20
+ *
21
+ * @param Varien_Object $object
22
+ */
23
+ public function afterSave($object)
24
+ {
25
+ $value = $object->getData($this->getAttribute()->getName());
26
+
27
+ if (is_array($value)) {
28
+ if(!empty($value['delete'])){ // delete : save default value
29
+ $object->setData($this->getAttribute()->getName(), Mage::helper('core')->jsonEncode($this->_defaultValue));
30
+ $this->getAttribute()->getEntity()
31
+ ->saveAttribute($object, $this->getAttribute()->getName());
32
+ return;
33
+ }
34
+
35
+ try {
36
+ // upload image
37
+ if(!isset($value['value']) || !file_exists($this->_getPathWithoutPrefix() . $value['value'])){
38
+ $uploader = new Mage_Core_Model_File_Uploader($this->getAttribute()->getName());
39
+ $uploader->setAllowedExtensions(array('jpg','jpeg','gif','png'));
40
+ $uploader->setAllowRenameFiles(true);
41
+ $result = $uploader->save($this->_getPath());
42
+
43
+ $value['image_path'] = $this->_getPrefix() . $result['file']; // update image path
44
+ }else{
45
+ $value['image_path'] = $value['value'];
46
+ }
47
+
48
+ $object->setData($this->getAttribute()->getName(), Mage::helper('core')->jsonEncode($value));
49
+ $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName()); // save attribute
50
+ } catch (Exception $e) {
51
+ if ($e->getCode() != Mage_Core_Model_File_Uploader::TMP_NAME_EMPTY) {
52
+ Mage::logException($e);
53
+ }
54
+
55
+ return;
56
+ }
57
+ }else{ // save default value
58
+ $object->setData($this->getAttribute()->getName(), Mage::helper('core')->jsonEncode($this->_defaultValue));
59
+ $this->getAttribute()->getEntity()
60
+ ->saveAttribute($object, $this->getAttribute()->getName());
61
+ return;
62
+ }
63
+ }
64
+
65
+ /**
66
+ * Get path to save file
67
+ *
68
+ * @return string
69
+ */
70
+ protected function _getPath()
71
+ {
72
+ return Mage::getBaseDir('media') . DS . 'catalog' . DS . 'product' . DS . 'auguria' . DS . 'interactiveimage' . DS;
73
+ }
74
+
75
+ /**
76
+ * Get prefix when save path file in attribute value
77
+ *
78
+ * @return string
79
+ */
80
+ protected function _getPrefix()
81
+ {
82
+ return 'auguria' . DS . 'interactiveimage' . DS;
83
+ }
84
+
85
+ /**
86
+ * Get path without prefix
87
+ *
88
+ * @return string
89
+ */
90
+ protected function _getPathWithoutPrefix()
91
+ {
92
+ return Mage::getBaseDir('media') . DS . 'catalog' . DS . 'product' . DS;
93
+ }
94
+ }
app/code/community/Auguria/InteractiveImage/controllers/Adminhtml/Auguria/InteractiveImage/ImageController.php ADDED
@@ -0,0 +1,111 @@
1
+ <?php
2
+ /**
3
+ * @category Auguria
4
+ * @package Auguria_InteractiveImage
5
+ * @author Auguria
6
+ * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3)
7
+ */
8
+ class Auguria_InteractiveImage_Adminhtml_Auguria_InteractiveImage_ImageController extends Mage_Adminhtml_Controller_Action
9
+ {
10
+ /**
11
+ * Additional initialization
12
+ *
13
+ */
14
+ protected function _construct()
15
+ {
16
+ $this->setUsedModuleName('Auguria_InteractiveImage');
17
+ }
18
+
19
+ /**
20
+ * Display popin and canvas with image background and image dimensions
21
+ */
22
+ public function displayAction()
23
+ {
24
+ $response = array('error' => false, 'messages' => array(), 'content' => '');
25
+ $params = Mage::helper('core')->jsonDecode($this->getRequest()->getParam('interactive_image', ''));
26
+
27
+ $fullImagePath = Mage::helper('auguria_interactiveimage')->getFullImagePath($params['image_path']);
28
+ $fullImageUrl = Mage::helper('auguria_interactiveimage')->getFullImageUrl($params['image_path']);
29
+
30
+ try {
31
+ if(file_exists($fullImagePath)){
32
+ $this->loadLayout(); // init layout messages
33
+
34
+ if(!is_array($params['areas'])){
35
+ $params['areas'] = Mage::helper('core')->jsonDecode($params['areas']);
36
+ }
37
+
38
+ $params['image_url'] = $fullImageUrl; // add full image path to params
39
+ $response['content'] = $this->getLayout()->getBlock('interactive.image.popin')->setParams($params)->toHtml();
40
+ }else{
41
+ Mage::throwException($this->__('Image not found.'));
42
+ }
43
+ } catch (Exception $e) {
44
+ $response['error'] = true;
45
+ $this->_getSession()->addException($e, $this->__('Error while loading edition interface.'));
46
+ }
47
+
48
+ if($response['error']){
49
+ // if success messages called in template
50
+ $response['messages'][Mage_Core_Model_Message::ERROR] = $this->_getSession()->getMessages(true)->getItemsByType(Mage_Core_Model_Message::ERROR); // clear messages
51
+ }
52
+
53
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response));
54
+ }
55
+
56
+ /**
57
+ * Get Panel Tab html
58
+ */
59
+ public function createPanelTabAction()
60
+ {
61
+ $response = array('error' => false, 'messages' => array(), 'content' => '');
62
+ $area = Mage::helper('core')->jsonDecode($this->getRequest()->getParam('area', ''));
63
+
64
+ try {
65
+ if($area){
66
+ $this->loadLayout(); // init layout messages
67
+
68
+ $response['content'] = $this->getLayout()->getBlock('interactive.image.panel.areas')->getAreaHtml($area);
69
+ }else{
70
+ Mage::throwException($this->__('Area does not exixsts.'));
71
+ }
72
+ } catch (Exception $e) {
73
+ $response['error'] = true;
74
+ $this->_getSession()->addException($e, $this->__('Error while adding area.'));
75
+ }
76
+
77
+ if($response['error']){
78
+ // if success messages called in template
79
+ $response['messages'][Mage_Core_Model_Message::ERROR] = $this->_getSession()->getMessages(true)->getItemsByType(Mage_Core_Model_Message::ERROR); // clear messages
80
+ }
81
+
82
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response));
83
+ }
84
+
85
+ /**
86
+ * Save form values
87
+ */
88
+ public function saveAction()
89
+ {
90
+ $response = array('error' => false, 'messages' => array(), 'content' => '');
91
+ $areas = $this->getRequest()->getParam('areas', null);
92
+
93
+ try {
94
+ if($areas){
95
+ $response['content'] = Mage::helper('core')->jsonEncode($areas);
96
+ }else{
97
+ Mage::throwException($this->__('Areas does not exixsts.'));
98
+ }
99
+ } catch (Exception $e) {
100
+ $response['error'] = true;
101
+ $this->_getSession()->addException($e, $this->__('Error while saving areas.'));
102
+ }
103
+
104
+ if($response['error']){
105
+ // if success messages called in template
106
+ $response['messages'][Mage_Core_Model_Message::ERROR] = $this->_getSession()->getMessages(true)->getItemsByType(Mage_Core_Model_Message::ERROR); // clear messages
107
+ }
108
+
109
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response));
110
+ }
111
+ }
app/code/community/Auguria/InteractiveImage/controllers/Checkout/Cart/AjaxController.php ADDED
@@ -0,0 +1,164 @@
1
+ <?php
2
+ /**
3
+ * @category Auguria
4
+ * @package Auguria_InteractiveImage
5
+ * @author Auguria
6
+ * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3)
7
+ */
8
+
9
+ class Auguria_InteractiveImage_Checkout_Cart_AjaxController extends Mage_Core_Controller_Front_Action
10
+ {
11
+ /**
12
+ * Retrieve shopping cart model object
13
+ *
14
+ * @return Mage_Checkout_Model_Cart
15
+ */
16
+ protected function _getCart()
17
+ {
18
+ return Mage::getSingleton('checkout/cart');
19
+ }
20
+
21
+ /**
22
+ * Get checkout session model instance
23
+ *
24
+ * @return Mage_Checkout_Model_Session
25
+ */
26
+ protected function _getSession()
27
+ {
28
+ return Mage::getSingleton('checkout/session');
29
+ }
30
+
31
+ /**
32
+ * Set back redirect url to response
33
+ *
34
+ * @return Mage_Checkout_CartController
35
+ */
36
+ protected function _goBack()
37
+ {
38
+ $returnUrl = $this->getRequest()->getParam('return_url');
39
+ if ($returnUrl) {
40
+
41
+ if (!$this->_isUrlInternal($returnUrl)) {
42
+ throw new Mage_Exception('External urls redirect to "' . $returnUrl . '" denied!');
43
+ }
44
+
45
+ $this->_getSession()->getMessages(true);
46
+ $this->getResponse()->setRedirect($returnUrl);
47
+ } elseif (!Mage::getStoreConfig('checkout/cart/redirect_to_cart')
48
+ && !$this->getRequest()->getParam('in_cart')
49
+ && $backUrl = $this->_getRefererUrl()
50
+ ) {
51
+ $this->getResponse()->setRedirect($backUrl);
52
+ } else {
53
+ if (($this->getRequest()->getActionName() == 'add') && !$this->getRequest()->getParam('in_cart')) {
54
+ $this->_getSession()->setContinueShoppingUrl($this->_getRefererUrl());
55
+ }
56
+ $this->_redirect('checkout/cart');
57
+ }
58
+ return $this;
59
+ }
60
+
61
+ /**
62
+ * Initialize product instance from request data
63
+ *
64
+ * @param int $productId
65
+ * @return Mage_Catalog_Model_Product || false
66
+ */
67
+ protected function _initProduct($productId)
68
+ {
69
+ if ($productId) {
70
+ $product = Mage::getModel('catalog/product')
71
+ ->setStoreId(Mage::app()->getStore()->getId())
72
+ ->load($productId);
73
+ if ($product->getId()) {
74
+ return $product;
75
+ }
76
+ }
77
+ return false;
78
+ }
79
+
80
+ /**
81
+ * Add product to shopping cart action
82
+ */
83
+ public function addAction()
84
+ {
85
+ $cart = $this->_getCart();
86
+ $params = $this->getRequest()->getParams();
87
+
88
+ try {
89
+
90
+ foreach($params['products'] as $_child){
91
+
92
+ // get required params to add in cart
93
+ $_child['uenc'] = $params['uenc'];
94
+
95
+ if (isset($_child['qty'])) {
96
+ $filter = new Zend_Filter_LocalizedToNormalized(
97
+ array('locale' => Mage::app()->getLocale()->getLocaleCode())
98
+ );
99
+ $_child['qty'] = $filter->filter($_child['qty']);
100
+ }
101
+
102
+ if(!array_key_exists('qty', $_child) || $_child['qty'] == 0){
103
+ continue; // check qty
104
+ }
105
+
106
+ $product = $this->_initProduct($_child['product']);
107
+
108
+ /**
109
+ * Check product availability
110
+ */
111
+ if (!$product) {
112
+ $this->_goBack();
113
+ return;
114
+ }
115
+
116
+ $related = $this->getRequest()->getParam('related_product');
117
+
118
+ $cart->addProduct($product, $_child);
119
+ if (!empty($related)) {
120
+ $cart->addProductsByIds(explode(',', $related));
121
+ }
122
+ }
123
+
124
+ $cart->save();
125
+
126
+ $this->_getSession()->setCartWasUpdated(true);
127
+
128
+ /**
129
+ * @todo remove wishlist observer processAddToCart
130
+ */
131
+ Mage::dispatchEvent('checkout_cart_add_product_complete',
132
+ array('product' => $product, 'request' => $this->getRequest(), 'response' => $this->getResponse())
133
+ );
134
+
135
+ if (!$this->_getSession()->getNoCartRedirect(true)) {
136
+ if (!$cart->getQuote()->getHasError()){
137
+ $message = $this->__('%s was added to your shopping cart.', Mage::helper('core')->escapeHtml($product->getName()));
138
+ $this->_getSession()->addSuccess($message);
139
+ }
140
+ $this->_goBack();
141
+ }
142
+ } catch (Mage_Core_Exception $e) {
143
+ if ($this->_getSession()->getUseNotice(true)) {
144
+ $this->_getSession()->addNotice(Mage::helper('core')->escapeHtml($e->getMessage()));
145
+ } else {
146
+ $messages = array_unique(explode("\n", $e->getMessage()));
147
+ foreach ($messages as $message) {
148
+ $this->_getSession()->addError(Mage::helper('core')->escapeHtml($message));
149
+ }
150
+ }
151
+
152
+ $url = $this->_getSession()->getRedirectUrl(true);
153
+ if ($url) {
154
+ $this->getResponse()->setRedirect($url);
155
+ } else {
156
+ $this->_redirectReferer(Mage::helper('checkout/cart')->getCartUrl());
157
+ }
158
+ } catch (Exception $e) {
159
+ $this->_getSession()->addException($e, $this->__('Cannot add the item to shopping cart.'));
160
+ Mage::logException($e);
161
+ $this->_goBack();
162
+ }
163
+ }
164
+ }
app/code/community/Auguria/InteractiveImage/controllers/Checkout/CartController.php ADDED
@@ -0,0 +1,164 @@
1
+ <?php
2
+ /**
3
+ * @category Auguria
4
+ * @package Auguria_InteractiveImage
5
+ * @author Auguria
6
+ * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3)
7
+ */
8
+
9
+ class Auguria_InteractiveImage_Checkout_CartController extends Mage_Core_Controller_Front_Action
10
+ {
11
+ /**
12
+ * Retrieve shopping cart model object
13
+ *
14
+ * @return Mage_Checkout_Model_Cart
15
+ */
16
+ protected function _getCart()
17
+ {
18
+ return Mage::getSingleton('checkout/cart');
19
+ }
20
+
21
+ /**
22
+ * Get checkout session model instance
23
+ *
24
+ * @return Mage_Checkout_Model_Session
25
+ */
26
+ protected function _getSession()
27
+ {
28
+ return Mage::getSingleton('checkout/session');
29
+ }
30
+
31
+ /**
32
+ * Set back redirect url to response
33
+ *
34
+ * @return Mage_Checkout_CartController
35
+ */
36
+ protected function _goBack()
37
+ {
38
+ $returnUrl = $this->getRequest()->getParam('return_url');
39
+ if ($returnUrl) {
40
+
41
+ if (!$this->_isUrlInternal($returnUrl)) {
42
+ throw new Mage_Exception('External urls redirect to "' . $returnUrl . '" denied!');
43
+ }
44
+
45
+ $this->_getSession()->getMessages(true);
46
+ $this->getResponse()->setRedirect($returnUrl);
47
+ } elseif (!Mage::getStoreConfig('checkout/cart/redirect_to_cart')
48
+ && !$this->getRequest()->getParam('in_cart')
49
+ && $backUrl = $this->_getRefererUrl()
50
+ ) {
51
+ $this->getResponse()->setRedirect($backUrl);
52
+ } else {
53
+ if (($this->getRequest()->getActionName() == 'add') && !$this->getRequest()->getParam('in_cart')) {
54
+ $this->_getSession()->setContinueShoppingUrl($this->_getRefererUrl());
55
+ }
56
+ $this->_redirect('checkout/cart');
57
+ }
58
+ return $this;
59
+ }
60
+
61
+ /**
62
+ * Initialize product instance from request data
63
+ *
64
+ * @param int $productId
65
+ * @return Mage_Catalog_Model_Product || false
66
+ */
67
+ protected function _initProduct($productId)
68
+ {
69
+ if ($productId) {
70
+ $product = Mage::getModel('catalog/product')
71
+ ->setStoreId(Mage::app()->getStore()->getId())
72
+ ->load($productId);
73
+ if ($product->getId()) {
74
+ return $product;
75
+ }
76
+ }
77
+ return false;
78
+ }
79
+
80
+ /**
81
+ * Add product to shopping cart action
82
+ */
83
+ public function addAction()
84
+ {
85
+ $cart = $this->_getCart();
86
+ $params = $this->getRequest()->getParams();
87
+
88
+ try {
89
+
90
+ foreach($params['products'] as $_child){
91
+
92
+ // get required params to add in cart
93
+ $_child['uenc'] = $params['uenc'];
94
+
95
+ if (isset($_child['qty'])) {
96
+ $filter = new Zend_Filter_LocalizedToNormalized(
97
+ array('locale' => Mage::app()->getLocale()->getLocaleCode())
98
+ );
99
+ $_child['qty'] = $filter->filter($_child['qty']);
100
+ }
101
+
102
+ if(!array_key_exists('qty', $_child) || $_child['qty'] == 0){
103
+ continue; // check qty
104
+ }
105
+
106
+ $product = $this->_initProduct($_child['product']);
107
+
108
+ /**
109
+ * Check product availability
110
+ */
111
+ if (!$product) {
112
+ $this->_goBack();
113
+ return;
114
+ }
115
+
116
+ $related = $this->getRequest()->getParam('related_product');
117
+
118
+ $cart->addProduct($product, $_child);
119
+ if (!empty($related)) {
120
+ $cart->addProductsByIds(explode(',', $related));
121
+ }
122
+ }
123
+
124
+ $cart->save();
125
+
126
+ $this->_getSession()->setCartWasUpdated(true);
127
+
128
+ /**
129
+ * @todo remove wishlist observer processAddToCart
130
+ */
131
+ Mage::dispatchEvent('checkout_cart_add_product_complete',
132
+ array('product' => $product, 'request' => $this->getRequest(), 'response' => $this->getResponse())
133
+ );
134
+
135
+ if (!$this->_getSession()->getNoCartRedirect(true)) {
136
+ if (!$cart->getQuote()->getHasError()){
137
+ $message = $this->__('%s was added to your shopping cart.', Mage::helper('core')->escapeHtml($product->getName()));
138
+ $this->_getSession()->addSuccess($message);
139
+ }
140
+ $this->_goBack();
141
+ }
142
+ } catch (Mage_Core_Exception $e) {
143
+ if ($this->_getSession()->getUseNotice(true)) {
144
+ $this->_getSession()->addNotice(Mage::helper('core')->escapeHtml($e->getMessage()));
145
+ } else {
146
+ $messages = array_unique(explode("\n", $e->getMessage()));
147
+ foreach ($messages as $message) {
148
+ $this->_getSession()->addError(Mage::helper('core')->escapeHtml($message));
149
+ }
150
+ }
151
+
152
+ $url = $this->_getSession()->getRedirectUrl(true);
153
+ if ($url) {
154
+ $this->getResponse()->setRedirect($url);
155
+ } else {
156
+ $this->_redirectReferer(Mage::helper('checkout/cart')->getCartUrl());
157
+ }
158
+ } catch (Exception $e) {
159
+ $this->_getSession()->addException($e, $this->__('Cannot add the item to shopping cart.'));
160
+ Mage::logException($e);
161
+ $this->_goBack();
162
+ }
163
+ }
164
+ }
app/code/community/Auguria/InteractiveImage/etc/adminhtml.xml ADDED
@@ -0,0 +1,30 @@
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * @category Auguria
5
+ * @package Auguria_InteractiveImage
6
+ * @author Auguria
7
+ * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3)
8
+ */
9
+ -->
10
+ <config>
11
+ <acl>
12
+ <resources>
13
+ <admin>
14
+ <children>
15
+ <system>
16
+ <children>
17
+ <config>
18
+ <children>
19
+ <auguria_interactiveimage translate="title" module="auguria_interactiveimage">
20
+ <title>Auguria interactive image</title>
21
+ </auguria_interactiveimage>
22
+ </children>
23
+ </config>
24
+ </children>
25
+ </system>
26
+ </children>
27
+ </admin>
28
+ </resources>
29
+ </acl>
30
+ </config>
app/code/community/Auguria/InteractiveImage/etc/config.xml ADDED
@@ -0,0 +1,111 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--
3
+ /**
4
+ * @category Auguria
5
+ * @package Auguria_InteractiveImage
6
+ * @author Auguria
7
+ * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3)
8
+ */
9
+ -->
10
+ <config>
11
+
12
+ <modules>
13
+ <Auguria_InteractiveImage>
14
+ <version>0.0.1</version>
15
+ </Auguria_InteractiveImage>
16
+ </modules>
17
+
18
+ <global>
19
+ <resources>
20
+ <auguria_interactiveimage_setup>
21
+ <setup>
22
+ <module>Auguria_InteractiveImage</module>
23
+ <class>Mage_Catalog_Model_Resource_Setup</class>
24
+ </setup>
25
+ </auguria_interactiveimage_setup>
26
+ </resources>
27
+ <blocks>
28
+ <auguria_interactiveimage>
29
+ <class>Auguria_InteractiveImage_Block</class>
30
+ </auguria_interactiveimage>
31
+ </blocks>
32
+ <helpers>
33
+ <auguria_interactiveimage>
34
+ <class>Auguria_InteractiveImage_Helper</class>
35
+ </auguria_interactiveimage>
36
+ </helpers>
37
+ <models>
38
+ <auguria_interactiveimage>
39
+ <class>Auguria_InteractiveImage_Model</class>
40
+ </auguria_interactiveimage>
41
+ </models>
42
+ </global>
43
+
44
+ <frontend>
45
+ <routers>
46
+ <auguria_interactiveimage>
47
+ <use>standard</use>
48
+ <args>
49
+ <module>Auguria_InteractiveImage</module>
50
+ <frontName>image</frontName>
51
+ </args>
52
+ </auguria_interactiveimage>
53
+ </routers>
54
+ <layout>
55
+ <updates>
56
+ <auguria_interactiveimage>
57
+ <file>auguria/interactive_image.xml</file>
58
+ </auguria_interactiveimage>
59
+ </updates>
60
+ </layout>
61
+ <translate>
62
+ <modules>
63
+ <Auguria_InteractiveImage>
64
+ <files>
65
+ <default>Auguria_InteractiveImage.csv</default>
66
+ </files>
67
+ </Auguria_InteractiveImage>
68
+ </modules>
69
+ </translate>
70
+ </frontend>
71
+
72
+ <admin>
73
+ <routers>
74
+ <adminhtml>
75
+ <args>
76
+ <modules>
77
+ <auguria_interactiveimage before="Mage_Adminhtml">Auguria_InteractiveImage_Adminhtml</auguria_interactiveimage>
78
+ </modules>
79
+ </args>
80
+ </adminhtml>
81
+ </routers>
82
+ </admin>
83
+
84
+ <adminhtml>
85
+ <layout>
86
+ <updates>
87
+ <auguria_interactiveimage>
88
+ <file>auguria/interactive_image.xml</file>
89
+ </auguria_interactiveimage>
90
+ </updates>
91
+ </layout>
92
+ <translate>
93
+ <modules>
94
+ <Auguria_InteractiveImage>
95
+ <files>
96
+ <default>Auguria_InteractiveImage.csv</default>
97
+ </files>
98
+ </Auguria_InteractiveImage>
99
+ </modules>
100
+ </translate>
101
+ </adminhtml>
102
+
103
+ <default>
104
+ <auguria_interactiveimage>
105
+ <general>
106
+ <use_ajax>0</use_ajax>
107
+ </general>
108
+ </auguria_interactiveimage>
109
+ </default>
110
+
111
+ </config>
app/code/community/Auguria/InteractiveImage/etc/jstranslator.xml ADDED
@@ -0,0 +1,14 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--
3
+ /**
4
+ * @category Auguria
5
+ * @package Auguria_InteractiveImage
6
+ * @author Auguria
7
+ * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3)
8
+ */
9
+ -->
10
+ <jstranslator>
11
+ <alert-display-image-url-undefined translate="message" module="auguria_interactiveimage">
12
+ <message>Complete</message>
13
+ </alert-display-image-url-undefined>
14
+ </jstranslator>
app/code/community/Auguria/InteractiveImage/etc/system.xml ADDED
@@ -0,0 +1,45 @@
1
+ <!--
2
+ /**
3
+ * @category Auguria
4
+ * @package Auguria_InteractiveImage
5
+ * @author Auguria
6
+ * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3)
7
+ */
8
+ -->
9
+ <config>
10
+ <sections>
11
+ <auguria_interactiveimage translate="label" module="auguria_interactiveimage">
12
+ <label>Interactive image</label>
13
+ <tab>auguria</tab>
14
+ <header_css>auguria-header</header_css>
15
+ <frontend_type>text</frontend_type>
16
+ <sort_order>300</sort_order>
17
+ <show_in_default>1</show_in_default>
18
+ <show_in_website>1</show_in_website>
19
+ <show_in_store>0</show_in_store>
20
+ <groups>
21
+ <general translate="label">
22
+ <label>General</label>
23
+ <frontend_type>text</frontend_type>
24
+ <sort_order>1</sort_order>
25
+ <show_in_default>1</show_in_default>
26
+ <show_in_website>1</show_in_website>
27
+ <show_in_store>0</show_in_store>
28
+ <fields>
29
+ <use_ajax translate="label comment">
30
+ <label>Use ajax for adding product to cart</label>
31
+ <comment>Module Auguria_CartAjax must be enabled</comment>
32
+ <frontend_type>select</frontend_type>
33
+ <source_model>adminhtml/system_config_source_yesno</source_model>
34
+ <sort_order>1</sort_order>
35
+ <show_in_default>1</show_in_default>
36
+ <show_in_website>1</show_in_website>
37
+ <show_in_store>0</show_in_store>
38
+ <if_module_enabled>Auguria_CartAjax</if_module_enabled>
39
+ </use_ajax>
40
+ </fields>
41
+ </general>
42
+ </groups>
43
+ </auguria_interactiveimage>
44
+ </sections>
45
+ </config>
app/code/community/Auguria/InteractiveImage/sql/auguria_interactiveimage_setup/install-0.0.1.php ADDED
@@ -0,0 +1,37 @@
1
+ <?php
2
+ /**
3
+ * @category Auguria
4
+ * @package Auguria_InteractiveImage
5
+ * @author Auguria
6
+ * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3)
7
+ */
8
+
9
+ /* @var $this Mage_Catalog_Model_Resource_Setup */
10
+
11
+ // Create new attribute group ( render attribute element correctly )
12
+ $entityTypeId = $this->getEntityTypeId('catalog_product');
13
+
14
+ // add group for each existing attribute set
15
+ $attributeSets = $this->_conn->fetchAll('select * from '.$this->getTable('eav/attribute_set').' where entity_type_id=?', $entityTypeId);
16
+ foreach ($attributeSets as $attributeSet) {
17
+ $setId = $attributeSet['attribute_set_id'];
18
+ $this->addAttributeGroup($entityTypeId, $setId, 'Interactive image');
19
+ }
20
+
21
+ // auguria_matrix_active : define if the matrix can be displayed on the product view page
22
+ $this->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'auguria_interactiveimage_image', array(
23
+ 'group' => 'Interactive image',
24
+ 'type' => 'text',
25
+ 'backend' => 'auguria_interactiveimage/catalog_product_attribute_backend_image',
26
+ 'frontend' => '',
27
+ 'label' => 'Interactive image',
28
+ 'input' => 'image',
29
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
30
+ 'visible' => true,
31
+ 'required' => false,
32
+ 'user_defined' => false,
33
+ 'default' => '',
34
+ 'input_renderer' => 'auguria_interactiveimage/adminhtml_catalog_product_helper_form_image_interactive',
35
+ 'visible_on_front' => false,
36
+ 'used_in_product_listing' => true
37
+ ));
app/design/adminhtml/default/default/layout/auguria/interactive_image.xml ADDED
@@ -0,0 +1,35 @@
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * @category Auguria
5
+ * @package Auguria_InteractiveImage
6
+ * @author Auguria
7
+ * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3)
8
+ */
9
+ -->
10
+
11
+ <layout>
12
+
13
+ <adminhtml_catalog_product_edit>
14
+ <reference name="head">
15
+ <action method="addJs"><link>auguria/interactiveimage/kinetic-v4.5.4.min.js</link></action>
16
+ <action method="addJs"><link>auguria/interactiveimage/image.js</link></action>
17
+ <action method="addCss"><link>auguria/interactiveimage/image.css</link></action>
18
+ </reference>
19
+ </adminhtml_catalog_product_edit>
20
+
21
+ <adminhtml_auguria_interactiveimage_image_display>
22
+ <reference name="content">
23
+ <block type="auguria_interactiveimage/adminhtml_catalog_product_helper_form_image_interactive_popin" name="interactive.image.popin" template="auguria/interactiveimage/catalog/product/helper/form/image/interactive/popin.phtml">
24
+ <block type="auguria_interactiveimage/adminhtml_catalog_product_helper_form_image_interactive_panel_areas" name="interactive.image.panel.areas" template="auguria/interactiveimage/catalog/product/helper/form/image/interactive/panel/areas.phtml">
25
+ </block>
26
+ </block>
27
+ </reference>
28
+ </adminhtml_auguria_interactiveimage_image_display>
29
+
30
+ <adminhtml_auguria_interactiveimage_image_createpaneltab>
31
+ <block type="auguria_interactiveimage/adminhtml_catalog_product_helper_form_image_interactive_panel_areas" name="interactive.image.panel.areas" template="auguria/interactiveimage/catalog/product/helper/form/image/interactive/panel/areas.phtml">
32
+ </block>
33
+ </adminhtml_auguria_interactiveimage_image_createpaneltab>
34
+
35
+ </layout>
app/design/adminhtml/default/default/template/auguria/interactiveimage/catalog/product/helper/form/image/interactive/panel/area/default.phtml ADDED
@@ -0,0 +1,46 @@
1
+ <?php
2
+ /**
3
+ * @category Auguria
4
+ * @package Auguria_InteractiveImage
5
+ * @author Auguria
6
+ * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3)
7
+ */
8
+
9
+ /* @var $this Auguria_InteractiveImage_Block_Adminhtml_Catalog_Product_Helper_Form_Image_Interactive_Panel_Area_Default */
10
+ ?>
11
+ <?php
12
+ $area = $this->getInteractiveArea();
13
+ ?>
14
+
15
+ <fieldset id="fieldset-<?php echo $area['id']?>" class="area">
16
+ <input type="hidden" name="areas[<?php echo $area['id']?>][id]" value="<?php echo $area['id']?>">
17
+ <input type="hidden" name="areas[<?php echo $area['id']?>][size][x]" value="<?php echo $area['size']['x']?>">
18
+ <input type="hidden" name="areas[<?php echo $area['id']?>][size][y]" value="<?php echo $area['size']['y']?>">
19
+ <input type="hidden" name="areas[<?php echo $area['id']?>][size][width]" value="<?php echo $area['size']['width']?>">
20
+ <input type="hidden" name="areas[<?php echo $area['id']?>][size][height]" value="<?php echo $area['size']['height']?>">
21
+ <input type="hidden" name="areas[<?php echo $area['id']?>][type]" value="<?php echo $area['type']?>">
22
+ <input type="hidden" name="areas[<?php echo $area['id']?>][color]" value="<?php echo $area['color']?>">
23
+ <input type="hidden" name="areas[<?php echo $area['id']?>][render]" value="<?php echo $area['render']?>">
24
+ <label>
25
+ <?php echo $this->__('Position')?>
26
+ <input type="text" name="areas[<?php echo $area['id']?>][position]" value="<?php echo isset($area['position']) ? $area['position'] : '' ?>">
27
+ </label>
28
+ <label>
29
+ <?php echo $this->__('Product Sku')?>
30
+ <input type="text" name="areas[<?php echo $area['id']?>][sku]" value="<?php echo isset($area['sku']) ? $area['sku'] : '' ?>">
31
+ </label>
32
+ <label>
33
+ <?php $value = isset($area['hilight_area']) ? $area['hilight_area'] : '0' ?>
34
+
35
+ <?php echo $this->__('Hilight area on frontend')?>
36
+ <select name="areas[<?php echo $area['id']?>][hilight_area]">
37
+ <option value="0" <?php echo $value == '0' ? 'selected="selected"' : ''?>><?php echo $this->__('No')?></option>
38
+ <option value="1" <?php echo $value == '1' ? 'selected="selected"' : ''?>><?php echo $this->__('Yes')?></option>
39
+ </select>
40
+ </label>
41
+
42
+ <div class="clear"></div>
43
+ <button type="button" class="button button-delete" onclick="interactiveImage.deleteArea('<?php echo $area['id']?>');"><?php echo $this->__('Delete')?></button>
44
+ </fieldset>
45
+
46
+ <hr>
app/design/adminhtml/default/default/template/auguria/interactiveimage/catalog/product/helper/form/image/interactive/panel/areas.phtml ADDED
@@ -0,0 +1,25 @@
1
+ <?php
2
+ /**
3
+ * @category Auguria
4
+ * @package Auguria_InteractiveImage
5
+ * @author Auguria
6
+ * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3)
7
+ */
8
+
9
+ /* @var $this Auguria_InteractiveImage_Block_Adminhtml_Catalog_Product_Helper_Form_Image_Interactive_Panel_Areas */
10
+ ?>
11
+ <?php
12
+ $areas = $this->getAreas();
13
+ ?>
14
+
15
+ <div class="buttons">
16
+ <button class="button btn-clear" type="button" onclick="interactiveImage.clear();">
17
+ <span><span><?php echo $this->__('Clear')?></span></span>
18
+ </button>
19
+ </div>
20
+
21
+ <?php if(count($areas) > 0):?>
22
+ <?php foreach($areas as $_area):?>
23
+ <?php echo $this->getAreaHtml($_area)?>
24
+ <?php endforeach;?>
25
+ <?php endif;?>
app/design/adminhtml/default/default/template/auguria/interactiveimage/catalog/product/helper/form/image/interactive/popin.phtml ADDED
@@ -0,0 +1,35 @@
1
+ <?php
2
+ /**
3
+ * @category Auguria
4
+ * @package Auguria_InteractiveImage
5
+ * @author Auguria
6
+ * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3)
7
+ */
8
+
9
+ /* @var $this Auguria_InteractiveImage_Block_Adminhtml_Catalog_Product_Helper_Form_Image_Interactive_Popin */
10
+ ?>
11
+ <?php
12
+ $image = $this->getImage();
13
+ $params = $this->getParams();
14
+ ?>
15
+ <div class="popin interactive-image">
16
+ <?php echo $this->getMessagesBlock()->setMessages(Mage::getSingleton('adminhtml/session')->getMessages(true))->getGroupedHtml(); ?>
17
+
18
+ <div id="interactive-image-canvas" style="width:<?php echo $image['size'][0]?>px;height:<?php echo $image['size'][1]?>px;background-image: url('<?php echo $image['url']?>');" ></div>
19
+ <div id="interactive-image-panel" style="width:300px;">
20
+ <form id="interactive-image-form">
21
+ <?php if(isset($params['areas'])):?>
22
+ <?php echo $this->getChild('interactive.image.panel.areas')->setAreas($params['areas'])->tohtml()?>
23
+ <?php endif;?>
24
+ </form>
25
+ </div>
26
+
27
+ <div class="buttons">
28
+ <button class="button btn-close" type="button" onclick="interactiveImage.close();">
29
+ <span><span><?php echo $this->__('Close')?></span></span>
30
+ </button>
31
+ <button class="button btn-save" type="button" onclick="interactiveImage.save();">
32
+ <span><span><?php echo $this->__('Save')?></span></span>
33
+ </button>
34
+ </div>
35
+ </div>
app/design/frontend/base/default/layout/auguria/interactive_image.xml ADDED
@@ -0,0 +1,26 @@
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * @category Auguria
5
+ * @package Auguria_InteractiveImage
6
+ * @author Auguria
7
+ * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3)
8
+ */
9
+ -->
10
+ <layout version="0.1.0">
11
+
12
+ <catalog_product_view>
13
+ <reference name="head">
14
+ <action method="addJs"><link>auguria/interactiveimage/jquery-1.10.2.min.js</link></action>
15
+ <action method="addJs"><link>auguria/interactiveimage/jquery.maphilight.min.js</link></action>
16
+ <action method="addJs"><link>auguria/interactiveimage/cart.js</link></action>
17
+ <action method="addCss"><link>css/auguria/interactiveimage/image.css</link></action>
18
+ </reference>
19
+ <reference name="product.info.additional">
20
+ <block type="auguria_interactiveimage/catalog_product_image" name="auguria.interactiveimage.catalog.product.image">
21
+ <action method="setTemplate"><template>auguria/interactiveimage/catalog/product/image.phtml</template></action>
22
+ </block>
23
+ </reference>
24
+ </catalog_product_view>
25
+
26
+ </layout>
app/design/frontend/base/default/template/auguria/interactiveimage/catalog/product/image.phtml ADDED
@@ -0,0 +1,126 @@
1
+ <?php
2
+ /**
3
+ * @category Auguria
4
+ * @package Auguria_InteractiveImage
5
+ * @author Auguria
6
+ * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3)
7
+ */
8
+
9
+ /* @var $this Auguria_InteractiveImage_Block_Catalog_Product_Image */
10
+ ?>
11
+ <?php
12
+ $imageUrl = $this->getInteractiveImage();
13
+ $useAjax = Mage::helper('auguria_interactiveimage/config')->useAjax();
14
+ ?>
15
+
16
+ <?php if($imageUrl):?>
17
+
18
+ <?php
19
+ $areas = $this->getAreas();
20
+ $products = $this->getProducts();
21
+ ?>
22
+ <div class="box box-collateral">
23
+ <h2>
24
+ <?php echo $this->__('Interactive image') ?>
25
+ </h2>
26
+ <div class="std">
27
+ <div class="interactive-container">
28
+ <img id="interactiveimage" src="<?php echo $imageUrl ?>" alt=""
29
+ usemap="#interactiveimage" />
30
+
31
+ <?php if(count($areas)):?>
32
+ <map name="interactiveimage" id="map-interactiveimage">
33
+ <?php foreach($areas as $_area):?>
34
+ <?php
35
+ $_coords = $this->getCoords($_area);
36
+ $_product = $this->getProductBySku($_area['sku']);
37
+ ?>
38
+
39
+ <?php if($_product): ?>
40
+ <area id="area-position-<?php echo $_area['id']?>"
41
+ shape="<?php echo $_area['type']?>"
42
+ coords="<?php echo $_coords['area']?>"
43
+ href="<?php echo $this->getAddToCartUrl($_area['sku'])?>"
44
+ alt="<?php echo $_area['sku']?>"
45
+ <?php echo $useAjax ? 'onclick="cartajax.submitInline(this, ' . Mage::helper('auguria_cartajax')->getAjaxParams($_area['sku']) . ');return false;"' : '' ?>
46
+ data-maphilight='<?php echo isset($_area['hilight_area']) && $_area['hilight_area'] ? '{"alwaysOn":true, "neverOn":false}' : '' ?>'>
47
+
48
+ <div id="tooltip-area-position-<?php echo $_area['id']?>" class="tooltip" style="display:none;top:<?php echo $_coords['tooltip']['top']?>px;left:<?php echo $_coords['tooltip']['left']?>px;">
49
+ <div class="sku">
50
+ <?php echo $_product->getSku()?>
51
+ </div>
52
+ <div class="name">
53
+ <?php echo $_product->getName()?>
54
+ </div>
55
+ <div class="price">
56
+ <?php echo $_product->getFormatedPrice()?>
57
+ </div>
58
+ </div>
59
+ <?php endif; ?>
60
+ <?php endforeach;?>
61
+ </map>
62
+
63
+ <form action="<?php echo $this->getMassAddToCartUrl() ?>"
64
+ method="post" id="image_addtocart_form">
65
+
66
+ <table id="interactiveimage-product-list"
67
+ class="interactiveimage-product-list data-table">
68
+ <caption></caption>
69
+ <thead>
70
+ <tr>
71
+ <th><?php echo $this->__('Position')?></th>
72
+ <th><?php echo $this->__('Reference')?></th>
73
+ <th><?php echo $this->__('Designation')?></th>
74
+ <th><?php echo $this->__('Unit price')?></th>
75
+ <th><?php echo $this->__('Qty')?></th>
76
+ </tr>
77
+ </thead>
78
+ <tfoot>
79
+ </tfoot>
80
+ <tbody id="interactiveimage-product-list-body">
81
+ <?php foreach($products as $_product):?>
82
+ <?php /* @var $_product Mage_Catalog_Model_Product */ ?>
83
+ <tr>
84
+ <td><?php echo $this->getPositionBySku($_product->getSku())?></td>
85
+ <td><?php echo $_product->getSku()?></td>
86
+ <td><?php echo $_product->getName()?></td>
87
+ <td><?php echo $_product->getFormatedPrice()?></td>
88
+ <td><input type="hidden"
89
+ name="products[<?php echo $_product->getId()?>][product]"
90
+ value="<?php echo $_product->getId()?>" /> <input type="text"
91
+ name="products[<?php echo $_product->getId()?>][qty]" value="0" />
92
+ </td>
93
+ </tr>
94
+ <?php endforeach;?>
95
+ </tbody>
96
+ </table>
97
+
98
+ <div class="no-display">
99
+ <input type="hidden" name="related_product"
100
+ id="related-products-field" value="" />
101
+ </div>
102
+
103
+ <button class="button btn-cart"
104
+ title="<?php echo $this->__('Add to Cart')?>" type="submit"
105
+ <?php echo $useAjax ? 'onclick="productAddToCartForm.submit(this);return false;"' : '' ?>>
106
+ <span><span><?php echo $this->__('Add to Cart')?> </span> </span>
107
+ </button>
108
+
109
+ </form>
110
+
111
+ <script type="text/javascript">
112
+ jQuery('#interactiveimage').maphilight({neverOn:true,fillColor:'00D2FF',strokeColor:'000000'});
113
+ jQuery(document).ready(function() {
114
+ jQuery('area').mouseover(function() {
115
+ jQuery('#tooltip-' + this.id).toggle();
116
+ });
117
+ jQuery('area').mouseout(function() {
118
+ jQuery('#tooltip-' + this.id).toggle();
119
+ });
120
+ });
121
+ </script>
122
+ <?php endif;?>
123
+ </div>
124
+ </div>
125
+ </div>
126
+ <?php endif;?>
app/etc/modules/Auguria_InteractiveImage.xml ADDED
@@ -0,0 +1,20 @@
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * @category Auguria
5
+ * @package Auguria_InteractiveImage
6
+ * @author Auguria
7
+ * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3)
8
+ */
9
+ -->
10
+ <config>
11
+ <modules>
12
+ <Auguria_InteractiveImage>
13
+ <active>true</active>
14
+ <codePool>community</codePool>
15
+ <depends>
16
+ <Auguria_Core />
17
+ </depends>
18
+ </Auguria_InteractiveImage>
19
+ </modules>
20
+ </config>
app/locale/en_US/Auguria_InteractiveImage.csv ADDED
File without changes
app/locale/fr_FR/Auguria_InteractiveImage.csv ADDED
@@ -0,0 +1,14 @@
1
+ "Interactive image","Image interactive"
2
+ "Use ajax for adding product to cart","Utiliser l'ajax (popin) pour l'ajout au panier"
3
+ "Module Auguria_CartAjax must be enabled","Le module Auguria_CartAjax doit être activé"
4
+ "Define areas","Définir les zones"
5
+ "Clear","Tout supprimer"
6
+ "Position","Position"
7
+ "Product Sku","Sku du produit"
8
+ "Hilight area on frontend","Afficher le contour de la zone en front"
9
+ "Delete","Supprimer"
10
+ "Close","Fermer"
11
+ "Save","Sauvegarder"
12
+ "Products","Produits"
13
+ "Designation","Désignation"
14
+ "Qty","Qté"
js/auguria/interactiveimage/cart.js ADDED
@@ -0,0 +1,11 @@
1
+ InteractiveImage = Class.create();
2
+ InteractiveImage.prototype = {
3
+
4
+ initialize: function(){
5
+
6
+ },
7
+
8
+ addToCart: function(sku){
9
+
10
+ }
11
+ }
js/auguria/interactiveimage/image.js ADDED
@@ -0,0 +1,357 @@
1
+ InteractiveImage = Class.create();
2
+ InteractiveImage.prototype = {
3
+
4
+ initialize: function(imgUrl, config){
5
+
6
+ if(config == undefined){
7
+ alert(Translator.translate('Image path is not defined. Upload the image (choose image path and save product) then define areas (and save again).'));
8
+ return false;
9
+ }
10
+
11
+ // by config
12
+ this.imgUrl = imgUrl;
13
+ this.imagePath = config.image_path;
14
+
15
+ var areas = {};
16
+ if(config.areas){var areas = JSON.parse(config.areas);}
17
+ this.originAreas = areas;
18
+ this.areas = areas;
19
+
20
+ // base
21
+ this.popin = null;
22
+ this.types = {rect: 'rect'}
23
+ this.formId = 'interactive-image-form';
24
+
25
+ // canvas
26
+ this.canvasId = 'interactive-image-canvas';
27
+ this.canvasWidth = null;
28
+ this.canvasHeight = null;
29
+
30
+ this.stage = null;
31
+ this.currentArea = null;
32
+
33
+ // control panel
34
+ this.panelId = 'interactive-image-panel';
35
+ this.panel = $(this.panelId);
36
+ },
37
+
38
+ // display popin for edition (areas definitions)
39
+ display: function(){
40
+ if(this.imagePath == undefined){
41
+ alert(Translator.translate('Image path is not defined. Upload the image (choose image path and save product) then define areas (and save again).'));
42
+ return false;
43
+ }
44
+
45
+ var _self = this;
46
+
47
+ // informations used for edition interface
48
+ var params = {
49
+ 'image_path': this.imagePath,
50
+ 'areas': this.areas
51
+ }
52
+
53
+ this.initImage(); // get canvas/image dimensions
54
+
55
+ new Ajax.Request('/admin/auguria_interactiveImage_image/display', {
56
+ parameters: {
57
+ 'interactive_image': Object.toJSON(params),
58
+ },
59
+ onSuccess: function(transport) {
60
+ var response = transport.responseText.evalJSON(true);
61
+
62
+ if(response.error){
63
+ alert('error');
64
+ }else{
65
+ if(response.content){
66
+ _self.popin = Dialog.info(response.content, {
67
+ closable: true,
68
+ resizable: true,
69
+ draggable: true,
70
+ className: 'magento',
71
+ windowClassName: 'popup-window',
72
+ width: 'auto',
73
+ height: 'auto',
74
+ top: 0, // fix top position with largest images (draggable popin)
75
+ zIndex: 1000,
76
+ recenterAuto: false,
77
+ hideEffect: Element.hide,
78
+ showEffect: Element.show,
79
+ id: 'interactive-image-popin',
80
+ destroyOnClose: true
81
+ });
82
+ }
83
+
84
+ _self.initCanvas();
85
+ _self.initAreas();
86
+ }
87
+ }
88
+ });
89
+ },
90
+
91
+ // init image/canvas dimensions
92
+ initImage: function(){
93
+ var img = new Image();
94
+ img.src = this.imgUrl;
95
+ this.canvasWidth = img.width;
96
+ this.canvasHeight = img.height;
97
+ },
98
+
99
+ // clear areas
100
+ clear: function(){
101
+ this.stage.clear(); // layers
102
+ // DOM
103
+ $('#' + this.formId + ' fieldset').each(function(elem){
104
+ elem.remove();
105
+ });
106
+ this.areas = this.originAreas;
107
+ },
108
+
109
+ // close generated popin
110
+ close: function(){
111
+ if(this.popin != null){
112
+ // this.areas = this.originAreas;
113
+ this.popin.close();
114
+ }
115
+
116
+ return false;
117
+ },
118
+
119
+ // save areas
120
+ save: function(){
121
+ var _self = this;
122
+
123
+ new Ajax.Request('/admin/auguria_interactiveImage_image/save', {
124
+ parameters: $(this.formId).serialize(true),
125
+ onSuccess: function(transport) {
126
+ var response = transport.responseText.evalJSON(true);
127
+
128
+ if(response.error){
129
+ alert('error');
130
+ }else{
131
+ $('auguria_interactiveimage_image_areas').setValue(response.content);
132
+ _self.areas = JSON.parse(response.content);
133
+ alert('saved');
134
+ }
135
+ }
136
+ });
137
+ },
138
+
139
+ // init canvas
140
+ initCanvas: function(){
141
+ _self = this;
142
+
143
+ this.stage = new Kinetic.Stage({
144
+ container: this.canvasId,
145
+ width: this.canvasWidth,
146
+ height: this.canvasHeight
147
+ });
148
+
149
+ document.getElementById(this.canvasId).addEventListener('mousedown', function(){_self.mouseDown(_self)});
150
+ },
151
+
152
+ mouseDown: function(_self){
153
+ var mousePos = _self.stage.getMousePosition();
154
+
155
+ if(document.body.style.cursor != 'pointer'){
156
+ _self.draw = true;
157
+ _self.initCurrentArea({type: _self.types.rect, x:mousePos.x, y:mousePos.y});
158
+
159
+ var mouseMove = _self.mouseMove(_self);
160
+ document.getElementById(this.canvasId).addEventListener('mousemove', mouseMove, false);
161
+
162
+ var mouseUp = _self.mouseUp(_self);
163
+ document.getElementById(this.canvasId).addEventListener('mouseup', mouseUp, false);
164
+ }
165
+ },
166
+
167
+ mouseUp: function(_self){
168
+ var handler = function(event){
169
+ _self.createArea(_self.currentArea);
170
+ _self.createPanelTab(_self.currentArea);
171
+
172
+ // var mouseMove = _self.mouseMove(_self);
173
+ // document.getElementById(_self.canvasId).removeEventListener('mousemove', mouseMove, false);
174
+
175
+ document.getElementById(_self.canvasId).removeEventListener('mouseup', arguments.callee, false);
176
+
177
+ _self.draw = false;
178
+ }
179
+
180
+ return handler;
181
+ },
182
+
183
+ mouseMove: function(_self){
184
+ var handler = function(event){
185
+ if(!_self.draw){
186
+ document.getElementById(_self.canvasId).removeEventListener('mousemove', arguments.callee, false);
187
+ }
188
+
189
+ var mousePos = _self.stage.getMousePosition();
190
+
191
+ // rect
192
+ if(_self.currentArea.type == _self.types.rect){
193
+ _self.currentArea.size.width = mousePos.x - _self.currentArea.size.x;
194
+ _self.currentArea.size.height = mousePos.y - _self.currentArea.size.y;
195
+ }
196
+ }
197
+
198
+ return handler;
199
+ },
200
+
201
+ // init existing areas
202
+ initAreas: function(){
203
+ var _self = this;
204
+
205
+ for (var i in _self.areas) {
206
+ if (_self.areas.hasOwnProperty(i)) {
207
+ _self.createArea(_self.areas[i]);
208
+ }
209
+ }
210
+
211
+ $('auguria_interactiveimage_image_areas').setValue(Object.toJSON(_self.areas));
212
+ },
213
+
214
+ initCurrentArea: function(params){
215
+ if(params.type == this.types.rect){
216
+
217
+ var areaKeys = Object.keys(this.areas);
218
+ if(areaKeys.length > 0){
219
+ var id = areaKeys[areaKeys.length - 1];
220
+ id = parseInt(id) + 1;
221
+ }else{
222
+ var id = 0;
223
+ }
224
+
225
+ this.currentArea = {
226
+ type: params.type,
227
+ color:'#00D2FF',
228
+ size: {
229
+ x: params.x,
230
+ y: params.y,
231
+ width: 0,
232
+ height: 0
233
+ },
234
+ render: 'default',
235
+ id: id,
236
+ }
237
+ }
238
+ },
239
+
240
+ // create defined area
241
+ createArea: function(area){
242
+ _self = this;
243
+ var layer = new Kinetic.Layer();
244
+
245
+ if(area.type == this.types.rect){
246
+ var box = new Kinetic.Rect({
247
+ x: parseFloat(area.size.x),
248
+ y: parseFloat(area.size.y),
249
+ width: parseFloat(area.size.width),
250
+ height: parseFloat(area.size.height),
251
+ fill: area.color,
252
+ stroke: 'black',
253
+ strokeWidth: 1,
254
+ opacity: 0.6,
255
+ draggable: true,
256
+ dragBoundFunc: function(pos) {
257
+ // x
258
+ var newX = pos.x < 0 ? 0 : pos.x;
259
+ var newX = newX > _self.canvasWidth - area.size.width ? _self.canvasWidth - area.size.width : newX;
260
+ // y
261
+ var newY = pos.y < 0 ? 0 : pos.y;
262
+ var newY = newY > _self.canvasHeight