/pimcore/static6/js/pimcore/element/selector/selector.js

https://github.com/zspine/pimcore · JavaScript · 219 lines · 165 code · 42 blank · 12 comment · 24 complexity · d94e52593838ecf94717f9e2fdd834e2 MD5 · raw file

  1. /**
  2. * Pimcore
  3. *
  4. * This source file is subject to the GNU General Public License version 3 (GPLv3)
  5. * For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
  6. * files that are distributed with this source code.
  7. *
  8. * @copyright Copyright (c) 2009-2016 pimcore GmbH (http://www.pimcore.org)
  9. * @license http://www.pimcore.org/license GNU General Public License version 3 (GPLv3)
  10. */
  11. pimcore.registerNS("pimcore.element.selector.selector");
  12. pimcore.element.selector.selector = Class.create({
  13. initialize: function (multiselect, callback, restrictions, config) {
  14. this.initialRestrictions = restrictions ? restrictions: {};
  15. this.callback = callback;
  16. this.restrictions = restrictions;
  17. this.multiselect = multiselect;
  18. this.config = typeof config != "undefined" ? config : {};
  19. if(!this.multiselect) {
  20. this.multiselect = false;
  21. }
  22. var possibleClassRestrictions = [];
  23. var classStore = pimcore.globalmanager.get("object_types_store");
  24. classStore.each(function (rec) {
  25. possibleClassRestrictions.push(rec.data.text);
  26. });
  27. var restrictionDefaults = {
  28. type: ["document","asset","object"],
  29. subtype: {
  30. document: ["page", "snippet","folder","link","hardlink","email"], //email added by ckogler
  31. asset: ["folder", "image", "text", "audio", "video", "document", "archive", "unknown"],
  32. object: ["object", "folder", "variant"]
  33. },
  34. specific: {
  35. classes: possibleClassRestrictions // put here all classes from global class store ...
  36. }
  37. };
  38. if(!this.restrictions) {
  39. this.restrictions = restrictionDefaults;
  40. }
  41. this.restrictions = Ext.applyIf(this.restrictions, restrictionDefaults);
  42. if(!this.callback) {
  43. this.callback = function () {};
  44. //throw "";
  45. }
  46. this.panel = new Ext.Panel({
  47. tbar: this.getToolbar(),
  48. border: false,
  49. layout: "fit"
  50. });
  51. var windowWidth = 1000;
  52. if(this.multiselect) {
  53. windowWidth = 1250;
  54. }
  55. var windowConfig = {
  56. width: windowWidth,
  57. height: 550,
  58. modal: true,
  59. layout: "fit",
  60. items: [this.panel]
  61. };
  62. if(this.config["moveToTab"]) {
  63. windowConfig["tools"] = [{
  64. type: "maximize",
  65. tooltip: t("move_to_tab"),
  66. callback: this.moveToTab.bind(this)
  67. }];
  68. }
  69. this.window = new Ext.Window(windowConfig);
  70. this.window.show();
  71. var user = pimcore.globalmanager.get("user");
  72. if(in_array("document", this.restrictions.type) && user.isAllowed("documents")) {
  73. this.searchDocuments();
  74. }
  75. else if(in_array("asset", this.restrictions.type) && user.isAllowed("assets")) {
  76. this.searchAssets();
  77. }
  78. else if(in_array("object", this.restrictions.type) && user.isAllowed("objects")) {
  79. this.searchObjects();
  80. }
  81. },
  82. getToolbar: function () {
  83. var user = pimcore.globalmanager.get("user");
  84. var toolbar;
  85. var items = [];
  86. this.toolbarbuttons = {};
  87. if(in_array("document", this.restrictions.type) && user.isAllowed("documents")) {
  88. this.toolbarbuttons.document = new Ext.Button({
  89. text: t("documents"),
  90. handler: this.searchDocuments.bind(this),
  91. iconCls: "pimcore_icon_document",
  92. enableToggle: true
  93. });
  94. items.push(this.toolbarbuttons.document);
  95. }
  96. if(in_array("asset", this.restrictions.type) && user.isAllowed("assets")) {
  97. items.push("-");
  98. this.toolbarbuttons.asset = new Ext.Button({
  99. text: t("assets"),
  100. handler: this.searchAssets.bind(this),
  101. iconCls: "pimcore_icon_asset",
  102. enableToggle: true
  103. });
  104. items.push(this.toolbarbuttons.asset);
  105. }
  106. if(in_array("object", this.restrictions.type) && user.isAllowed("objects")) {
  107. items.push("-");
  108. this.toolbarbuttons.object = new Ext.Button({
  109. text: t("objects"),
  110. handler: this.searchObjects.bind(this),
  111. iconCls: "pimcore_icon_object",
  112. enableToggle: true
  113. });
  114. items.push(this.toolbarbuttons.object);
  115. }
  116. if(items.length > 2) {
  117. toolbar = {
  118. items: items
  119. };
  120. }
  121. return toolbar;
  122. },
  123. moveToTab: function () {
  124. // create new tab-panel
  125. this.myTabId = "pimcore_search_" + uniqid();
  126. this.tabpanel = new Ext.Panel({
  127. id: this.myTabId,
  128. iconCls: "pimcore_icon_search",
  129. title: t(this.current.getTabTitle()),
  130. border: false,
  131. layout: "fit",
  132. closable:true,
  133. items: [this.panel]
  134. });
  135. var tabPanel = Ext.getCmp("pimcore_panel_tabs");
  136. tabPanel.add(this.tabpanel);
  137. tabPanel.setActiveItem(this.myTabId);
  138. pimcore.layout.refresh();
  139. this.window.close();
  140. },
  141. setSearch: function (panel) {
  142. delete this.current;
  143. this.panel.removeAll();
  144. this.panel.add(panel);
  145. this.panel.updateLayout();
  146. },
  147. resetToolbarButtons: function () {
  148. if(this.toolbarbuttons.document) {
  149. this.toolbarbuttons.document.toggle(false);
  150. }
  151. if(this.toolbarbuttons.asset) {
  152. this.toolbarbuttons.asset.toggle(false);
  153. }
  154. if(this.toolbarbuttons.object) {
  155. this.toolbarbuttons.object.toggle(false);
  156. }
  157. },
  158. searchDocuments: function () {
  159. this.resetToolbarButtons();
  160. this.toolbarbuttons.document.toggle(true);
  161. this.current = new pimcore.element.selector.document(this);
  162. },
  163. searchAssets: function () {
  164. this.resetToolbarButtons();
  165. this.toolbarbuttons.asset.toggle(true);
  166. this.current = new pimcore.element.selector.asset(this);
  167. },
  168. searchObjects: function () {
  169. this.resetToolbarButtons();
  170. this.toolbarbuttons.object.toggle(true);
  171. this.current = new pimcore.element.selector.object(this);
  172. },
  173. commitData: function (data) {
  174. this.callback(data);
  175. this.window.close();
  176. }
  177. });