Notices.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. o2.widget = o2.widget || {};
  2. o2.require("o2.widget.Common", null, false);
  3. o2.widget.Notices = new Class({
  4. Implements: [Options, Events],
  5. Extends: o2.widget.Common,
  6. options: {
  7. "style": "default",
  8. "type": "default", // the type of the notice (defaults to 'default'), possible types are: 'ok', 'error', 'info', 'notice'
  9. "target": null,
  10. "delayClose": 1000,
  11. "offset": {x: 10, y: 10},
  12. "content": ""
  13. },
  14. initialize: function(options){
  15. this.setOptions(options);
  16. this.node = $(node);
  17. this.container = new Element("div");
  18. this.path = o2.session.path+"/widget/$Panel/";
  19. this.cssPath = o2.session.path+"/widget/$Panel/"+this.options.style+"/css.wcss";
  20. this._loadCss();
  21. this.setStatus();
  22. o2.widget.Panel.panels.push(this);
  23. },
  24. load: function(){
  25. if (this.fireEvent("queryLoad")){
  26. this.container.set("styles", this.css.container);
  27. this.container.set("styles", {
  28. "width": this.options.width,
  29. "height": this.options.height
  30. });
  31. this.createTitleNode();
  32. this.content = new Element("div", {
  33. "styles": this.css.panelContent
  34. }).inject(this.container);
  35. this.createBottomNode();
  36. if (!this.options.target) this.options.target = $(document.body);
  37. this.container.inject(this.options.target);
  38. this.content.setStyle("height", this.getContentHeight());
  39. this.node.inject(this.content);
  40. this.setPositions();
  41. if (this.options.isMove) this.setMove();
  42. if (this.options.isResize) this.setResize();
  43. this.show();
  44. this.fireEvent("postLoad");
  45. }
  46. },
  47. show: function(){
  48. if (!this.showHideMorph){
  49. this.showHideMorph = new Fx.Morph(this.container, {
  50. "duration": this.options.duration,
  51. "transition": this.options.transition
  52. });
  53. }
  54. this.showHideMorph.start(this.css.containerShow);
  55. },
  56. getContentHeight: function(top, bottom, container){
  57. var topSize = top;
  58. if (!topSize) topSize = this.titleNode.getSize();
  59. var bottomSize = bottom;
  60. if (!bottomSize) bottomSize = this.bottomNode.getSize();
  61. var containerSize = container;
  62. if (!containerSize) containerSize = this.container.getSize();
  63. paddingTop = this.container.getStyle("padding-top");
  64. paddingBottom = this.container.getStyle("padding-bottom");
  65. paddingLeft = this.container.getStyle("padding-left");
  66. paddingRight = this.container.getStyle("padding-right");
  67. this.options.height = (containerSize.y.toFloat())-(paddingTop.toFloat())-(paddingBottom.toFloat());
  68. this.options.width = (containerSize.x.toFloat())-(paddingLeft.toFloat())-(paddingRight.toFloat());
  69. // var contentHeight = (containerSize.y.toFloat())-(paddingTop.toFloat())-(paddingBottom.toFloat())-(topSize.y.toFloat())-(bottomSize.y.toFloat());
  70. var contentHeight = (this.options.height.toFloat())-(topSize.y.toFloat())-(bottomSize.y.toFloat());
  71. if (contentHeight<10){
  72. contentHeight = 10;
  73. // this.options.height = contentHeight+(topSize.y.toFloat())+(bottomSize.y.toFloat());
  74. }
  75. return contentHeight;
  76. },
  77. setMove: function(){
  78. //this.titleNode.setStyle("cursor", "move");
  79. this.panelMove = new Drag.Move(this.container, {
  80. "container": this.options.target,
  81. "handle": this.titleNode,
  82. "onComplete": function(){
  83. this.options.top = this.container.getStyle("top").toFloat();
  84. this.options.left = this.container.getStyle("left").toFloat();
  85. this.fireEvent("completeMove");
  86. }.bind(this)
  87. });
  88. },
  89. setResize: function(){
  90. this.container.makeResizable({
  91. "handle": this.resizeAction,
  92. "onDrag": function(){
  93. this.content.setStyle("height", this.getContentHeight());
  94. this.fireEvent("resize");
  95. }.bind(this),
  96. "limit": {x:[120,null], y:[120,null]}
  97. });
  98. },
  99. setPositions: function(){
  100. if (this.options.status.active){
  101. var p = this.options.target.getPosition();
  102. var top = (p.y.toFloat()) + (this.options.top.toFloat());
  103. var left = (p.x.toFloat()) + (this.options.left.toFloat());
  104. var pNode = this.options.target.getOffsetParent();
  105. if (pNode){
  106. var pNodePosition = pNode.getPosition();
  107. top = top - pNodePosition.y;
  108. left = left - pNodePosition.x;
  109. };
  110. this.container.setStyles({
  111. "position": "absolute",
  112. "top": top,
  113. "left": left
  114. });
  115. // this.container.setPosition({"x": left, "y": top});
  116. // alert(top)
  117. // this.container.position({
  118. // relativeTo: this.options.target,
  119. // position: 'upperRight',
  120. // edge: 'upperRight'
  121. // });
  122. }
  123. },
  124. setStatus: function(){
  125. this.options.status = {};
  126. this.options.status.active = true;
  127. this.options.status.expand = true;
  128. this.options.status.max = false;
  129. },
  130. createTitleNode: function(){
  131. this.titleNode = new Element("div", {
  132. "styles": this.css.panelTitleNode
  133. }).inject(this.container);
  134. this.actionNode = new Element("div", {
  135. "styles": this.css.panelActionNode
  136. }).inject(this.titleNode);
  137. this.textNode = new Element("div", {
  138. "styles": this.css.panelTextNode,
  139. "text": this.options.title
  140. }).inject(this.titleNode);
  141. if (this.options.isClose) this.createCloseAction();
  142. if (this.options.isMax) this.createMaxAction();
  143. if (this.options.isExpand) this.createExpandAction();
  144. this.titleNode.addEvent("click", function(){
  145. var maxIndex = this.container.getStyle("z-index").toInt();
  146. var idx = maxIndex;
  147. o2.widget.Panel.panels.each(function(panel){
  148. var index = panel.container.getStyle("z-index");
  149. if (maxIndex.toFloat()<index.toFloat()){
  150. maxIndex = index;
  151. }
  152. }.bind(this));
  153. maxIndex = (maxIndex.toFloat())+1;
  154. if (idx!=maxIndex){
  155. this.container.setStyle("z-index", maxIndex);
  156. }
  157. }.bind(this));
  158. },
  159. createCloseAction: function(){
  160. this.closeAction = new Element("div", {
  161. "styles": this.css.closeAction
  162. }).inject(this.actionNode);
  163. this.closeAction.addEvent("click", function(){
  164. this.closePanel();
  165. }.bind(this));
  166. },
  167. closePanel: function(){
  168. this.fireEvent("queryClose");
  169. if (!this.showHideMorph){
  170. this.showHideMorph = new Fx.Morph(this.container, {
  171. "duration": this.options.duration,
  172. "transition": this.options.transition
  173. });
  174. }
  175. this.showHideMorph.start(this.css.container).chain(function(){
  176. o2.widget.Panel.panels.erase(this);
  177. this.container.destroy();
  178. this.fireEvent("postClose");
  179. }.bind(this));
  180. },
  181. destroy: function(){
  182. this.container.destroy();
  183. },
  184. createMaxAction: function(){
  185. this.maxAction = new Element("div", {
  186. "styles": this.css.maxAction
  187. }).inject(this.actionNode);
  188. this.maxAction.addEvent("click", function(){
  189. this.maxReturnPanel();
  190. }.bind(this));
  191. },
  192. maxReturnPanel: function(){
  193. if (this.options.status.max){
  194. this.returnPanel();
  195. var img = this.maxAction.getStyle("background-image");
  196. img = img.replace(/return.gif/g, "max.gif");;
  197. this.maxAction.setStyle("background-image", img);
  198. this.options.status.max = false;
  199. }else{
  200. this.maxPanel();
  201. var img = this.maxAction.getStyle("background-image");
  202. img = img.replace(/max.gif/g, "return.gif");;
  203. this.maxAction.setStyle("background-image", img);
  204. this.options.status.max = true;
  205. }
  206. this.fireEvent("resize");
  207. },
  208. returnPanel: function(){
  209. if (!this.options.status.expand) this.setExpand();
  210. this.container.setStyles({
  211. "position": "absolute",
  212. "top": this.options.top,
  213. "left": this.options.left,
  214. "width": this.returnMaxContainerSize.x,
  215. "height": this.returnMaxContainerSize.y
  216. });
  217. this.content.setStyle("height", this.getContentHeight());
  218. this.panelMove.attach();
  219. // this.resizeAction.setStyle("display", "block");
  220. },
  221. maxPanel: function(){
  222. if (!this.options.status.expand) this.setExpand();
  223. this.returnMaxContainerSize = this.container.getSize();
  224. var size = $(document.body).getSize();
  225. this.container.setStyles({
  226. "position": "absolute",
  227. "top": 2,
  228. "left": 2,
  229. "width": size.x-6,
  230. "height": size.y
  231. });
  232. this.panelMove.detach();
  233. // this.resizeAction.setStyle("display", "none");
  234. this.content.setStyle("height", this.getContentHeight());
  235. },
  236. createExpandAction: function(){
  237. this.explandAction = new Element("div", {
  238. "styles": this.css.explandAction
  239. }).inject(this.actionNode);
  240. this.explandAction.addEvent("click", function(){
  241. this.explandPanel();
  242. }.bind(this));
  243. },
  244. explandPanel: function(){
  245. if (this.options.status.expand){
  246. this.collapse();
  247. var img = this.explandAction.getStyle("background-image");
  248. img = img.replace(/up.gif/g, "down.gif");;
  249. this.explandAction.setStyle("background-image", img);
  250. this.options.status.expand = false;
  251. }else{
  252. this.expand();
  253. var img = this.explandAction.getStyle("background-image");
  254. img = img.replace(/down.gif/g, "up.gif");;
  255. this.explandAction.setStyle("background-image", img);
  256. this.options.status.expand = true;
  257. }
  258. },
  259. collapse: function(){
  260. this.returnTopSize = this.titleNode.getSize();
  261. this.returnBottomSize = this.bottomNode.getSize();
  262. this.returnContainerSize = this.container.getSize();
  263. if (!this.containerTween){
  264. this.containerTween = new Fx.Tween(this.container, {
  265. "duration": this.options.duration,
  266. "transition": this.options.transition
  267. });
  268. }
  269. if (!this.bottomTween){
  270. this.bottomTween = new Fx.Tween(this.bottomNode, {
  271. "duration": this.options.duration,
  272. "transition": this.options.transition
  273. });
  274. }
  275. if (!this.contentTween){
  276. this.contentTween = new Fx.Tween(this.content, {
  277. "duration": this.options.duration,
  278. "transition": this.options.transition
  279. });
  280. }
  281. this.containerTween.options.transition = this.options.transition;
  282. this.bottomTween.options.transition = this.options.transition;
  283. this.contentTween.options.transition = this.options.transition;
  284. this.contentTween.start("height", 0);
  285. this.bottomTween.start("height", 0);
  286. this.containerTween.start("height", this.returnTopSize.y).chain(function(){
  287. this.bottomNode.setStyle("display", "none");
  288. this.content.setStyle("display", "none");
  289. }.bind(this));
  290. },
  291. expand: function(){
  292. if (!this.containerTween){
  293. this.containerTween = new Fx.Tween(this.container, {
  294. "duration": this.options.duration,
  295. "transition": this.options.transition
  296. });
  297. }
  298. if (!this.bottomTween){
  299. this.bottomTween = new Fx.Tween(this.bottomNode, {
  300. "duration": this.options.duration,
  301. "transition": this.options.transition
  302. });
  303. }
  304. if (!this.contentTween){
  305. this.contentTween = new Fx.Tween(this.content, {
  306. "duration": this.options.duration,
  307. "transition": this.options.transition
  308. });
  309. }
  310. this.containerTween.options.transition = this.options.transitionOut;
  311. this.bottomTween.options.transition = this.options.transitionOut;
  312. this.contentTween.options.transition = this.options.transitionOut;
  313. this.bottomNode.setStyle("display", "block");
  314. this.content.setStyle("display", "block");
  315. this.containerTween.start("height", (this.returnContainerSize.y.toFloat())-(this.container.getStyle("padding-top").toFloat())-(this.container.getStyle("padding-bottom").toFloat())-2);
  316. this.contentTween.start("height", (this.options.height.toFloat())-(this.returnTopSize.y.toFloat())-(this.returnBottomSize.y.toFloat()));
  317. this.bottomTween.start("height", this.returnBottomSize.y);
  318. },
  319. setExpand: function(){
  320. this.container.setStyle("height", (this.returnContainerSize.y.toFloat())-(this.container.getStyle("padding-top").toFloat())-(this.container.getStyle("padding-bottom").toFloat())-2);
  321. this.content.setStyle("height", (this.options.height.toFloat())-(this.returnTopSize.y.toFloat())-(this.returnBottomSize.y.toFloat()));
  322. this.bottomNode.setStyle("height", this.returnBottomSize.y);
  323. this.bottomNode.setStyle("display", "block");
  324. this.content.setStyle("display", "block");
  325. var img = this.explandAction.getStyle("background-image");
  326. img = img.replace(/down.gif/g, "up.gif");;
  327. this.explandAction.setStyle("background-image", img);
  328. this.options.status.expand = true;
  329. },
  330. createBottomNode: function(){
  331. this.bottomNode = new Element("div", {
  332. "styles": this.css.bottomNode
  333. }).inject(this.container);
  334. if (this.options.isResize) this.createResizeAction();
  335. },
  336. createResizeAction: function(){
  337. this.resizeAction = new Element("div", {
  338. "styles": this.css.resizeAction
  339. }).inject(this.bottomNode);
  340. }
  341. });
  342. o2.widget.Panel.panels = [];