Guest User

Untitled

a guest
Apr 23rd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.99 KB | None | 0 0
  1.  
  2. /*** The WebGUI Asset Manager
  3. * Requires: YAHOO, Dom, Event
  4. *
  5. */
  6.  
  7. if ( typeof WebGUI == "undefined" ) {
  8. WebGUI = {};
  9. }
  10. if ( typeof WebGUI.AssetManager == "undefined" ) {
  11. WebGUI.AssetManager = {};
  12. }
  13.  
  14. // Keep track of the open more menus
  15. WebGUI.AssetManager.MoreMenusDisplayed = {};
  16. WebGUI.AssetManager.CrumbMoreMenu;
  17. // Append something to a url:
  18. WebGUI.AssetManager.appendToUrl = function ( url, params ) {
  19. var components = [ url ];
  20. if (url.match(/\?/)) {
  21. components.push(";");
  22. }
  23. else {
  24. components.push("?");
  25. }
  26. components.push(params);
  27. return components.join('');
  28. }
  29.  
  30. /*---------------------------------------------------------------------------
  31. WebGUI.AssetManager.addHighlightToRow ( child )
  32. Highlight the row containing this element by adding to it the "highlight"
  33. class
  34. */
  35. WebGUI.AssetManager.addHighlightToRow
  36. = function ( child ) {
  37. var row = WebGUI.AssetManager.findRow( child );
  38. if ( !YAHOO.util.Dom.hasClass( row, "highlight" ) ) {
  39. YAHOO.util.Dom.addClass( row, "highlight" );
  40. }
  41. };
  42.  
  43. /*---------------------------------------------------------------------------
  44. WebGUI.AssetManager.buildMoreMenu ( url, linkElement )
  45. Build a WebGUI style "More" menu for the asset referred to by url
  46. */
  47. WebGUI.AssetManager.buildMoreMenu
  48. = function ( url, linkElement, isNotLocked ) {
  49. // Build a more menu
  50. var rawItems = WebGUI.AssetManager.MoreMenuItems;
  51. var menuItems = [];
  52. var isLocked = !isNotLocked;
  53. for ( var i = 0; i < rawItems.length; i++ ) {
  54. var itemUrl = rawItems[i].url.match( /<url>/ )
  55. ? rawItems[i].url.replace( /<url>(?:\?(.*))?/, WebGUI.AssetManager.appendToUrl(url, "$1") )
  56. : url + rawItems[i].url
  57. ;
  58. if (! (itemUrl.match( /func=edit;/) && isLocked )) {
  59. menuItems.push( { "url" : itemUrl, "text" : rawItems[i].label } );
  60. }
  61. }
  62. var options = {
  63. "zindex" : 1000,
  64. "clicktohide" : true,
  65. "position" : "dynamic",
  66. "context" : [ linkElement, "tl", "bl" ],
  67. "itemdata" : menuItems
  68. };
  69.  
  70. return options;
  71. };
  72.  
  73. /*---------------------------------------------------------------------------
  74. WebGUI.AssetManager.findRow ( child )
  75. Find the row that contains this child element.
  76. */
  77. WebGUI.AssetManager.findRow
  78. = function ( child ) {
  79. var node = child;
  80. while ( node ) {
  81. if ( node.tagName == "TR" ) {
  82. return node;
  83. }
  84. node = node.parentNode;
  85. }
  86. };
  87.  
  88. /*---------------------------------------------------------------------------
  89. WebGUI.AssetManager.formatActions ( )
  90. Format the Edit and More links for the row
  91. */
  92. WebGUI.AssetManager.formatActions = function ( elCell, oRecord, oColumn, orderNumber ) {
  93. if ( oRecord.getData( 'actions' ) ) {
  94. elCell.innerHTML
  95. = '<a href="' + WebGUI.AssetManager.appendToUrl(oRecord.getData( 'url' ), 'func=edit;proceed=manageAssets') + '">'
  96. + WebGUI.AssetManager.i18n.get('Asset', 'edit') + '</a>'
  97. + ' | '
  98. ;
  99. }
  100. else {
  101. elCell.innerHTML = "";
  102. }
  103. var more = document.createElement( 'a' );
  104. elCell.appendChild( more );
  105. more.appendChild( document.createTextNode( WebGUI.AssetManager.i18n.get('Asset','More' ) ) );
  106. more.href = '#';
  107.  
  108. // Delete the old menu
  109. if ( document.getElementById( 'moreMenu' + oRecord.getData( 'assetId' ) ) ) {
  110. var oldMenu = document.getElementById( 'moreMenu' + oRecord.getData( 'assetId' ) );
  111. oldMenu.parentNode.removeChild( oldMenu );
  112. }
  113.  
  114. var options = WebGUI.AssetManager.buildMoreMenu(oRecord.getData( 'url' ), more, oRecord.getData( 'actions' ));
  115.  
  116. var menu = new YAHOO.widget.Menu( "moreMenu" + oRecord.getData( 'assetId' ), options );
  117. YAHOO.util.Event.onDOMReady( function () { menu.render( document.getElementById( 'assetManager' ) ) } );
  118. YAHOO.util.Event.addListener( more, "click", function (e) { YAHOO.util.Event.stopEvent(e); menu.show(); menu.focus(); }, null, menu );
  119. };
  120.  
  121. /*---------------------------------------------------------------------------
  122. WebGUI.AssetManager.formatAssetIdCheckbox ( )
  123. Format the checkbox for the asset ID.
  124. */
  125. WebGUI.AssetManager.formatAssetIdCheckbox = function ( elCell, oRecord, oColumn, orderNumber ) {
  126. elCell.innerHTML = '<input type="checkbox" name="assetId" value="' + oRecord.getData("assetId") + '"'
  127. + 'onchange="WebGUI.AssetManager.toggleHighlightForRow( this )" />';
  128. };
  129.  
  130. /*---------------------------------------------------------------------------
  131. WebGUI.AssetManager.formatAssetSize ( )
  132. Format the asset class name
  133. */
  134. WebGUI.AssetManager.formatAssetSize = function ( elCell, oRecord, oColumn, orderNumber ) {
  135. elCell.innerHTML = oRecord.getData( "assetSize" );
  136. };
  137.  
  138. /*---------------------------------------------------------------------------
  139. WebGUI.AssetManager.formatClassName ( )
  140. Format the asset class name
  141. */
  142. WebGUI.AssetManager.formatClassName = function ( elCell, oRecord, oColumn, orderNumber ) {
  143. elCell.innerHTML = '<img src="' + oRecord.getData( 'icon' ) + '" /> '
  144. + oRecord.getData( "className" );
  145. };
  146.  
  147. /*---------------------------------------------------------------------------
  148. WebGUI.AssetManager.formatLockedBy ( )
  149. Format the asset class name
  150. */
  151. WebGUI.AssetManager.formatLockedBy = function ( elCell, oRecord, oColumn, orderNumber ) {
  152. var extras = getWebguiProperty('extrasURL');
  153. elCell.innerHTML
  154. = oRecord.getData( 'lockedBy' )
  155. ? '<a href="' + WebGUI.AssetManager.appendToUrl(oRecord.getData( 'url' ), 'func=manageRevisions') + '">'
  156. + '<img src="' + extras + '/assetManager/locked.gif" alt="' + WebGUI.AssetManager.i18n.get('WebGUI', 'locked by') + ' ' + oRecord.getData( 'lockedBy' ) + '" '
  157. + 'title="' + WebGUI.AssetManager.i18n.get('WebGUI', 'locked by') + ' ' + oRecord.getData( 'lockedBy' ) + '" border="0" />'
  158. + '</a>'
  159. : '<a href="' + WebGUI.AssetManager.appendToUrl(oRecord.getData( 'url' ), 'func=manageRevisions') + '">'
  160. + '<img src="' + extras + '/assetManager/unlocked.gif" alt="' + WebGUI.AssetManager.i18n.get('Asset', 'unlocked') + '" '
  161. + 'title="' + WebGUI.AssetManager.i18n.get('Asset', 'unlocked') +'" border="0" />'
  162. + '</a>'
  163. ;
  164. };
  165.  
  166. /*---------------------------------------------------------------------------
  167. WebGUI.AssetManager.formatRank ( )
  168. Format the input for the rank box
  169. */
  170. WebGUI.AssetManager.formatRank = function ( elCell, oRecord, oColumn, orderNumber ) {
  171. var rank = oRecord.getData("lineage").match(/[1-9][0-9]{0,5}$/);
  172. elCell.innerHTML = '<input type="text" name="' + oRecord.getData("assetId") + '_rank" '
  173. + 'value="' + rank + '" size="3" '
  174. + 'onchange="WebGUI.AssetManager.selectRow( this )" />';
  175. };
  176.  
  177.  
  178. /*---------------------------------------------------------------------------
  179. WebGUI.AssetManager.DefaultSortedBy ( )
  180. */
  181. WebGUI.AssetManager.DefaultSortedBy = {
  182. "key" : "lineage",
  183. "dir" : YAHOO.widget.DataTable.CLASS_ASC
  184. };
  185.  
  186. /*---------------------------------------------------------------------------
  187. WebGUI.AssetManager.BuildQueryString ( )
  188. */
  189. WebGUI.AssetManager.BuildQueryString = function ( state, dt ) {
  190. var query = "recordOffset=" + state.pagination.recordOffset
  191. + ';orderByDirection=' + ((state.sortedBy.dir === YAHOO.widget.DataTable.CLASS_DESC) ? "DESC" : "ASC")
  192. + ';rowsPerPage=' + state.pagination.rowsPerPage
  193. + ';orderByColumn=' + state.sortedBy.key
  194. ;
  195. return query;
  196. };
  197.  
  198. /*---------------------------------------------------------------------------
  199. WebGUI.AssetManager.formatRevisionDate ( )
  200. Format the asset class name
  201. */
  202. WebGUI.AssetManager.formatRevisionDate = function ( elCell, oRecord, oColumn, orderNumber ) {
  203. var revisionDate = new Date( oRecord.getData( "revisionDate" ) * 1000 );
  204. var minutes = revisionDate.getMinutes();
  205. if (minutes < 10)
  206. minutes = "0" + minutes;
  207. elCell.innerHTML = revisionDate.getFullYear() + '-' + ( revisionDate.getMonth() + 1 )
  208. + '-' + revisionDate.getDate() + ' ' + ( revisionDate.getHours() )
  209. + ':' + minutes
  210. ;
  211. };
  212.  
  213. /*---------------------------------------------------------------------------
  214. WebGUI.AssetManager.formatTitle ( )
  215. Format the link for the title
  216. */
  217. WebGUI.AssetManager.formatTitle = function ( elCell, oRecord, oColumn, orderNumber ) {
  218. elCell.innerHTML = '<span class="hasChildren">'
  219. + ( oRecord.getData( 'childCount' ) > 0 ? "+" : "&nbsp;" )
  220. + '</span> <a href="' + WebGUI.AssetManager.appendToUrl(oRecord.getData( 'url' ), 'op=assetManager;method=manage') + '">'
  221. + oRecord.getData( 'title' )
  222. + '</a>'
  223. ;
  224. };
  225.  
  226. /*---------------------------------------------------------------------------
  227. WebGUI.AssetManager.initManager ( )
  228. Initialize the i18n interface
  229. */
  230. WebGUI.AssetManager.initManager = function (o) {
  231. WebGUI.AssetManager.i18n
  232. = new WebGUI.i18n( {
  233. namespaces : {
  234. 'Asset' : [
  235. "edit",
  236. "More",
  237. "unlocked",
  238. "locked by"
  239. ],
  240. 'WebGUI' : [
  241. "< prev",
  242. "next >"
  243. ]
  244. },
  245. onpreload : {
  246. fn : WebGUI.AssetManager.initDataTable
  247. }
  248. } );
  249. };
  250.  
  251. /*---------------------------------------------------------------------------
  252. WebGUI.AssetManager.initDataTable ( )
  253. Initialize the www_manage page
  254. */
  255. WebGUI.AssetManager.initDataTable = function (o) {
  256. var assetPaginator = new YAHOO.widget.Paginator({
  257. containers : ['pagination'],
  258. pageLinks : 7,
  259. rowsPerPage : 100,
  260. previousPageLinkLabel : WebGUI.AssetManager.i18n.get('WebGUI', '< prev'),
  261. nextPageLinkLabel : WebGUI.AssetManager.i18n.get('WebGUI', 'next >'),
  262. template : "<strong>{CurrentPageReport}</strong> {PreviousPageLink} {PageLinks} {NextPageLink}"
  263. });
  264.  
  265.  
  266. // initialize the data source
  267. WebGUI.AssetManager.DataSource
  268. = new YAHOO.util.DataSource( '?op=assetManager;method=ajaxGetManagerPage;',{connTimeout:30000} );
  269. WebGUI.AssetManager.DataSource.responseType
  270. = YAHOO.util.DataSource.TYPE_JSON;
  271. WebGUI.AssetManager.DataSource.responseSchema
  272. = {
  273. resultsList: 'assets',
  274. fields: [
  275. { key: 'assetId' },
  276. { key: 'lineage' },
  277. { key: 'actions' },
  278. { key: 'title' },
  279. { key: 'className' },
  280. { key: 'revisionDate' },
  281. { key: 'assetSize' },
  282. { key: 'lockedBy' },
  283. { key: 'icon' },
  284. { key: 'url' },
  285. { key: 'childCount' }
  286. ],
  287. metaFields: {
  288. totalRecords: "totalAssets" // Access to value in the server response
  289. }
  290. };
  291.  
  292.  
  293.  
  294. // Initialize the data table
  295. WebGUI.AssetManager.DataTable
  296. = new YAHOO.widget.DataTable( 'dataTableContainer',
  297. WebGUI.AssetManager.ColumnDefs,
  298. WebGUI.AssetManager.DataSource,
  299. {
  300. initialRequest : 'recordOffset=0',
  301. dynamicData : true,
  302. paginator : assetPaginator,
  303. sortedBy : WebGUI.AssetManager.DefaultSortedBy,
  304. generateRequest : WebGUI.AssetManager.BuildQueryString
  305. }
  306. );
  307.  
  308. WebGUI.AssetManager.DataTable.handleDataReturnPayload = function(oRequest, oResponse, oPayload) {
  309. oPayload.totalRecords = oResponse.meta.totalRecords;
  310. return oPayload;
  311. }
  312.  
  313. };
  314.  
  315. /*---------------------------------------------------------------------------
  316. WebGUI.AssetManager.removeHighlightFromRow ( child )
  317. Remove the highlight from a row by removing the "highlight" class.
  318. */
  319. WebGUI.AssetManager.removeHighlightFromRow = function ( child ) {
  320. var row = WebGUI.AssetManager.findRow( child );
  321. if ( YAHOO.util.Dom.hasClass( row, "highlight" ) ) {
  322. YAHOO.util.Dom.removeClass( row, "highlight" );
  323. }
  324. };
  325.  
  326. /*---------------------------------------------------------------------------
  327. WebGUI.AssetManager.selectRow ( child )
  328. Check the assetId checkbox in the row that contains the given child.
  329. Used when something in the row changes.
  330. */
  331. WebGUI.AssetManager.selectRow = function ( child ) {
  332. // First find the row
  333. var node = WebGUI.AssetManager.findRow( child );
  334. WebGUI.AssetManager.addHighlightToRow( child );
  335.  
  336. // Now find the assetId checkbox in the first element
  337. var inputs = node.getElementsByTagName( "input" );
  338. for ( var i = 0; i < inputs.length; i++ ) {
  339. if ( inputs[i].name == "assetId" ) {
  340. inputs[i].checked = true;
  341. break;
  342. }
  343. }
  344. };
  345.  
  346. /*---------------------------------------------------------------------------
  347. WebGUI.AssetManager.showMoreMenu ( url, linkTextId )
  348. Build a More menu for the last element of the Crumb trail
  349. */
  350. WebGUI.AssetManager.showMoreMenu
  351. = function ( url, linkTextId, isNotLocked ) {
  352.  
  353. var menu;
  354. if ( typeof WebGUI.AssetManager.CrumbMoreMenu == "undefined" ) {
  355. var more = document.getElementById(linkTextId);
  356. var options = WebGUI.AssetManager.buildMoreMenu(url, more, isNotLocked);
  357. menu = new YAHOO.widget.Menu( "crumbMoreMenu", options );
  358. menu.render( document.getElementById( 'assetManager' ) );
  359. WebGUI.AssetManager.CrumbMoreMenu = menu;
  360. }
  361. else {
  362. menu = WebGUI.AssetManager.CrumbMoreMenu;
  363. }
  364. menu.show();
  365. menu.focus();
  366. };
  367.  
  368. /*---------------------------------------------------------------------------
  369. WebGUI.AssetManager.toggleHighlightForRow ( checkbox )
  370. Toggle the highlight for the row based on the state of the checkbox
  371. */
  372. WebGUI.AssetManager.toggleHighlightForRow = function ( checkbox ) {
  373. if ( checkbox.checked ) {
  374. WebGUI.AssetManager.addHighlightToRow( checkbox );
  375. }
  376. else {
  377. WebGUI.AssetManager.removeHighlightFromRow( checkbox );
  378. }
  379. };
  380.  
  381. /*---------------------------------------------------------------------------
  382. WebGUI.AssetManager.toggleRow ( child )
  383. Toggles the entire row by finding the checkbox and doing what needs to be
  384. done.
  385. */
  386. WebGUI.AssetManager.toggleRow = function ( child ) {
  387. var row = WebGUI.AssetManager.findRow( child );
  388.  
  389. // Find the checkbox
  390. var inputs = row.getElementsByTagName( "input" );
  391. for ( var i = 0; i < inputs.length; i++ ) {
  392. if ( inputs[i].name == "assetId" ) {
  393. inputs[i].checked = inputs[i].checked
  394. ? false
  395. : true
  396. ;
  397. WebGUI.AssetManager.toggleHighlightForRow( inputs[i] );
  398. break;
  399. }
  400. }
  401. };
Add Comment
Please, Sign In to add comment