/www/shop/templates/_default/backend/supplier/view/main/edit.js

https://bitbucket.org/weberlars/sot-shopware · JavaScript · 307 lines · 199 code · 17 blank · 91 comment · 1 complexity · e64b044bf28d5180c80d35eca46694ad MD5 · raw file

  1. /**
  2. * Shopware 4.0
  3. * Copyright Š 2012 shopware AG
  4. *
  5. * According to our dual licensing model, this program can be used either
  6. * under the terms of the GNU Affero General Public License, version 3,
  7. * or under a proprietary license.
  8. *
  9. * The texts of the GNU Affero General Public License with an additional
  10. * permission and of our proprietary license can be found at and
  11. * in the LICENSE file you have received along with this program.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * "Shopware" is a registered trademark of shopware AG.
  19. * The licensing of the program under the AGPLv3 does not imply a
  20. * trademark license. Therefore any rights, title and interest in
  21. * our trademarks remain entirely with us.
  22. *
  23. * @category Shopware
  24. * @package Supplier
  25. * @subpackage View
  26. * @copyright Copyright (c) 2012, shopware AG (http://www.shopware.de)
  27. * @version $Id$
  28. * @author shopware AG
  29. */
  30. /*{namespace name=backend/supplier/view/edit}*/
  31. /**
  32. * Shopware View - Supplier
  33. *
  34. * Backend - Management for Suppliers. Create | Modify | Delete and Logo Management.
  35. * Create a edit supplier view
  36. */
  37. //{block name=backend/supplier/view/main/edit}
  38. Ext.define('Shopware.apps.Supplier.view.main.Edit', {
  39. extend : 'Enlight.app.Window',
  40. alias : 'widget.supplier-main-edit',
  41. layout : 'fit',
  42. title : '{s name=title}Supplier - edit{/s}',
  43. width : 700,
  44. height : '90%',
  45. stateful : true,
  46. stateId : 'shopware-supplier-edit',
  47. /**
  48. * Initialize the component
  49. * @return void
  50. */
  51. initComponent : function () {
  52. var me = this,
  53. oldTitle = me.title;
  54. me.title = oldTitle + ': ' + me.record.get('name');
  55. me.logo = me.getLogo();
  56. me.dropZone = me.getDropZone();
  57. me.htmlEditor = me.getHtmlField();
  58. me.hiddenFields = me.getHiddenFields();
  59. me.topForm = me.getFormTopPart();
  60. me.deleteButton = me.getDeleteButton();
  61. me.supplierInfoForm = me.getInfoForm();
  62. me.supplierInfoForm.getForm().loadRecord(this.record);
  63. me.items = [me.supplierInfoForm];
  64. me.dockedItems = [{
  65. xtype: 'toolbar',
  66. dock: 'bottom',
  67. cls: 'shopware-toolbar',
  68. ui: 'shopware-ui',
  69. items: me.getButtons()
  70. }];
  71. //removed me.callParent(me); because chrome could not handle this call
  72. me.callParent(arguments);
  73. },
  74. /**
  75. * Returns an array of buttons. Default buttons are cancel and save
  76. *
  77. * @return array of buttons
  78. */
  79. getButtons : function()
  80. {
  81. var me = this;
  82. return ['->',
  83. {
  84. text : '{s name=cancel}Cancel{/s}',
  85. cls: 'secondary',
  86. scope : me,
  87. handler : me.destroy
  88. },
  89. {
  90. text : '{s name=save}Save{/s}',
  91. action : 'saveSupplier',
  92. scale : 'large',
  93. cls : 'primary',
  94. formBind: true
  95. }
  96. ];
  97. },
  98. /**
  99. * Returns the delete logo button
  100. *
  101. * @return Ext.buttonButton
  102. */
  103. getDeleteButton : function() {
  104. var me = this;
  105. return {
  106. xtype : 'button',
  107. cls: 'small secondary',
  108. name : 'deleteLogo',
  109. scope : me,
  110. text : '{s name=delete_logo}Delete Logo{/s}',
  111. action : 'deleteLogo',
  112. scale : 'small',
  113. style : 'float: right; margin: 0 35px 10px 0'
  114. };
  115. },
  116. /**
  117. * Return the entire form uses the methods
  118. * - getFormDefaults
  119. *
  120. * @return Ext.form.Panel
  121. */
  122. getInfoForm : function()
  123. {
  124. var me = this,
  125. logoArray = [];
  126. //logoArray.push(me.logo);
  127. //remove delete button when there is no logo to delete
  128. if (me.record.get('image') !== "") {
  129. logoArray.push(me.logo);
  130. logoArray.push(me.deleteButton);
  131. }
  132. return Ext.create('Ext.form.Panel', {
  133. collapsible : false,
  134. split : false,
  135. region : 'center',
  136. width : '100%',
  137. id : 'supplierFormPanel',
  138. defaults : me.getFormDefaults(),
  139. bodyPadding : 10,
  140. border : 0,
  141. autoScroll: true,
  142. items : [
  143. {
  144. xtype : 'container',
  145. anchor : '100%',
  146. layout : 'column',
  147. border : 1,
  148. defaults : {
  149. labelStyle : 'font-weight: 700; text-align: right;',
  150. labelWidth : 130,
  151. anchor : '100%'
  152. },
  153. items : [
  154. {
  155. xtype : 'container',
  156. layout : 'anchor',
  157. columnWidth : 0.8,
  158. defaults : {
  159. labelStyle : 'font-weight: 700; text-align: right;',
  160. anchor : '100%'
  161. },
  162. items : me.topForm
  163. },
  164. {
  165. xtype : 'container',
  166. layout : 'anchor',
  167. columnWidth : 0.2,
  168. items : logoArray
  169. },
  170. {
  171. xtype : 'container',
  172. layout : 'anchor',
  173. columnWidth : 1,
  174. defaults : {
  175. labelStyle : 'font-weight: 700; text-align: right;',
  176. anchor : '100%'
  177. },
  178. items : [
  179. me.htmlEditor,
  180. me.dropZone
  181. ]
  182. },
  183. me.hiddenFields
  184. ]
  185. }
  186. ]
  187. });
  188. },
  189. /**
  190. * Returns the HTML editor for the description
  191. *
  192. * @return Ext.form.field.HtmlEditor
  193. */
  194. getHtmlField : function()
  195. {
  196. return Ext.create('Shopware.form.field.TinyMCE', {
  197. name : 'description',
  198. fieldLabel : '{s name=description}Description{/s}',
  199. anchor : '100%',
  200. height: 300
  201. });
  202. },
  203. /**
  204. * Returns a set of hidden fields
  205. * @return array of hidden fields
  206. */
  207. getHiddenFields : function()
  208. {
  209. return [{
  210. xtype : 'hidden',
  211. name : 'image',
  212. fieldLabel : 'image'
  213. }];
  214. },
  215. /**
  216. * Returns the two most upper form fields: name and url
  217. *
  218. * @return array of form fields
  219. */
  220. getFormTopPart : function() {
  221. return [{
  222. xtype : 'textfield',
  223. name : 'name',
  224. allowBlank : false,
  225. anchor : '95%',
  226. fieldLabel : '{s name=name}Supplier name{/s}',
  227. supportText : '{s name=name_support}Name of the supplier e.g. Shopware AG{/s}'
  228. },
  229. {
  230. xtype : 'textfield',
  231. vtype : 'url',
  232. name : 'link',
  233. anchor : '95%',
  234. fieldLabel : '{s name=link}URL{/s}',
  235. supportText : '{s name=link_support}Link to suppliers website{/s}'
  236. }];
  237. },
  238. /**
  239. * Returns the media selector for the supplier module
  240. *
  241. * @return Shopware.MediaManager.MediaSelection
  242. */
  243. getDropZone : function()
  244. {
  245. return Ext.create('Shopware.MediaManager.MediaSelection', {
  246. fieldLabel : '{s name=form_logo}Logo{/s}',
  247. name : 'media-manager-selection',
  248. supportText : '{s name=logo_support}Supplier logo selection via Media Manager. The selection is limited to one media.{/s}',
  249. multiSelect : false,
  250. anchor : '100%',
  251. labelWidth : 100
  252. });
  253. },
  254. /**
  255. * Returns an object containing all default settings for every form element
  256. *
  257. * @return object
  258. */
  259. getFormDefaults : function() {
  260. return {
  261. /* todo@stp please move this to CSS/SASS */
  262. labelStyle : 'font-weight: 700; text-align: right;',
  263. labelWidth : 130,
  264. anchor : '100%'
  265. };
  266. },
  267. /**
  268. * Returns an element which contains the logo
  269. *
  270. * @return Ext.Img
  271. */
  272. getLogo : function() {
  273. var me = this,
  274. path = '{link file=""}',
  275. imageUrl = me.record.get('image'),
  276. image = Ext.create('Ext.Img', {
  277. src : path+imageUrl,
  278. maxWidth : 120,
  279. width : 120,
  280. maxHeight : 80,
  281. margin : '0 auto',
  282. name : 'image',
  283. itemId : 'supplierFormPanelLogo',
  284. style : 'height: 80px; width: 120px;'
  285. }
  286. );
  287. return image;
  288. }
  289. });
  290. //{/block}