Web Interface For Lite Argus Control modules
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

168 lines
6.0 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>The source code</title>
  5. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  6. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  7. </head>
  8. <body onload="prettyPrint();">
  9. <pre class="prettyprint lang-js">/*!
  10. * Ext JS Library 3.3.1
  11. * Copyright(c) 2006-2010 Sencha Inc.
  12. * licensing@sencha.com
  13. * http://www.sencha.com/license
  14. */
  15. <div id="cls-Ext.ux.ToolbarDroppable"></div>/**
  16. * @class Ext.ux.ToolbarDroppable
  17. * @extends Object
  18. * Plugin which allows items to be dropped onto a toolbar and be turned into new Toolbar items.
  19. * To use the plugin, you just need to provide a createItem implementation that takes the drop
  20. * data as an argument and returns an object that can be placed onto the toolbar. Example:
  21. * <pre>
  22. * new Ext.ux.ToolbarDroppable({
  23. * createItem: function(data) {
  24. * return new Ext.Button({text: data.text});
  25. * }
  26. * });
  27. * </pre>
  28. * The afterLayout function can also be overridden, and is called after a new item has been
  29. * created and inserted into the Toolbar. Use this for any logic that needs to be run after
  30. * the item has been created.
  31. */
  32. Ext.ux.ToolbarDroppable = Ext.extend(Object, {
  33. <div id="method-Ext.ux.ToolbarDroppable-constructor"></div>/**
  34. * @constructor
  35. */
  36. constructor: function(config) {
  37. Ext.apply(this, config, {
  38. });
  39. },
  40. <div id="method-Ext.ux.ToolbarDroppable-init"></div>/**
  41. * Initializes the plugin and saves a reference to the toolbar
  42. * @param {Ext.Toolbar} toolbar The toolbar instance
  43. */
  44. init: function(toolbar) {
  45. <div id="prop-Ext.ux.ToolbarDroppable-toolbar"></div>/**
  46. * @property toolbar
  47. * @type Ext.Toolbar
  48. * The toolbar instance that this plugin is tied to
  49. */
  50. this.toolbar = toolbar;
  51. this.toolbar.on({
  52. scope : this,
  53. render: this.createDropTarget
  54. });
  55. },
  56. <div id="method-Ext.ux.ToolbarDroppable-createDropTarget"></div>/**
  57. * Creates a drop target on the toolbar
  58. */
  59. createDropTarget: function() {
  60. <div id="prop-Ext.ux.ToolbarDroppable-dropTarget"></div>/**
  61. * @property dropTarget
  62. * @type Ext.dd.DropTarget
  63. * The drop target attached to the toolbar instance
  64. */
  65. this.dropTarget = new Ext.dd.DropTarget(this.toolbar.getEl(), {
  66. notifyOver: this.notifyOver.createDelegate(this),
  67. notifyDrop: this.notifyDrop.createDelegate(this)
  68. });
  69. },
  70. <div id="method-Ext.ux.ToolbarDroppable-addDDGroup"></div>/**
  71. * Adds the given DD Group to the drop target
  72. * @param {String} ddGroup The DD Group
  73. */
  74. addDDGroup: function(ddGroup) {
  75. this.dropTarget.addToGroup(ddGroup);
  76. },
  77. <div id="method-Ext.ux.ToolbarDroppable-calculateEntryIndex"></div>/**
  78. * Calculates the location on the toolbar to create the new sorter button based on the XY of the
  79. * drag event
  80. * @param {Ext.EventObject} e The event object
  81. * @return {Number} The index at which to insert the new button
  82. */
  83. calculateEntryIndex: function(e) {
  84. var entryIndex = 0,
  85. toolbar = this.toolbar,
  86. items = toolbar.items.items,
  87. count = items.length,
  88. xTotal = toolbar.getEl().getXY()[0],
  89. xHover = e.getXY()[0] - xTotal;
  90. for (var index = 0; index < count; index++) {
  91. var item = items[index],
  92. width = item.getEl().getWidth(),
  93. midpoint = xTotal + width / 2;
  94. xTotal += width;
  95. if (xHover < midpoint) {
  96. entryIndex = index;
  97. break;
  98. } else {
  99. entryIndex = index + 1;
  100. }
  101. }
  102. return entryIndex;
  103. },
  104. <div id="method-Ext.ux.ToolbarDroppable-canDrop"></div>/**
  105. * Returns true if the drop is allowed on the drop target. This function can be overridden
  106. * and defaults to simply return true
  107. * @param {Object} data Arbitrary data from the drag source
  108. * @return {Boolean} True if the drop is allowed
  109. */
  110. canDrop: function(data) {
  111. return true;
  112. },
  113. <div id="method-Ext.ux.ToolbarDroppable-notifyOver"></div>/**
  114. * Custom notifyOver method which will be used in the plugin's internal DropTarget
  115. * @return {String} The CSS class to add
  116. */
  117. notifyOver: function(dragSource, event, data) {
  118. return this.canDrop.apply(this, arguments) ? this.dropTarget.dropAllowed : this.dropTarget.dropNotAllowed;
  119. },
  120. <div id="method-Ext.ux.ToolbarDroppable-notifyDrop"></div>/**
  121. * Called when the drop has been made. Creates the new toolbar item, places it at the correct location
  122. * and calls the afterLayout callback.
  123. */
  124. notifyDrop: function(dragSource, event, data) {
  125. var canAdd = this.canDrop(dragSource, event, data),
  126. tbar = this.toolbar;
  127. if (canAdd) {
  128. var entryIndex = this.calculateEntryIndex(event);
  129. tbar.insert(entryIndex, this.createItem(data));
  130. tbar.doLayout();
  131. this.afterLayout();
  132. }
  133. return canAdd;
  134. },
  135. <div id="method-Ext.ux.ToolbarDroppable-createItem"></div>/**
  136. * Creates the new toolbar item based on drop data. This method must be implemented by the plugin instance
  137. * @param {Object} data Arbitrary data from the drop
  138. * @return {Mixed} An item that can be added to a toolbar
  139. */
  140. createItem: function(data) {
  141. throw new Error("The createItem method must be implemented in the ToolbarDroppable plugin");
  142. },
  143. <div id="prop-Ext.ux.ToolbarDroppable-afterLayout"></div>/**
  144. * Called after a new button has been created and added to the toolbar. Add any required cleanup logic here
  145. */
  146. afterLayout: Ext.emptyFn
  147. });</pre>
  148. </body>
  149. </html>