pagelayout.xts 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. Licensed Materials - Property of IBM
  4. IBM Cognos Products: cpscrn
  5. (C) Copyright IBM Corp. 2005, 2011
  6. US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. -->
  8. <!--
  9. Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
  10. Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
  11. -->
  12. <!-- $Header: //cpscrn/main/templates/fragments/pagelayout/pagelayout.xts#1 $ -->
  13. <!-- $DateTime: 2008/10/22 11:12:04 $ -->
  14. <!-- $Change: 25109 $ -->
  15. <xts:morphlet version="1.0" xmlns:xts="http://developer.cognos.com/schemas/xts/">
  16. <!--
  17. Page Layout Fragment
  18. -->
  19. <xts:block id="decode" processor="XSLT" type="exec" mode="interpret"
  20. condition="/root/env/param[@name = 'pagexml']" mandatory="false"
  21. nodelist="env">
  22. <xsl:stylesheet version="1.0"
  23. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  24. xmlns:xts="http://developer.cognos.com/schemas/xts/"
  25. xmlns:xtsext="xalan://com.cognos.xts.ext.XTSExt"
  26. exclude-result-prefixes="xts xtsext">
  27. <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>
  28. <xsl:template match="/">
  29. <xts:sequence>
  30. <xts:append>
  31. <pagelet>
  32. <xsl:value-of select="/root/env/param[@name = 'pagexml']" disable-output-escaping="yes"/>
  33. </pagelet>
  34. </xts:append>
  35. </xts:sequence>
  36. </xsl:template>
  37. </xsl:stylesheet>
  38. </xts:block>
  39. <xts:block id="default-layouts" processor="XML" type="exec" mode="input" path="/fragments/pagelayout/layouts.xml"/>
  40. <xts:block id="response" type="exec" mode="interpret" processor="XSLT"
  41. dependency="decode default-layouts"
  42. nodelist="env, pagelet, layouts">
  43. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  44. xmlns:xts="http://developer.cognos.com/schemas/xts/"
  45. xmlns:xtsext="xalan://com.cognos.xts.ext.XTSExt"
  46. xmlns:xos="http://developer.cognos.com/schemas/xts/output/"
  47. xmlns:cps="http://developer.cognos.com/schemas/cps/asm/objects/1/"
  48. xmlns:wsrp="urn:oasis:names:tc:wsrp:v1:types"
  49. xmlns:cpsext="http://developer.cognos.com/schemas/cps/wsrp/extensions/1/"
  50. exclude-result-prefixes="xts xtsext cps xos wsrp cpsext">
  51. <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>
  52. <xsl:key name="env-param" match="/root/env/param" use="@name"/>
  53. <xsl:key name="http-param" match="/root/http/param" use="@name"/>
  54. <xsl:variable name="frag-id" select="key('env-param', 'frag-id')"/>
  55. <xsl:variable name="frag-state" select="key('env-param', 'frag-state')"/>
  56. <xsl:variable name="frag-pagemode" select="key('env-param', 'frag-pagemode')"/>
  57. <xsl:variable name="frag-agent" select="key('env-param', 'frag-agent')"/>
  58. <xsl:variable name="read-only" select="key('env-param', 'readonly') = 'true'"/>
  59. <xsl:variable name="pagelet" select="/root/pagelet/*"/>
  60. <xsl:variable name="default-layouts" select="/root/layouts/layout"/>
  61. <!--
  62. if the pagelet layout is not found in the default layouts,
  63. the pagelet layout is added to the list of available layouts
  64. and the current selection index is set to the last entry
  65. otherwise the layout was found in the default layouts
  66. set the index to the matching default layout
  67. -->
  68. <xsl:variable name="pagelet-layout-id">
  69. <xsl:apply-templates select="$pagelet/cps:layout/layout" mode="id"/>
  70. </xsl:variable>
  71. <xsl:variable name="pagelet-layout-index">
  72. <xsl:apply-templates select="$default-layouts" mode="compare-ids">
  73. <xsl:with-param name="id" select="$pagelet-layout-id"/>
  74. </xsl:apply-templates>
  75. </xsl:variable>
  76. <xsl:variable name="calculated-layouts">
  77. <xsl:copy-of select="$default-layouts"/>
  78. <xsl:if test="$pagelet-layout-index = ''">
  79. <xsl:copy-of select="$pagelet/cps:layout/layout"/>
  80. </xsl:if>
  81. </xsl:variable>
  82. <xsl:variable name="layouts" select="$calculated-layouts/*"/>
  83. <xsl:variable name="layout-index">
  84. <xsl:choose>
  85. <xsl:when test="not($pagelet)">
  86. <xsl:value-of select="0"/>
  87. </xsl:when>
  88. <xsl:when test="$pagelet-layout-index = ''">
  89. <xsl:value-of select="count($default-layouts)"/>
  90. </xsl:when>
  91. <xsl:otherwise>
  92. <xsl:value-of select="$pagelet-layout-index"/>
  93. </xsl:otherwise>
  94. </xsl:choose>
  95. </xsl:variable>
  96. <!-- parameters not to be passed into assembler call -->
  97. <xsl:variable name="params-excluded" select="' encoding frag-id frag-state '"/>
  98. <xsl:variable name="interaction-params" select="/root/env/param[not(contains($params-excluded, concat(' ', @name, ' ')))]"/>
  99. <xsl:template match="/">
  100. <xts:sequence>
  101. <xts:append select="/root/output">
  102. <xos:part>
  103. <xos:entityHeader>
  104. <xos:param name="Content-type">text/xml</xos:param>
  105. </xos:entityHeader>
  106. <xos:entityBody>
  107. <xsl:call-template name="fragment"/>
  108. </xos:entityBody>
  109. </xos:part>
  110. </xts:append>
  111. </xts:sequence>
  112. </xsl:template>
  113. <xsl:template name="fragment">
  114. <fragment xmlns="http://developer.cognos.com/fragments/1/">
  115. <info>
  116. <title>Page Layout Editor</title>
  117. <description></description>
  118. </info>
  119. <css type="text/css" media="all" href="$CGI$/css/portlet?skin=$SKIN$"/>
  120. <library type="text/javascript" href="$WEB$/fragments/fragments.js"/>
  121. <library type="text/javascript" href="$WEB$/common/framework/validator/CValidator.js"/>
  122. <library type="text/javascript" href="$WEB$/fragments/pagelayout/script/pagelayout.js"/>
  123. <markup>
  124. <validator>
  125. <param name="readonly">
  126. <validate xmlns:val="http://developer.cognos.com/schemas/validator/1/" skipJavaScript="true">
  127. <val:name>readonly</val:name>
  128. <val:rule>
  129. <val:enumeration emptyValid="false">
  130. <val:list>true,false</val:list>
  131. </val:enumeration>
  132. </val:rule>
  133. </validate>
  134. </param>
  135. <param name="id">
  136. <validate xmlns:val="http://developer.cognos.com/schemas/validator/1/" skipJavaScript="true">
  137. <val:name>id</val:name>
  138. <val:ruleRef xmlns:fragment="urn:cognos:fragments:validator" id="fragment:frag-id"/>
  139. </validate>
  140. </param>
  141. </validator>
  142. <mimeType>text/html</mimeType>
  143. <markupXml>
  144. <script>
  145. var RESOURCE_URI = "_THIS?frag-resource=/fragments/THIS_";
  146. //-------------------------------------------------------------
  147. // Page Layout Editor
  148. // the current CPage object
  149. var _THIS_page = null;
  150. // generate unique ids for the current page session
  151. var _THIS_idcount = 0;
  152. function _THIS_genID()
  153. {
  154. return "P<xsl:value-of select="xtsext:generateGUID()"/>" + (_THIS_idcount++);
  155. }
  156. //-------------------------------------------------------------
  157. // layout menu
  158. <xsl:if test="not ($read-only)">
  159. var _THIS_layouts = [ <xsl:apply-templates select="$layouts" mode="layout"/> ] ;
  160. var _THIS_layoutMenu =
  161. {
  162. current: "<xsl:value-of select="$layout-index"/>",
  163. selectDivs: null,
  164. menu: null,
  165. menuDivs: null,
  166. //- void init()
  167. init: function()
  168. {
  169. this.menu = $("_THIS_layoutmenu");
  170. var container = $("_THIS_layoutselect");
  171. var list = container.childNodes;
  172. this.selectDivs = new Array(list.length);
  173. this.menuDivs = new Array(list.length);
  174. var i, l = list.length;
  175. for (i = 0; i &lt; l; i++)
  176. {
  177. this.selectDivs[i] = list[i];
  178. var div = $("_THIS_layoutitem" + i);
  179. this.menuDivs[i] = div;
  180. div.menuIndex = i;
  181. xAddEventListener(div, "mouseover", function(e) { _THIS_layoutMenu.menuOver(e) }, false);
  182. xAddEventListener(div, "mouseout", function(e) { _THIS_layoutMenu.menuOut(e) }, false);
  183. xAddEventListener(div, "mousedown", function(e) { _THIS_layoutMenu.menuDown(e) }, false);
  184. }
  185. },
  186. //- void select(int index)
  187. select: function(index)
  188. {
  189. if (index == this.current)
  190. return;
  191. if (this.current > -1)
  192. {
  193. xDisplay(this.selectDivs[this.current], "none");
  194. xBackground(this.menuDivs[this.current], "white");
  195. }
  196. if (index > -1)
  197. {
  198. xDisplay(this.selectDivs[index], "block");
  199. xBackground(this.menuDivs[index], "lightgrey");
  200. }
  201. this.current = index;
  202. },
  203. //- void setLayout(index)
  204. setLayout: function(index)
  205. {
  206. this.select(index);
  207. _THIS_page.setLayout("_THIS_page", _THIS_layouts[index]);
  208. },
  209. //- boolean visible()
  210. visible: function()
  211. {
  212. return xVisibility(this.menu) != 'hidden';
  213. },
  214. //- void show()
  215. show: function()
  216. {
  217. xShow(this.menu);
  218. if (!this.menuMDfunc)
  219. {
  220. this.menuMDfunc = function(e)
  221. {
  222. xRemoveEventListener(document, "mousedown", _THIS_layoutMenu.menuMDfunc, false);
  223. _THIS_layoutMenu.hide();
  224. };
  225. }
  226. xAddEventListener(document, "mousedown", this.menuMDfunc, false);
  227. },
  228. //- void hide()
  229. hide: function()
  230. {
  231. xHide(this.menu);
  232. },
  233. //- void toggle()
  234. toggle: function()
  235. {
  236. if (this.visible())
  237. this.hide();
  238. else
  239. this.show();
  240. },
  241. //- void menuOver(Event evt)
  242. menuOver: function(evt)
  243. {
  244. var e = new xEvent(evt);
  245. var ele = e.target;
  246. var obj = _F_findParentObj(ele, "_THIS_layoutitem");
  247. var index = obj.menuIndex;
  248. if (this.menuDivs[index])
  249. {
  250. var div = this.menuDivs[index];
  251. var td = xParent(div, true);
  252. td.style.backgroundColor = "lightblue";
  253. }
  254. },
  255. //- void menuOut(Event evt)
  256. menuOut: function(evt)
  257. {
  258. var e = new xEvent(evt);
  259. var ele = e.target;
  260. var obj = _F_findParentObj(ele, "_THIS_layoutitem");
  261. var index = obj.menuIndex;
  262. if (this.menuDivs[index])
  263. {
  264. var div = this.menuDivs[index];
  265. var td = xParent(div, true);
  266. td.style.backgroundColor = "white";
  267. }
  268. },
  269. //- void menuDown(Event evt)
  270. menuDown: function(evt)
  271. {
  272. xPreventDefault(evt);
  273. var e = new xEvent(evt);
  274. var ele = e.target;
  275. var obj = _F_findParentObj(ele, "_THIS_layoutitem");
  276. var index = obj.menuIndex;
  277. this.setLayout(index);
  278. }
  279. };
  280. </xsl:if>
  281. //-------------------------------------------------------------
  282. // init
  283. _THIS_.ondrop =
  284. function(context)
  285. {
  286. var x = context.xevent.pageX;
  287. var y = context.xevent.pageY;
  288. if (context.type == "portlet" || context.type == "pagelet")
  289. {
  290. switch (context.dropType)
  291. {
  292. case context.ENTER:
  293. _THIS_page.startSelection(x, y);
  294. break;
  295. case context.MOVE:
  296. _THIS_page.moveSelection(x, y);
  297. context.canDrop(_THIS_page.hasSelection());
  298. break;
  299. case context.LEAVE:
  300. _THIS_page.endSelection();
  301. break;
  302. case context.DROP:
  303. var sLayoutId = _THIS_genID();
  304. var sId = "_THIS_" + sLayoutId;
  305. var sPortletId = context.payload.substring(1);
  306. var sTitle = context.title;
  307. var portlet = new CPortlet(sId, sLayoutId, sPortletId, sTitle);
  308. _THIS_page.insertPortlet(portlet);
  309. portlet.retrieve();
  310. _THIS_page.endSelection();
  311. break;
  312. }
  313. }
  314. };
  315. _THIS_.onresize =
  316. function()
  317. {
  318. _THIS_page.reflow();
  319. };
  320. _THIS_.setOnloadHandler(
  321. function()
  322. {
  323. if (window._THIS_layoutMenu)
  324. _THIS_layoutMenu.init();
  325. <xsl:choose>
  326. <xsl:when test="$pagelet">
  327. _THIS_page = new CPage("_THIS_", "<xsl:value-of select="xtsext:javascriptencode(/root/env/param[@name = 'id'])"/>", _THIS_.div, [ <xsl:apply-templates select="$pagelet//column[not(row)]" mode="zone"/> ]);
  328. <xsl:if test="$read-only">
  329. _THIS_page.isReadOnly=true;
  330. </xsl:if>
  331. _THIS_page.initZones("_THIS_page", <xsl:apply-templates select="$pagelet/cps:layout/layout" mode="layout"/>);
  332. </xsl:when>
  333. <xsl:otherwise>
  334. _THIS_page = new CPage("_THIS_", null, _THIS_.div);
  335. _THIS_page.setLayout("_THIS_page", _THIS_layouts[<xsl:value-of select="$layout-index"/>]);
  336. if(window._THIS_layoutMenu)
  337. _THIS_layoutMenu.setLayout(<xsl:value-of select="$layout-index"/>);
  338. </xsl:otherwise>
  339. </xsl:choose>
  340. }
  341. );
  342. </script>
  343. <!-- Layout Menu -->
  344. <xsl:variable name="MINISELECT_WIDTH" select="16"/>
  345. <xsl:variable name="MINISELECT_HEIGHT" select="20"/>
  346. <xsl:variable name="MINI_WIDTH" select="20"/>
  347. <xsl:variable name="MINI_HEIGHT" select="24"/>
  348. <xsl:variable name="cols" select="3"/>
  349. <xsl:variable name="rows" select="ceiling(count($layouts) div $cols)"/>
  350. <xsl:if test="not($read-only)">
  351. <table cellspacing="0" cellpadding="0" border="0">
  352. <tr>
  353. <td>
  354. <div style="border: 1px solid silver;" onclick="_THIS_layoutMenu.toggle();">
  355. <table cellspacing="0" cellpadding="0" border="0">
  356. <tr>
  357. <td>
  358. <div id="_THIS_layoutselect">
  359. <xsl:for-each select="$layouts">
  360. <xsl:variable name="display">
  361. <xsl:choose>
  362. <xsl:when test="(position() - 1) = $layout-index">block</xsl:when>
  363. <xsl:otherwise>none</xsl:otherwise>
  364. </xsl:choose>
  365. </xsl:variable>
  366. <div style="width:{ $MINISELECT_WIDTH + 2 }px; height:{ $MINISELECT_HEIGHT + 5 }px; margin:3px; display:{ $display };">
  367. <xsl:apply-templates select="." mode="mini">
  368. <xsl:with-param name="width" select="$MINISELECT_WIDTH"/>
  369. <xsl:with-param name="height" select="$MINISELECT_HEIGHT"/>
  370. </xsl:apply-templates>
  371. </div>
  372. </xsl:for-each>
  373. </div>
  374. </td>
  375. <td width="10px" align="middle" valign="center">
  376. <img src="_THIS?frag-resource=/fragments/common/images/dropdown.gif/THIS_"/>
  377. </td>
  378. </tr>
  379. </table>
  380. </div>
  381. </td>
  382. </tr>
  383. </table>
  384. <div id="_THIS_layoutmenu" style="position: absolute; overflow: hidden; visibility: hidden; z-index:100; width: { ($MINI_WIDTH + 11) * $cols }px; border:1px solid black; background-color: white;">
  385. <table border="0" cellpadding="0" cellspacing="0">
  386. <xsl:for-each select="$layouts[position() mod $cols = 1]">
  387. <xsl:variable name="outer" select="(position() - 1) * $cols"/>
  388. <tr>
  389. <xsl:for-each select=". | following-sibling::layout[position() &lt; $cols]">
  390. <xsl:variable name="index" select="$outer + position() - 1"/>
  391. <td>
  392. <xsl:variable name="style-selected">
  393. <xsl:if test="$index = $layout-index">
  394. <xsl:text> background-color: lightgrey;</xsl:text>
  395. </xsl:if>
  396. </xsl:variable>
  397. <div id="_THIS_layoutitem{ $index }" style="width:{ $MINI_WIDTH }px; margin:5px;{ $style-selected }">
  398. <xsl:apply-templates select="." mode="mini">
  399. <xsl:with-param name="width" select="$MINI_WIDTH"/>
  400. <xsl:with-param name="height" select="$MINI_HEIGHT"/>
  401. </xsl:apply-templates>
  402. </div>
  403. </td>
  404. </xsl:for-each>
  405. </tr>
  406. </xsl:for-each>
  407. </table>
  408. </div>
  409. </xsl:if>
  410. <!-- Layout pieces -->
  411. <div id="_THIS_page"/>
  412. <div id="_THIS_selector" style="visibility:hidden; position:absolute; border: 2px solid black; z-index: 80"/>
  413. <div id="_THIS_shadow" style="visibility:hidden; position:absolute; border: 2px dashed black; z-index: 22"/>
  414. <div id="_THIS_resizeBar" style="position:absolute; visibility: hidden; cursor: w-resize; width: 4px; background-color:#999999; z-index:80"/>
  415. <div id="_THIS_resizeBox" style="position:absolute; visibility: hidden; border: 4px solid #999999; z-index:79"/>
  416. <div id="_THIS_resizeInfo" style="position:absolute; visibility: hidden; width: 60px; height: 20px; border: 1px solid black; background-color:#ffff99; z-index:79">
  417. <table cellspacing="0" cellpadding="2" border="0" width="100%">
  418. <tr>
  419. <td width="50%" align="left" valign="middle"><span id="_THIS_resizeLeft">0%</span></td>
  420. <td width="50%" align="right" valign="middle"><span id="_THIS_resizeRight">0%</span></td>
  421. </tr>
  422. </table>
  423. </div>
  424. <div id="_THIS_blur" style="position:absolute; background-color:#eeeeee; filter:alpha(opacity=50); opacity:0.3; z-index:80;"/>
  425. </markupXml>
  426. </markup>
  427. </fragment>
  428. </xsl:template>
  429. <!--
  430. deserialize pagelet xml into a CPage object
  431. -->
  432. <xsl:template match="cps:pagelet">
  433. <xsl:text>new CPage("_THIS_", _THIS_.div, </xsl:text>
  434. <xsl:apply-templates select="cps:layout" mode="layout"/>
  435. <xsl:text>, [ </xsl:text>
  436. <xsl:apply-templates select="cps:layout//column[not(self::row)]" mode="zone"/>
  437. <xsl:text>], { id: "</xsl:text>
  438. <xsl:value-of select="cps:id"/>
  439. <xsl:text>", name: "</xsl:text>
  440. <xsl:value-of select="cps:name"/>
  441. <xsl:if test="cps:description">
  442. <xsl:text>", description: "</xsl:text>
  443. <xsl:value-of select="cps:description"/>
  444. </xsl:if>
  445. <xsl:if test="cps:screenTip">
  446. <xsl:text>", screenTip: "</xsl:text>
  447. <xsl:value-of select="cps:screenTip"/>
  448. </xsl:if>
  449. <xsl:text>" } ) </xsl:text>
  450. </xsl:template>
  451. <xsl:template match="cps:layout">
  452. <xsl:apply-templates mode="layout"/>
  453. </xsl:template>
  454. <!--
  455. deserialize layout xml into CLayout objects
  456. -->
  457. <xsl:template match="layout" mode="layout">
  458. <xsl:text>new CLayout( [ </xsl:text>
  459. <xsl:choose>
  460. <xsl:when test="row">
  461. <xsl:apply-templates select="row" mode="layout"/>
  462. </xsl:when>
  463. <xsl:otherwise>
  464. <xsl:text>new CRow( [ </xsl:text>
  465. <xsl:apply-templates select="column" mode="layout"/>
  466. <xsl:text>] ) </xsl:text>
  467. </xsl:otherwise>
  468. </xsl:choose>
  469. <xsl:text>], { </xsl:text>
  470. <xsl:apply-templates select="title | instructions | portletOptions" mode="json"/>
  471. <xsl:text>} )</xsl:text>
  472. <xsl:if test="position() != last()">,</xsl:if>
  473. <xsl:text> </xsl:text>
  474. </xsl:template>
  475. <xsl:template match="row" mode="layout">
  476. <xsl:text>new CRow( [ </xsl:text>
  477. <xsl:apply-templates select="column" mode="layout"/>
  478. <xsl:text> ] )</xsl:text>
  479. <xsl:if test="position() != last()">,</xsl:if>
  480. <xsl:text> </xsl:text>
  481. </xsl:template>
  482. <xsl:template match="column" mode="layout">
  483. <xsl:text>new CColumn("</xsl:text>
  484. <xsl:value-of select="@width"/>
  485. <xsl:text>"</xsl:text>
  486. <xsl:if test="row">
  487. <xsl:text>, [ </xsl:text>
  488. <xsl:apply-templates select="row" mode="layout"/>
  489. <xsl:text>] </xsl:text>
  490. </xsl:if>
  491. <xsl:text>) </xsl:text>
  492. <xsl:if test="position() != last()">,</xsl:if>
  493. <xsl:text> </xsl:text>
  494. </xsl:template>
  495. <!--
  496. deserialize column xml into CZone objects
  497. -->
  498. <xsl:template match="column" mode="zone">
  499. <xsl:text>new CZone( [ </xsl:text>
  500. <xsl:apply-templates select="portlet" mode="zone"/>
  501. <xsl:text>] )</xsl:text>
  502. <xsl:if test="position() != last()">,</xsl:if>
  503. <xsl:text> </xsl:text>
  504. </xsl:template>
  505. <xsl:template match="portlet" mode="zone">
  506. <xsl:variable name="layout-id" select="@id"/>
  507. <xsl:variable name="portlet-instance" select="$pagelet/cps:portletInstance[cps:id = $layout-id]"/>
  508. <xsl:text>new CPortlet( { id: "_THIS_portlet_</xsl:text>
  509. <xsl:value-of select="$layout-id"/>
  510. <xsl:text>", layoutId: "</xsl:text>
  511. <xsl:value-of select="$layout-id"/>
  512. <xsl:text>", portletId: "</xsl:text>
  513. <xsl:value-of select="$portlet-instance/cps:portletId"/>
  514. <xsl:text>"</xsl:text>
  515. <xsl:variable name="context" select="$portlet-instance/wsrp:portletContext"/>
  516. <xsl:if test="$context">
  517. <xsl:text>, context: { portletHandle: "</xsl:text>
  518. <xsl:value-of select="$context/wsrp:portletHandle"/>
  519. <xsl:text>", portletState: "</xsl:text>
  520. <xsl:value-of select="$context/wsrp:portletState"/>
  521. <xsl:text>"</xsl:text>
  522. <xsl:variable name="type" select="$context/wsrp:extensions/cpsext:info/cpsext:type"/>
  523. <xsl:if test="$type">
  524. <xsl:text>, portletType: "</xsl:text>
  525. <xsl:value-of select="$type"/>
  526. <xsl:text>"</xsl:text>
  527. </xsl:if>
  528. <xsl:text> } </xsl:text>
  529. </xsl:if>
  530. <xsl:text>} ) </xsl:text>
  531. <xsl:if test="position() != last()">,</xsl:if>
  532. <xsl:text> </xsl:text>
  533. </xsl:template>
  534. <!--
  535. render mini layouts
  536. -->
  537. <xsl:template match="layout" mode="mini">
  538. <xsl:param name="width"/>
  539. <xsl:param name="height"/>
  540. <xsl:choose>
  541. <xsl:when test="row">
  542. <xsl:apply-templates select="row" mode="mini">
  543. <xsl:with-param name="width" select="$width"/>
  544. <xsl:with-param name="height" select="$height"/>
  545. </xsl:apply-templates>
  546. </xsl:when>
  547. <xsl:otherwise>
  548. <xsl:call-template name="row-mini">
  549. <xsl:with-param name="width" select="$width"/>
  550. <xsl:with-param name="height" select="$height"/>
  551. </xsl:call-template>
  552. </xsl:otherwise>
  553. </xsl:choose>
  554. </xsl:template>
  555. <xsl:template match="row" name="row-mini" mode="mini">
  556. <xsl:param name="width"/>
  557. <xsl:param name="height"/>
  558. <xsl:variable name="pixel-height" select="$height div last()"/>
  559. <table cellpadding="0" cellspacing="0" border="1" width="100%">
  560. <tr height="{ $pixel-height - 1 }px">
  561. <xsl:apply-templates select="column" mode="mini">
  562. <xsl:with-param name="width" select="$width"/>
  563. <xsl:with-param name="height" select="$pixel-height"/>
  564. </xsl:apply-templates>
  565. </tr>
  566. </table>
  567. </xsl:template>
  568. <xsl:template match="column" mode="mini">
  569. <xsl:param name="width"/>
  570. <xsl:param name="height"/>
  571. <xsl:variable name="pixel-width" select="($width * @width div 100) - count(ancestor::row)"/>
  572. <td width="{ $pixel-width }px" val="{ count(ancestor::row) }">
  573. <xsl:if test="position() = last()">
  574. <xsl:attribute name="align">right</xsl:attribute>
  575. </xsl:if>
  576. <xsl:choose>
  577. <xsl:when test="row">
  578. <xsl:apply-templates select="row" mode="mini">
  579. <xsl:with-param name="width" select="$pixel-width"/>
  580. <xsl:with-param name="height" select="$height"/>
  581. </xsl:apply-templates>
  582. </xsl:when>
  583. <xsl:otherwise>
  584. <img width="1" height="1" alt="" src="_THIS?frag-resource=/fragments/pagelayout/images/space.gif/THIS_"/>
  585. </xsl:otherwise>
  586. </xsl:choose>
  587. </td>
  588. </xsl:template>
  589. <!--
  590. calc layout ids
  591. -->
  592. <xsl:template match="layout" mode="compare-ids">
  593. <xsl:param name="id"/>
  594. <xsl:variable name="layout-id">
  595. <xsl:apply-templates select="." mode="id"/>
  596. </xsl:variable>
  597. <xsl:if test="$id = $layout-id">
  598. <xsl:value-of select="position() - 1"/>
  599. </xsl:if>
  600. </xsl:template>
  601. <xsl:template match="layout" mode="layout-ids">
  602. <xsl:text>"</xsl:text>
  603. <xsl:apply-templates select="." mode="id"/>
  604. <xsl:text>"</xsl:text>
  605. <xsl:if test="position() != last()">,</xsl:if>
  606. <xsl:text> </xsl:text>
  607. </xsl:template>
  608. <xsl:template match="layout" mode="id">
  609. <xsl:choose>
  610. <xsl:when test="row">
  611. <xsl:apply-templates select="row" mode="id"/>
  612. </xsl:when>
  613. <xsl:otherwise>
  614. <xsl:call-template name="row-id"/>
  615. </xsl:otherwise>
  616. </xsl:choose>
  617. </xsl:template>
  618. <xsl:template match="row" name="row-id" mode="id">
  619. <xsl:param name="level" select="0"/>
  620. <xsl:value-of select="concat('R', $level)"/>
  621. <xsl:apply-templates select="column" mode="id">
  622. <xsl:with-param name="level" select="$level"/>
  623. </xsl:apply-templates>
  624. </xsl:template>
  625. <xsl:template match="column" mode="id">
  626. <xsl:param name="level" select="0"/>
  627. <xsl:value-of select="concat('C', $level)"/>
  628. <xsl:apply-templates select="row" mode="id">
  629. <xsl:with-param name="level" select="$level + 1"/>
  630. </xsl:apply-templates>
  631. </xsl:template>
  632. <!--
  633. json serialization
  634. -->
  635. <xsl:template match="*" mode="json">
  636. <xsl:value-of select="concat(name(), ': { ')"/>
  637. <xsl:apply-templates select="@* | * | text()" mode="json"/>
  638. <xsl:text>}</xsl:text>
  639. <xsl:if test="position() != last()">,</xsl:if>
  640. <xsl:text> </xsl:text>
  641. </xsl:template>
  642. <xsl:template match="text()" mode="json">
  643. <xsl:value-of select="concat('&quot;_text_&quot;: &quot;', xtsext:javascriptencode(.), '&quot;')"/>
  644. <xsl:if test="position() != last()">,</xsl:if>
  645. <xsl:text> </xsl:text>
  646. </xsl:template>
  647. <xsl:template match="@*" mode="json">
  648. <xsl:value-of select="concat('&quot;', name(), '&quot;: &quot;', xtsext:javascriptencode(.), '&quot;')"/>
  649. <xsl:if test="position() != last()">,</xsl:if>
  650. <xsl:text> </xsl:text>
  651. </xsl:template>
  652. </xsl:stylesheet>
  653. </xts:block>
  654. </xts:morphlet>