PageRenderTime 44ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/nimbus/sys/kernel/api/elements/window.php

https://github.com/codepassive/dev-nimbus
PHP | 160 lines | 102 code | 8 blank | 50 comment | 23 complexity | 93de1efec8f1c4e9ad33e0be22f2f3d1 MD5 | raw file
  1. <?php
  2. /**
  3. * Nimbus - Manage, Share & Collaborate
  4. *
  5. * Nimbus is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. * see LICENSE for more Copyright goodness.
  10. *
  11. * @package: Nimbus
  12. * @subpackage: Nimbus_api
  13. * @copyright: 2009-2010, Nimbus Dev Group, All rights reserved.
  14. * @license: GNU/GPLv3, see LICENSE
  15. * @version: 1.0.0 Alpha
  16. */
  17. /**
  18. * The Window
  19. *
  20. * @category: API/Elements
  21. */
  22. class window extends Elements implements ElementInterface {
  23. /**
  24. * Name of the Element
  25. *
  26. * @access: Public
  27. */
  28. public $name = 'window';
  29. /**
  30. * Class constructor
  31. *
  32. * @access: Public
  33. */
  34. public function __construct($options = array()){
  35. parent::__construct(array(
  36. 'id' => 'window-' . generateHash(microtime()),
  37. 'classes' => array(),
  38. 'type' => 0, //Application(0) or Dialog(1)
  39. 'height' => 0,
  40. 'minHeight' => null,
  41. 'maxHeight' => null,
  42. 'width' => 0,
  43. 'minWidth' => null,
  44. 'maxWidth' => null,
  45. 'icon' => config('appurl') . 'public/resources/images/icons/Tango/16/actions/document-new.png',
  46. 'x' => 0,
  47. 'y' => 0,
  48. 'z' => 0,
  49. 'name' => null,
  50. 'title' => 'Default Window Title',
  51. 'toolbars' => array(),
  52. 'content' => array(),
  53. 'buttons' => array(),
  54. 'showInTaskbar' => true,
  55. 'parent' => null,
  56. //Flags
  57. 'visible' => true,
  58. 'resizable' => true,
  59. 'draggable' => true,
  60. 'pinnable' => false,
  61. 'minimizable' => true,
  62. 'toggable' => true,
  63. 'closable' => true,
  64. 'hasIcon' => true,
  65. 'modal' => false,
  66. //Callbacks
  67. 'onResizing' => null,
  68. 'onResizeStart' => null,
  69. 'onResizeStop' => null,
  70. 'onDraging' => null,
  71. 'onDragStart' => null,
  72. 'onDragStop' => null,
  73. 'onPin' => null,
  74. 'onUnpin' => null,
  75. 'onMinimize' => null,
  76. 'onMaximize' => null,
  77. 'onToggle' => null,
  78. 'onLoad' => null,
  79. 'onUnload' => null
  80. ), $options);
  81. //Render the position fix
  82. $classes = $this->flag('classes');
  83. if ($this->flag('x') == 'center') $classes = array_merge($classes, array('center-x'));
  84. if ($this->flag('y') == 'center') $classes = array_merge($classes, array('center-y'));
  85. if ($this->flag('modal') == true) $classes = array_merge($classes, array('modal'));
  86. if ($this->flag('draggable') == true) $classes = array_merge($classes, array('draggable'));
  87. if ($this->flag('resizable') == true) $classes = array_merge($classes, array('resizable'));
  88. if ($this->flag('toggable') == true) $classes = array_merge($classes, array('toggable'));
  89. $this->flag('classes', $classes);
  90. //Set the styles
  91. $this->styles = '';
  92. $this->styles .= ($this->flag('width') == 0) ? 'width:200px;': 'width:' . $this->flag('width') . ';';
  93. $this->styles .= ($this->flag('height') == 0) ? '': 'height:' . $this->flag('height') . ';';
  94. }
  95. /**
  96. * Display the contents from the content store
  97. *
  98. * @access: Public
  99. */
  100. public function content(){
  101. echo implode("", $this->flag('content'));
  102. }
  103. /**
  104. * Display the toolbars from the toolbar store
  105. *
  106. * @access: Public
  107. */
  108. public function toolbars($id){
  109. $toolbars = $this->flag('toolbars');
  110. if (isset($toolbars[$id])) {
  111. foreach($toolbars[$id] as $toolbar){
  112. if (is_object($toolbar)) {
  113. echo '<div class="toolbar-row">' . $toolbar->render() . '</div>';
  114. } else {
  115. echo '<div class="toolbar-row">' . $toolbar . '</div>';
  116. }
  117. }
  118. }
  119. }
  120. /**
  121. * Display buttons in order of arrangement in the buttons array
  122. *
  123. * @access: Public
  124. */
  125. public function buttons(){
  126. $output = '';
  127. $buttons = $this->flag('buttons');
  128. $i = 1;
  129. foreach ($buttons as $button) {
  130. if (is_array($button)) {
  131. //For the OK or proceed button
  132. $hash = generateHash(microtime());
  133. $id = $this->handle . '-button-' . $hash;
  134. $output .= '<input type="button" value="' . $button[0] . '" id="' . $id . '" class="button"/>&nbsp;';
  135. if (isset($button[2])) {
  136. if (isset($button[1])) {
  137. Application::bindEvent('click', $id, $this->handle, $button[1], true);
  138. }
  139. } else {
  140. if (isset($button[1])) {
  141. Application::bindEvent('click', $id, $this->handle, $button[1]);
  142. }
  143. }
  144. } else {
  145. $output .= $button;
  146. }
  147. $i++;
  148. }
  149. return $output;
  150. }
  151. }
  152. ?>