PageRenderTime 50ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/trunk/scripts/AwesomeGridView.js

#
JavaScript | 829 lines | 713 code | 109 blank | 7 comment | 157 complexity | 7c9527e53c170d8ee4499c1767ffccb1 MD5 | raw file
  1. ///<reference path="~/scripts/Awesome.js" />
  2. ///<reference path="~/scripts/AwesomeQuery.js" />
  3. ///<reference path="~/scripts/AwesomeVisuals.js" />
  4. ///<reference path="~/scripts/AwesomeControls.js" />
  5. // Version 1.0
  6. // TODO: Add multiple selecting via keyboard and mouse commands
  7. // TODO: Add adding, removing and reordering columns dynamically
  8. if (typeof (AwesomeVisuals) == "undefined") { alert("AwesomeVisuals required for the GridView"); }
  9. if (typeof (AwesomeControls) == "undefined") { alert("AwesomeControls required for the GridView"); }
  10. if (typeof (AwesomeQuery) == "undefined") { alert("AwesomeQuery required for the GridView"); }
  11. Type.GridView = Type.$++;
  12. Type.GridView = Type.$++;
  13. Type.GridViewColumn = Type.$++;
  14. Type.GridViewRow = Type.$++;
  15. Type.GridViewGroupRow = Type.$++;
  16. Type.GridColumnSize = Type.$++;
  17. GridView.AscSortIcon = "▲";
  18. GridView.DescSortIcon = "▼";
  19. Table.Extensions.Add(new Extension("gridview", GridView));
  20. var $GridView = $Anchor;
  21. var $RowBoundEventArgs = $Array;
  22. function GridView(e) {
  23. if (this.DOM === undefined) {
  24. return GridView.Inherit(GridView.Extend(new Table(e).ClassName("gridview")));
  25. }
  26. var $ = this;
  27. e = $.DOM;
  28. $.__Display = (e.getAttribute("display") || "10").ToInt();
  29. $.Columns = new ObservableArray($);
  30. var c, v, i, l, g, d;
  31. c = $.Head.Rows[0].Cells;
  32. g = e.getElementsByTagName("col");
  33. l = c.length;
  34. for (i = 0; i < l; i++) {
  35. v = c[i];
  36. $.Columns.Add(GridViewColumn.Inherit(GridViewColumn.Extend(v), g[i]));
  37. }
  38. $.__Focus = new Anchor().Position("fixed").X(-100).Y(10).Text("rawr").Href("javascript: Null()");
  39. $.__Multiple = (e.getAttribute("multiple") || "false").ToBoolean();
  40. $.__Sortable = (e.getAttribute("sortable") || "true").ToBoolean();
  41. $.__Selectable = (e.getAttribute("selectable") || "true").ToBoolean();
  42. $.__SelectClass = (e.getAttribute("selectclass") || "selected");
  43. $.__SortClass = (e.getAttribute("sortclass") || "sorted");
  44. $.__ASortClass = (e.getAttribute("ascsortclass") || "");
  45. $.__DSortClass = (e.getAttribute("descsortclass") || "");
  46. $.__RowHeight = (e.getAttribute("rowheight") || "");
  47. $.__Loading = false;
  48. Page.AddElement($.__Focus);
  49. $.__LastIndex = -1;
  50. $.__LastRow = null;
  51. $.OnClick.Add(new Delegate($.__Focus.Focus, $.__Focus));
  52. $.Style(Style.TableLayout, "fixed").NaturalDisplay = "inline-block";
  53. $.Data = new ObservableArray($);
  54. $.SelectedData = new ObservableArray($);
  55. $.Container = new Div().Width($.AttributeWidth());
  56. $.Container.Style(Style.WhiteSpace, "nowrap");
  57. e.parentNode.replaceChild($.Container.DOM, e);
  58. $.ScrollBar = new ScrollBar();
  59. $.ScrollBar.Style(Style.Float, "right");
  60. $.Holder = new Div().Style(Style.Display, "inline-block");
  61. $.Holder.AddElement($);
  62. $.Container.AddElements([$.ScrollBar, $.Holder]);
  63. $.Style(Style.BorderCollapse, "separate");
  64. $.AscSortIcon = GridView.AscSortIcon;
  65. $.DescSortIcon = GridView.DescSortIcon;
  66. $.SortIcon = new Span().Style(Style.Float, "right");
  67. $.OnSelectionChanged = $.SelectedData.OnChange;
  68. $.OnRowBound = new Event($);
  69. $.MessageRow = new Row();
  70. $.MessageRow.Cells.Add(new Cell());
  71. $.__Focus.OnKeyDown.Add(new Delegate($.HandleKey, $, Delegate.Event));
  72. $.ScrollBar.OnScrollChange.Add(new Delegate($.Refresh, $));
  73. $.OnMouseWheel.Add(new Delegate($.HandleScroll, $, Delegate.Event));
  74. v = $.Container.Style(Style.Width);
  75. if (v.Type == Type.String) {
  76. if (v.Contains("%")) {
  77. Client.OnResize.Add(new Delegate($.RefreshWidth, $));
  78. }
  79. }
  80. $.RefreshRows();
  81. $.RefreshWidth();
  82. $.Data.OnChange.Add(new Delegate($.RefreshData, $));
  83. $.RefreshData();
  84. $.SelectedData.OnChange.Add(new Delegate($.Refresh, $));
  85. if ($.Container.onselectstart !== undefined) {
  86. $.Container.onselectstart = function () { return false; };
  87. }
  88. else {
  89. $.Container.OnMouseDown.Add(function (e) { e.Handled = true; e.CancelEvent = true; });
  90. }
  91. if ($.__Sortable) {
  92. $.__Order = SortOrder.Ascending;
  93. c = $.Columns, l = c.length;
  94. d = new Delegate($.Sort, $, Delegate.Event);
  95. for (i = 0; i < l; i++) {
  96. if (c[i].__Sort) {
  97. c[i].OnClick.Add(d);
  98. }
  99. }
  100. }
  101. e.__Sort = null;
  102. e.Type = Type.GridView;
  103. if (Client.Storage.Local) {
  104. i = Client.Storage.Local.GetItem(Page.Location().pathname + ":" + this.DOM.id);
  105. if (i) {
  106. this.Sort(i.s, i.o);
  107. }
  108. }
  109. return e;
  110. }
  111. GridView.prototype.Sort = function (e, o) {
  112. var s, p;
  113. if (e === undefined) {
  114. this.Data.Sort(this.__Sort, this.__Order);
  115. return;
  116. }
  117. if (this.SortIcon.DOM.parentNode) {
  118. this.SortIcon.DOM.parentNode.$.ClassName("");
  119. }
  120. if (e.Sender) {
  121. s = e.Sender, p = s.__Property;
  122. }
  123. else {
  124. p = e;
  125. }
  126. if (!p) {
  127. this.__Order = SortOrder.Ascending;
  128. this.__Sort = null;
  129. this.SortIcon.DOM.parentNode.$.RemoveElement(this.SortIcon).ClassName
  130. return;
  131. }
  132. if (p == this.__Sort) {
  133. this.__Order = this.__Order == SortOrder.Ascending ? SortOrder.Descending : SortOrder.Ascending;
  134. }
  135. else {
  136. this.__Order = o || SortOrder.Ascending;
  137. var a = this.Columns, l = a.length, v, i;
  138. for (i = 0; i < l; i++) {
  139. v = a[i];
  140. if (v.__Property == p) {
  141. v.InsertElement(0, this.SortIcon);
  142. break;
  143. }
  144. }
  145. }
  146. this.SortIcon.Text(this.__Order == SortOrder.Ascending ? this.AscSortIcon : this.DescSortIcon);
  147. this.SortIcon.DOM.parentNode.$.ClassName(this.__SortClass || (this.__Order == SortOrder.Ascending ? this.__ASortClass : this.__DSortClass) || "");
  148. this.__Sort = p;
  149. this.Data.Sort(p, this.__Order);
  150. this.Refresh();
  151. if (Client.Storage.Local) {
  152. Client.Storage.Local.SetItem(Page.Location().pathname + ":" + this.DOM.id, { s: this.__Sort, o: this.__Order });
  153. }
  154. return this;
  155. };
  156. GridView.prototype.Bind = function (data) {
  157. var v = this.ScrollBar.Value();
  158. this.Data.BeginUpdate();
  159. this.Data.Clear();
  160. if (data) {
  161. this.Data.AddRange(data);
  162. }
  163. if (this.Data.length == 0) {
  164. this.MessageRow.Cells[0].Text("No items");
  165. }
  166. this.__LastIndex = -1;
  167. this.__LastRow = null;
  168. this.__Loading = false;
  169. this.Data.EndUpdate();
  170. this.Refresh()
  171. this.ScrollBar.Value(v);
  172. this.SelectedData.Clear();
  173. };
  174. GridView.prototype.Loading = function (txt) {
  175. this.Data.Clear();
  176. txt = txt || "Loading...";
  177. this.__Loading = true;
  178. this.MessageRow.Cells[0].Text(txt);
  179. return this;
  180. };
  181. GridView.prototype.Refresh = function () {
  182. if (this.__Loading) { return; }
  183. var r = this.Rows, l = r.length, v, u, i, c, s;
  184. this.__LastRow = -1;
  185. var o = document.createElement("TBODY");
  186. this.Body.DOM.parentNode.replaceChild(o, this.Body.DOM);
  187. for (i = 1, j = this.ScrollBar.Value(); i < l; i++, j++) {
  188. v = this.Data[j];
  189. u = r[i];
  190. s = this.SelectedData.Contains(v);
  191. c = s ? this.__SelectClass : "";
  192. u.Bind(v).ClassName(c);
  193. if (this.OnRowBound.length > 0) {
  194. this.OnRowBound.Fire(new RowBoundEventArgs(this, u, v));
  195. }
  196. if (s) {
  197. this.__LastRow = i;
  198. }
  199. u.Index = j;
  200. }
  201. if (this.Data.length > 0) {
  202. this.Rows[0].Collapsed(true);
  203. this.Rows[1].Collapsed(false);
  204. }
  205. else {
  206. this.Rows[0].Collapsed(false).Cells[0].Text("No items.").ColumnSpan(this.Columns.length);
  207. this.Rows[1].Collapsed(true);
  208. }
  209. o.parentNode.replaceChild(this.Body.DOM, o);
  210. delete o;
  211. return this;
  212. };
  213. GridView.prototype.RefreshData = function () {
  214. if (this.__Sort) {
  215. this.Sort();
  216. }
  217. var i, c = this.Columns, l = c.length, j, d = this.Data, k = d.length;
  218. for (j = 0; j < k; j++) {
  219. d[j].__P = new Array();
  220. for (i = 0; i < l; i++) {
  221. d[j].__P[i] = c[i].__Premutate(d[j]);
  222. }
  223. }
  224. if (this.Data.length <= this.__Display) {
  225. this.ScrollBar.Collapsed(true);
  226. this.ScrollBar.MaxValue(0);
  227. this.Refresh();
  228. this.RefreshWidth();
  229. return;
  230. }
  231. else {
  232. this.ScrollBar.Collapsed(false);
  233. this.RefreshWidth();
  234. this.ScrollBar.Height(this.LayoutHeight()).__RefreshView();
  235. this.ScrollBar.MaxValue(this.Data.length - this.__Display);
  236. this.Refresh();
  237. }
  238. };
  239. GridView.prototype.ScrollToItem = function (item) {
  240. if (item) {
  241. var index = this.Data.IndexOf(item), a = this.ScrollBar.Value(), b = this.__Display, c = b + a;
  242. if (index >= a && index < c) {
  243. return;
  244. }
  245. else if (index >= c) {
  246. this.ScrollBar.Value(index - b + 1);
  247. }
  248. else if (index < a) {
  249. this.ScrollBar.Value(index);
  250. }
  251. }
  252. };
  253. GridView.prototype.RowHeight = function (v) {
  254. if (v === undefined) {
  255. return this.__RowHeight;
  256. }
  257. this.__RowHeight = v;
  258. this.RefreshRows();
  259. this.Refresh();
  260. }
  261. GridView.prototype.DisplayRows = function (d) {
  262. if (d === undefined) {
  263. return this.__Display;
  264. }
  265. if (this.__Display != d) {
  266. this.__Display = d;
  267. this.RefreshRows();
  268. this.Refresh();
  269. }
  270. return this;
  271. }
  272. GridView.prototype.RefreshRows = function () {
  273. this.Rows.BeginUpdate();
  274. this.Rows.Clear();
  275. var i, r = [], v, l = this.__Display;
  276. var d = new Delegate(this.HandleClick, this, Delegate.Event);
  277. r.Add(this.MessageRow.Collapsed(true));
  278. this.MessageRow.Cells[0].AttributeHeight(this.__RowHeight);
  279. for (i = 0; i < l; i++) {
  280. v = new GridViewRow();
  281. v.RefreshColumns(this.Columns);
  282. v.Bind(null);
  283. if (this.__Selectable) {
  284. v.OnClick.Add(d);
  285. v.OnContextMenu.Add(d);
  286. }
  287. if (this.__RowHeight) {
  288. v.Cells[0].AttributeHeight(this.__RowHeight);
  289. }
  290. r.Add(v);
  291. }
  292. this.Rows.AddRange(r);
  293. this.Rows.EndUpdate();
  294. };
  295. GridView.prototype.HandleClick = function (e) {
  296. if (e.Sender.Tag) {
  297. if (this.SelectedData.Contains(e.Sender.Tag)) { return; }
  298. this.SelectedData.BeginUpdate();
  299. this.SelectedData.Clear();
  300. this.SelectedData.Add(e.Sender.Tag);
  301. this.__LastIndex = e.Sender.Index;
  302. this.SelectedData.EndUpdate();
  303. }
  304. };
  305. GridView.prototype.HandleScroll = function (e) {
  306. if (this.ScrollBar.Collapsed()) { return; }
  307. this.ScrollBar.Value(this.ScrollBar.Value() + e.Clicks);
  308. e.Handled = true;
  309. };
  310. GridView.prototype.HandleKey = function (e) {
  311. var i = this.__LastIndex, d = this.Data, sd = this.SelectedData;
  312. if (d.length == 0) { return; }
  313. e.Handled = true;
  314. switch (e.Key) {
  315. case Keys.DownArrow:
  316. sd.BeginUpdate();
  317. if (false) {
  318. }
  319. else {
  320. i++;
  321. if (i >= d.length) {
  322. i = d.length - 1;
  323. }
  324. if (this.__LastIndex == i) {
  325. d.Updating = false;
  326. return;
  327. }
  328. this.__LastIndex = i;
  329. sd.Clear();
  330. sd.Add(d[i]);
  331. if (this.__LastRow == this.__Display) {
  332. this.ScrollBar.Value(this.ScrollBar.Value() + 1);
  333. d.Updating = false;
  334. return;
  335. }
  336. }
  337. sd.EndUpdate();
  338. break;
  339. case Keys.UpArrow:
  340. sd.BeginUpdate();
  341. if (false) {
  342. }
  343. else {
  344. i--;
  345. if (i < 0) {
  346. i = 0;
  347. }
  348. if (this.__LastIndex == i) {
  349. d.Updating = false;
  350. return;
  351. }
  352. this.__LastIndex = i;
  353. sd.Clear();
  354. sd.Add(d[i]);
  355. if (this.__LastRow == 1) {
  356. this.ScrollBar.Value(this.ScrollBar.Value() - 1);
  357. sd.Updating = false;
  358. return;
  359. }
  360. }
  361. sd.EndUpdate();
  362. break;
  363. case Keys.Home:
  364. sd.BeginUpdate();
  365. if (false) {
  366. }
  367. else {
  368. this.__LastIndex = 0;
  369. sd.Clear();
  370. sd.Add(d[0]);
  371. this.ScrollBar.Value(0);
  372. sd.Updating = false;
  373. }
  374. sd.EndUpdate();
  375. break;
  376. case Keys.End:
  377. sd.BeginUpdate();
  378. if (false) {
  379. }
  380. else {
  381. i = d.length - 1;
  382. this.__LastIndex = i;
  383. sd.Clear();
  384. sd.Add(d[i]);
  385. this.ScrollBar.Value(i);
  386. sd.Updating = false;
  387. }
  388. sd.EndUpdate();
  389. break;
  390. case Keys.PageUp:
  391. sd.BeginUpdate();
  392. if (false) {
  393. }
  394. else {
  395. i = i - 10;
  396. if (i < 0) {
  397. i = 0;
  398. }
  399. this.__LastIndex = i;
  400. sd.Clear();
  401. sd.Add(d[i]);
  402. this.ScrollBar.Value(this.ScrollBar.Value() - this.__Display);
  403. sd.Updating = false;
  404. }
  405. sd.EndUpdate();
  406. break;
  407. case Keys.PageDown:
  408. sd.BeginUpdate();
  409. if (false) {
  410. }
  411. else {
  412. i = i + 10;
  413. if (i >= d.length) {
  414. i = d.length - 1;
  415. }
  416. this.__LastIndex = i;
  417. sd.Clear();
  418. sd.Add(d[i]);
  419. this.ScrollBar.Value(this.ScrollBar.Value() + this.__Display);
  420. sd.Updating = false;
  421. }
  422. sd.EndUpdate();
  423. break;
  424. }
  425. };
  426. GridView.prototype.RefreshWidth = function () {
  427. var a = this.Columns, l = a.length, v, w, u, i, o;
  428. o = document.createElement("THEAD");
  429. this.AttributeWidth(0);
  430. var total = this.Container.LayoutWidth() - this.ScrollBar.LayoutWidth();
  431. this.AttributeWidth(total);
  432. this.Head.DOM.parentNode.replaceChild(o, this.Head.DOM);
  433. var lq = [];
  434. for (i = 0; i < l; i++) {
  435. w = this.Columns[i];
  436. v = w.__Width;
  437. switch (v.Type) {
  438. case GridColumnSizeType.Static:
  439. w.Width(w.Value);
  440. total -= w.Value;
  441. break;
  442. case GridColumnSizeType.Relative:
  443. u = total * v.Value;
  444. w.Width(u);
  445. total -= u;
  446. break;
  447. case GridColumnSizeType.Liquid:
  448. lq.Add(w);
  449. break;
  450. }
  451. }
  452. l = lq.length;
  453. u = (total / lq.length).Round();
  454. for (i = 0; i < l; i++) {
  455. lq[i].Width(u);
  456. }
  457. o.parentNode.replaceChild(this.Head.DOM, o);
  458. delete o;
  459. return this;
  460. };
  461. function GridViewColumn(c) {
  462. if (this.DOM === undefined) {
  463. return GridViewColumn.Inherit(GridViewColumn.Extend(new Header()));
  464. }
  465. var $ = this;
  466. var e = $.DOM;
  467. $.Style(Style.Overflow, "hidden").Style(Style.WhiteSpace, "nowrap").Position("relative"); ;
  468. if (c) {
  469. $.__HAlign = c.getAttribute("align") || "left";
  470. $.__VAlign = c.getAttribute("valign") || "top";
  471. $.__Style = c.getAttribute("style") || "";
  472. $.__Class = c.getAttribute("class") || "";
  473. }
  474. else {
  475. $.__HAlign = "left";
  476. $.__VAlign = "top";
  477. $.__Style = "";
  478. $.__Class = "";
  479. }
  480. $.__HTML = (e.getAttribute("html") || "false").ToBoolean();
  481. $.__Sort = (e.getAttribute("sortable") || "true").ToBoolean();
  482. $.__Type = e.getAttribute("columntype") || "data";
  483. $.__Prec = (e.getAttribute("precision") || "2").ToInt();
  484. $.__Format = e.getAttribute("format") || "";
  485. $.__Width = new GridColumnSize(e.getAttribute("width") || "*");
  486. $.__Property = e.getAttribute("property") || "";
  487. $.OnColumnBound = new Event($);
  488. var o = e.getAttribute("onbound");
  489. if (o) {
  490. $.OnColumnBound.Add(window[o]);
  491. }
  492. switch ($.__Type) {
  493. case GridViewColumnType.Image:
  494. $.__Map = window[e.getAttribute("map")];
  495. break;
  496. case GridViewColumnType.ImageAction:
  497. $.__Map = window[e.getAttribute("map")];
  498. $.__Func = window[e.getAttribute("function")];
  499. break;
  500. case GridViewColumnType.Link:
  501. $.__Href = e.getAttribute("href");
  502. $.__Target = e.getAttribute("target") || "";
  503. $.__Text = e.getAttribute("text") || "{" + $.__Property + "}";
  504. $.__Popup = e.getAttribute("popup");
  505. break;
  506. case GridViewColumnType.Action:
  507. $.__Func = window[e.getAttribute("function")];
  508. $.__Text = e.getAttribute("text") || "{" + $.__Property + "}";
  509. break;
  510. }
  511. $.Type = Type.GridViewColumn;
  512. }
  513. GridViewColumn.prototype.__Premutate = function (d) {
  514. var w = this, u, v;
  515. switch (w.__Type) {
  516. case GridViewColumnType.Image:
  517. u = v = w.__Map[Awesome.EvalBind(w.__Property, d).toString()];
  518. break;
  519. case GridViewColumnType.ImageAction:
  520. u = w.__Map[Awesome.EvalBind(w.__Property, d).toString()];
  521. break;
  522. case GridViewColumnType.Link:
  523. v = String.BindFormat(w.__Href, d);
  524. u = String.BindFormat(w.__Text, d);
  525. break;
  526. case GridViewColumnType.Action:
  527. u = String.BindFormat(w.__Text, d);
  528. break;
  529. default:
  530. u = Awesome.EvalBind(w.__Property, d);
  531. if (!NullOrUndefined(u)) {
  532. u = u.toString();
  533. switch (w.__Format) {
  534. case GridViewColumnFormat.Currency:
  535. u = u.FormatCurrency(w.__Prec);
  536. break;
  537. case GridViewColumnFormat.Number:
  538. u = u.FormatNumber(w.__Prec);
  539. }
  540. }
  541. break;
  542. }
  543. return { __T: u, __D: v };
  544. };
  545. var GridViewColumnType = {
  546. Data: "data",
  547. Image: "image",
  548. Link: "link",
  549. Action: "action",
  550. ImageAction: "imageaction",
  551. Menu: "menu"
  552. };
  553. var GridViewColumnFormat = {
  554. Currency: "currency",
  555. Number: "number"
  556. };
  557. function GridViewRow(e) {
  558. return GridViewRow.Extend(new Row());
  559. }
  560. GridViewRow.prototype.Bind = function (d) {
  561. this.Tag = d;
  562. this.Index = 0;
  563. var a = this.Cells, l = a.length, i, v, w, u, t, ev = new ColumnBoundEventArgs();
  564. for (i = 0; i < l; i++) {
  565. v = a[i];
  566. w = v.__Col;
  567. ev.Cancel = false;
  568. if (!NullOrUndefined(d) && w.OnColumnBound.length > 0) {
  569. ev.Column = w;
  570. ev.Item = d;
  571. ev.Sender = v;
  572. w.OnColumnBound.Fire(ev);
  573. }
  574. if (!d || ev.Cancel) {
  575. switch (w.__Type) {
  576. case GridViewColumnType.Image:
  577. case GridViewColumnType.Link:
  578. case GridViewColumnType.Action:
  579. v.DOM.firstChild.$.Collapsed(true);
  580. break;
  581. default:
  582. v.Content("&nbsp;");
  583. break;
  584. }
  585. }
  586. else {
  587. u = d.__P[i].__D;
  588. t = d.__P[i].__T;
  589. switch (w.__Type) {
  590. case GridViewColumnType.Image:
  591. if (u) {
  592. v.DOM.firstChild.$.Collapsed(false).Source(u);
  593. }
  594. else {
  595. v.DOM.firstChild.$.Collapsed(true);
  596. }
  597. break;
  598. case GridViewColumnType.ImageAction:
  599. if (u) {
  600. v.DOM.firstChild.$.Collapsed(false).Source(u);
  601. }
  602. else {
  603. v.DOM.firstChild.$.Collapsed(true);
  604. }
  605. v.DOM.firstChild.$.OnClick[0].Parameters[0] = d;
  606. break;
  607. case GridViewColumnType.Link:
  608. v.DOM.firstChild.$.Collapsed(false);
  609. if (u) {
  610. if (w.__Popup) {
  611. v.DOM.firstChild.$.OnClick[0].Parameters[0] = u;
  612. }
  613. else {
  614. v.DOM.firstChild.$.Href(u);
  615. }
  616. }
  617. if (t) {
  618. v.DOM.firstChild.$.Text(t);
  619. }
  620. break;
  621. case GridViewColumnType.Action:
  622. v.DOM.firstChild.$.Collapsed(false);
  623. v.DOM.firstChild.$.Text(t);
  624. break;
  625. default:
  626. if (w.__HTML) {
  627. v.Content(t);
  628. }
  629. else {
  630. v.Text(t);
  631. }
  632. break;
  633. }
  634. }
  635. }
  636. return this;
  637. };
  638. GridViewRow.prototype.RefreshColumns = function (columns) {
  639. this.Cells.BeginUpdate();
  640. this.Cells.Clear();
  641. var a = columns;
  642. var l = a.length;
  643. var i, v, c = [], b, u, h, w, s;
  644. for (i = 0; i < l; i++) {
  645. v = a[i];
  646. b = new Cell()
  647. .ClassName(v.__Class)
  648. .HorizontalAlignment(v.__HAlign)
  649. .VerticalAlignment(v.__VAlign);
  650. b.DOM.setAttribute("style", v.__Style);
  651. b.Style(Style.Overflow, "hidden").Style(Style.WhiteSpace, "nowrap");
  652. b.__Col = v;
  653. switch (v.__Type) {
  654. case GridViewColumnType.Image:
  655. b.AddElement(new ImageElement());
  656. break;
  657. case GridViewColumnType.Link:
  658. u = new Anchor().Target(v.__Target);
  659. b.AddElement(u);
  660. if (v.__Popup) {
  661. s = v.__Popup.split(",");
  662. u.OnClick.Add(new Delegate(Client.Popup, null, null, s[0].ToInt(), s[1].ToInt()));
  663. }
  664. break;
  665. case GridViewColumnType.Action:
  666. u = new Anchor();
  667. b.AddElement(u);
  668. u.OnClick.Add(new Delegate(v.DoAction, this, v.__Func));
  669. break;
  670. }
  671. c.Add(b);
  672. }
  673. this.Cells.AddRange(c);
  674. this.Cells.EndUpdate();
  675. };
  676. var GridColumnSizeType = {
  677. Static: 0,
  678. Relative: 1,
  679. Liquid: 2
  680. };
  681. GridViewColumn.prototype.DoAction = function (a) {
  682. a(this.Tag);
  683. };
  684. function GridColumnSize(value) {
  685. this.Value = null;
  686. this.ColumnsType = GridColumnSizeType.Liquid;
  687. this.Type = Type.GridColumnSize;
  688. switch (value.Type) {
  689. case Type.String:
  690. if (value.EndsWith("%")) {
  691. this.Value = value.Remove("%").ToFloat() / 100;
  692. this.ColumnsType = GridColumnSizeType.Relative;
  693. }
  694. else if (value == "*") {
  695. this.Value = null;
  696. this.ColumnsType = GridColumnSizeType.Liquid;
  697. }
  698. else if (value.IsInt()) {
  699. this.Value = value.ToInt();
  700. this.ColumnsType = GridColumnSizeType.Static;
  701. }
  702. break;
  703. case Type.Number:
  704. this.Value = value;
  705. this.ColumnsType = GridColumnSizeType.Static;
  706. break;
  707. }
  708. }
  709. function RowBoundEventArgs(sender, row, item) {
  710. this.Sender = sender;
  711. this.Row = row;
  712. this.Item = item;
  713. this.Cancel = false;
  714. }
  715. function ColumnBoundEventArgs(sender, col, item) {
  716. this.Sender = sender;
  717. this.Column = col;
  718. this.Item = item;
  719. this.Cancel = false;
  720. }