collaboration.js 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687
  1. // Licensed Materials - Property of IBM
  2. //
  3. // IBM Cognos Products: cpscrn
  4. //
  5. // (C) Copyright IBM Corp. 2005, 2011
  6. //
  7. // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8. //
  9. //
  10. (function () {
  11. // Define the sharepoint namespace
  12. if (!com_ibm_cognos_cps.sp) {
  13. com_ibm_cognos_cps.sp = {};
  14. }
  15. // Make sure we only define the CPSCollaboration object once
  16. if (com_ibm_cognos_cps.sp.CPSCollaboration) {
  17. return;
  18. }
  19. com_ibm_cognos_cps.sp.executeWhenLoaded = function (f) {
  20. if (ExecuteOrDelayUntilScriptLoaded) {
  21. ExecuteOrDelayUntilScriptLoaded(f, 'sp.js');
  22. }
  23. }
  24. // Metadata
  25. var REPORT_TYPE_FORMATS = [
  26. {
  27. name: 'Excel 2002',
  28. value: 'XLWA',
  29. icon: 'ps/portal/images/icon_result_excel_web_arch.gif'
  30. },
  31. {
  32. name: 'Excel 2007',
  33. value: 'spreadsheetML',
  34. icon: 'ps/portal/images/icon_result_excel_2007.gif'
  35. },
  36. {
  37. name: 'PDF',
  38. value: 'PDF',
  39. icon: 'ps/portal/images/icon_result_pdf.gif'
  40. }
  41. ];
  42. var PUBLISH_OBJECT_TYPES = {
  43. 'dashboard': {
  44. },
  45. 'reportView': {
  46. runFormats: REPORT_TYPE_FORMATS
  47. },
  48. 'report': {
  49. runFormats: REPORT_TYPE_FORMATS
  50. },
  51. 'query': {
  52. runFormats: REPORT_TYPE_FORMATS
  53. },
  54. 'analysis': {
  55. runFormats: REPORT_TYPE_FORMATS
  56. }
  57. }
  58. var ConfirmationDialog = function (options) {
  59. this.message = options.message;
  60. this.hint = options.hint;
  61. this.title = options.title;
  62. this.buttons = options.buttons;
  63. }
  64. ConfirmationDialog.prototype = {
  65. getNode: function () {
  66. if (!this.node) {
  67. this.node = document.createElement('div');
  68. var html = '<form style="padding:5px">' +
  69. '<h3 class="ms-standardheader" style="padding:10px">' + this.message + '</h3>' +
  70. '<div class="ms-descriptiontext" style="padding:10px">' + this.hint + '</div>' +
  71. ' <table class="ms-formtoolbar" border="0" cellSpacing="0" cellPadding="2" width="100%">' +
  72. ' <tr>';
  73. for (var i = 0, l = this.buttons.length; i < l; i++) {
  74. html += '<td class="ms-toolbar" width="99%" nowrap="noWrap">&nbsp;</td>' +
  75. '<td class="ms-toolbar" nowrap="nowrap" align="right">' +
  76. ' <input name="' + this.buttons[i].name + '" accessKey="' + this.buttons[i].accessKey + 'O" class="ms-ButtonHeightWidth" value="' + this.buttons[i].name + '" type="button"> ' +
  77. '</td>';
  78. }
  79. html += ' </tr> ' +
  80. ' </table>' +
  81. '</form>';
  82. this.node.innerHTML = html;
  83. // attach behavior
  84. var _self = this;
  85. this.form = this.node.getElementsByTagName('form')[0];
  86. for (var i = 0, l = this.buttons.length; i < l; i++) {
  87. if (this.form[this.buttons[i].name]) {
  88. this.attachButtonOnClick(this.form[this.buttons[i].name], this.buttons[i].callback);
  89. }
  90. }
  91. }
  92. return this.node;
  93. },
  94. attachButtonOnClick: function (button, callback) {
  95. button.onclick = function () {
  96. SP.UI.ModalDialog.commonModalDialogClose();
  97. if (callback) {
  98. callback();
  99. }
  100. };
  101. },
  102. show: function () {
  103. var self = this;
  104. var node = this.getNode();
  105. var options = {
  106. html: node,
  107. title: this.title,
  108. allowMaximize: false,
  109. showClose: true
  110. };
  111. SP.UI.ModalDialog.showModalDialog(options);
  112. if (this.form[this.buttons[0].name]) {
  113. this.form[this.buttons[0].name].focus();
  114. }
  115. }
  116. }
  117. com_ibm_cognos_cps.sp.ObjectTree = function (options) {
  118. this.listType = options.listType;
  119. this.selectionSpec = options.selectionSpec;
  120. this.isShowRootWeb = options.isShowRootWeb;
  121. this.autoErrorRecovery = options.autoErrorRecovery
  122. this.isHideListFolders = options.isHideListFolders;
  123. this.allowNoWriteItems = options.allowNoWriteItems;
  124. this.selectedNode = null;
  125. this.initialized = false;
  126. }
  127. com_ibm_cognos_cps.sp.ObjectTree.prototype = {
  128. initialize: function (callback) {
  129. if (!this.initialized) {
  130. var node = this._createEmptyNode();
  131. this.context = new SP.ClientContext();
  132. // If we have a selection spec, create the nodes based on the information we have
  133. if (this.selectionSpec) {
  134. var nodes = this.selectionSpec.split(',');
  135. for (var i = 0, l = nodes.length; i < l; i++) {
  136. if (i > 0) {
  137. var parent = node;
  138. node = this._createEmptyNode();
  139. node.parent = parent;
  140. }
  141. var values = nodes[i].split('|');
  142. node.type = values[0];
  143. node.title = values[1];
  144. node.url = values[2];
  145. node.webUrl = values[3];
  146. node.listId = values[4];
  147. if (node.type === 'web') {
  148. node.object = this.context.get_site().openWeb(node.url);
  149. } else if (node.type === 'folder') {
  150. var web = this.context.get_site().openWeb(node.webUrl);
  151. node.object = web.getFolderByServerRelativeUrl(node.url);
  152. } else if (node.type === 'list') {
  153. var w = this.context.get_site().openWeb(node.webUrl);
  154. node.object = w.get_lists().getById(node.listId);
  155. }
  156. }
  157. if (!this.isShowRootWeb) {
  158. node.parent = null;
  159. }
  160. } else {
  161. node.type = 'web';
  162. node.object = this.isShowRootWeb ? this.context.get_site().get_rootWeb() : this.context.get_web();
  163. if (this.isShowRootWeb) {
  164. node.isRootWeb = true;
  165. }
  166. }
  167. this.setNode(node, false, callback);
  168. this.initialized = true;
  169. }
  170. else {
  171. callback();
  172. }
  173. },
  174. _createEmptyNode: function () {
  175. return {
  176. loaded: false,
  177. title: null,
  178. type: null,
  179. image: null,
  180. url: null,
  181. object: null,
  182. parent: null,
  183. nodes: null
  184. };
  185. },
  186. getNode: function () {
  187. if (!this.initialized) {
  188. return null;
  189. }
  190. return this.selectedNode;
  191. },
  192. setNode: function (node, fetchChildren, callback) {
  193. this.selectedNode = node;
  194. if (node.nodes !== null) {
  195. callback();
  196. return;
  197. }
  198. if (node.type == 'web') {
  199. this.getWebChildrenCallback(node, fetchChildren, callback);
  200. } else if (node.type == 'list') {
  201. this.getListChildrenCallback(node, fetchChildren, callback);
  202. } else if (node.type == 'folder') {
  203. this.getFolderChildrenCallback(node, fetchChildren, callback);
  204. }
  205. },
  206. getWebChildrenCallback: function (container, fetchChildren, callback) {
  207. // used in retries ..
  208. var originalArguments = { 'callback': callback, 'fetchChildren': fetchChildren };
  209. var obj = container.object;
  210. if (!container.loaded) {
  211. this.context.load(obj);
  212. }
  213. var listCollection = null;
  214. if (fetchChildren) {
  215. listCollection = obj.get_lists();
  216. this.context.load(listCollection);
  217. }
  218. var getListSuccess = Function.createDelegate(this, function () {
  219. if (!container.loaded) {
  220. container.loaded = true;
  221. container.title = obj.get_title();
  222. container.url = obj.get_serverRelativeUrl();
  223. container.image = '/_layouts/images/SharePointFoundation16.png';
  224. }
  225. if (fetchChildren) {
  226. container.nodes = [];
  227. // get lists permissions
  228. var webLists = [];
  229. var webListsRootFolders = [];
  230. for (var i = 0, l = listCollection.get_count(); i < l; i++) {
  231. var list = listCollection.get_item(i);
  232. this.context.load(list, 'Title', 'ImageUrl', 'EffectiveBasePermissions');
  233. webLists.push(list);
  234. // root folder is needed to get the list url
  235. var folder = list.get_rootFolder();
  236. this.context.load(folder);
  237. webListsRootFolders.push(folder);
  238. }
  239. var getListDetailSuccess = function () {
  240. for (var i = 0, l = webLists.length; i < l; i++) {
  241. var list = webLists[i];
  242. var rootFolder = webListsRootFolders[i];
  243. if (!list.get_hidden() && list.get_baseTemplate() === this.listType && (this.allowNoWriteItems || list.get_effectiveBasePermissions().has(SP.PermissionKind.addListItems))) {
  244. var node = {
  245. loaded: true,
  246. title: list.get_title(),
  247. parent: container,
  248. nodes: null,
  249. type: 'list',
  250. object: list,
  251. image: list.get_imageUrl(),
  252. url: rootFolder.get_serverRelativeUrl()
  253. };
  254. container.nodes.push(node);
  255. }
  256. }
  257. // Now get subwebs
  258. var webs = obj.getSubwebsForCurrentUser();
  259. this.context.load(webs);
  260. var getSubwebSuccess = Function.createDelegate(this, function () {
  261. // add sub webs
  262. var webNodes = [];
  263. for (var i = 0, l = webs.get_count(); i < l; i++) {
  264. var web = webs.get_item(i);
  265. var node = {
  266. loaded: true,
  267. title: web.get_title(),
  268. parent: container,
  269. nodes: null,
  270. type: 'web',
  271. object: web,
  272. image: '/_layouts/images/SharePointFoundation16.png',
  273. url: web.get_serverRelativeUrl()
  274. };
  275. webNodes.push(node);
  276. }
  277. container.nodes = webNodes.concat(container.nodes);
  278. callback();
  279. });
  280. this.executeQuery(getSubwebSuccess, originalArguments, function () {
  281. // No access for subwebs .. simply ignore
  282. callback();
  283. return true;
  284. });
  285. }
  286. this.executeQuery(getListDetailSuccess, originalArguments);
  287. } else {
  288. callback();
  289. }
  290. });
  291. this.executeQuery(getListSuccess, originalArguments);
  292. },
  293. getListChildrenCallback: function (container, fetchChildren, callback) {
  294. // used in retries ..
  295. var originalArguments = { 'callback': callback, 'fetchChildren': fetchChildren };
  296. var obj = container.object;
  297. var rootFolder;
  298. if (!container.loaded) {
  299. this.context.load(obj, 'Title', 'ImageUrl', 'EffectiveBasePermissions');
  300. rootFolder = obj.get_rootFolder();
  301. this.context.load(rootFolder);
  302. }
  303. if (!this.isHideListFolders && fetchChildren) {
  304. var items = obj.getItems([]);
  305. var folders = obj.get_rootFolder().get_folders();
  306. this.context.load(items);
  307. this.context.load(folders);
  308. }
  309. var onSuccess = Function.createDelegate(this, function () {
  310. if (!container.loaded) {
  311. container.loaded = true;
  312. container.title = obj.get_title();
  313. container.image = obj.get_imageUrl();
  314. container.url = rootFolder.get_serverRelativeUrl();
  315. }
  316. if (fetchChildren) {
  317. container.nodes = [];
  318. if (!this.isHideListFolders) {
  319. for (var i = 0, l = items.get_count(); i < l; i++) {
  320. var item = items.get_item(i);
  321. if (item.get_fileSystemObjectType() === 1) {
  322. // lookup the folder
  323. var folder = null;
  324. var name = item.get_item('Title');
  325. for (var j = 0, jlen = folders.get_count(); j < jlen; j++) {
  326. if (folders.itemAt(j).get_name() == name) {
  327. folder = folders.itemAt(j);
  328. break;
  329. }
  330. }
  331. if (folder) {
  332. var node = {
  333. loaded: true,
  334. title: name,
  335. parent: container,
  336. nodes: null,
  337. type: 'folder',
  338. object: folder,
  339. item: item,
  340. image: '/_layouts/images/folder.gif',
  341. url: folder.get_serverRelativeUrl()
  342. };
  343. container.nodes.push(node);
  344. }
  345. }
  346. }
  347. }
  348. }
  349. callback();
  350. });
  351. this.executeQuery(onSuccess, originalArguments);
  352. },
  353. getFolderChildrenCallback: function (container, fetchChildren, callback) {
  354. // used in retries ..
  355. var originalArguments = { 'callback': callback, 'fetchChildren': fetchChildren };
  356. var obj = container.object;
  357. if (!container.loaded) {
  358. this.context.load(obj);
  359. }
  360. if (fetchChildren) {
  361. var folders = obj.get_folders();
  362. this.context.load(folders);
  363. }
  364. var onSuccess = Function.createDelegate(this, function () {
  365. if (!container.loaded) {
  366. container.loaded = true;
  367. container.title = obj.get_name();
  368. container.url = obj.get_serverRelativeUrl();
  369. container.image = '/_layouts/images/folder.gif';
  370. }
  371. if (fetchChildren) {
  372. container.nodes = [];
  373. for (var i = 0, l = folders.get_count(); i < l; i++) {
  374. var f = folders.itemAt(i);
  375. var node = {
  376. loaded: true,
  377. title: f.get_name(),
  378. parent: container,
  379. nodes: null,
  380. type: 'folder',
  381. object: f,
  382. image: '/_layouts/images/folder.gif',
  383. url: f.get_serverRelativeUrl()
  384. };
  385. container.nodes.push(node);
  386. }
  387. }
  388. callback();
  389. });
  390. this.executeQuery(onSuccess, originalArguments);
  391. },
  392. executeQuery: function (successCallback, originalArguments, errorHandler) {
  393. this.context.executeQueryAsync(
  394. Function.createDelegate(this, successCallback),
  395. Function.createDelegate(this, function (request, error) {
  396. this.onFail(request, error, originalArguments, errorHandler);
  397. }));
  398. },
  399. getSelectionData: function (node) {
  400. var data = {};
  401. var selectionSpec = '';
  402. var n = node;
  403. var fullName = '';
  404. while (n) {
  405. fullName = n.title + (fullName !== '' ? ' > ' : '') + fullName;
  406. var s = n.type + '|' + n.title + '|' + n.url + '|' + this.getWebUrl(n) + '|' + this.getListId(n);
  407. selectionSpec = s + (selectionSpec !== '' ? ',' : '') + selectionSpec;
  408. n = n.parent;
  409. }
  410. data.fullName = fullName;
  411. data.selectionSpec = selectionSpec;
  412. data.type = node.type;
  413. data.title = node.title;
  414. data.image = node.image;
  415. data.url = node.url;
  416. data.webUrl = this.getWebUrl(node);
  417. data.listId = this.getListId(node);
  418. return data;
  419. },
  420. getListId: function (container) {
  421. var n = container;
  422. while (n) {
  423. if (n.listId) {
  424. return n.listId;
  425. } else if (n.type === 'list') {
  426. return n.object.get_id().toString();
  427. }
  428. n = n.parent;
  429. }
  430. return '';
  431. },
  432. getWebUrl: function (container) {
  433. var n = container;
  434. while (n) {
  435. if (n.webUrl) {
  436. return n.webUrl;
  437. } else if (n.type === 'web') {
  438. return n.object.get_serverRelativeUrl();
  439. }
  440. n = n.parent;
  441. }
  442. return '';
  443. },
  444. canWriteToNode: function (node) {
  445. return ((node.type === 'list' && node.object.get_effectiveBasePermissions().has(SP.PermissionKind.addListItems)) || node.type === 'folder')
  446. },
  447. onFail: function (request, error, originalArguments, errorHandler) {
  448. if (errorHandler) {
  449. // caller special handler.
  450. if (errorHandler()) {
  451. return;
  452. }
  453. }
  454. var originalCallback = (originalArguments && originalArguments.callback) ? originalArguments.callback : null;
  455. if (this.autoErrorRecovery && originalCallback) {
  456. // try to recover
  457. if (error.get_errorTypeName() === 'System.UnauthorizedAccessException') {
  458. if (this.selectionSpec) {
  459. this.ignoredUserSelection = this.selectedNode;
  460. // retry with root web
  461. this.selectionSpec = null;
  462. var node = this._createEmptyNode();
  463. node.object = this.context.get_site().get_rootWeb();
  464. node.type = 'web';
  465. node.isRootWeb = true;
  466. this.setNode(node, originalArguments.fetchChildren, originalCallback)
  467. return;
  468. }
  469. if (this.selectedNode.isRootWeb) {
  470. // retry with current web
  471. var node = this._createEmptyNode();
  472. node.object = this.context.get_web();
  473. node.type = 'web';
  474. this.setNode(node, originalArguments.fetchChildren, originalCallback)
  475. return;
  476. }
  477. }
  478. }
  479. this.error = error;
  480. if (error.get_errorTypeName() !== 'System.UnauthorizedAccessException') {
  481. var status = SP.UI.Status.addStatus(error.get_errorTypeName(), '', false);
  482. SP.UI.Status.setStatusPriColor(status, 'red');
  483. SP.UI.Status.updateStatus(status, error.get_message());
  484. }
  485. if (originalCallback) {
  486. // it's up to the called to check error state.
  487. originalCallback();
  488. }
  489. }
  490. }
  491. com_ibm_cognos_cps.sp.SelectDialog = function (options) {
  492. this.options = options;
  493. this.messages = this.options.messages;
  494. this.height = this.options.height ? this.options.height : 500;
  495. this.width = this.options.width ? this.options.width : 500;
  496. this.objectTree = options.objectTree;
  497. this.title = this.options.title;
  498. this.okCallback = this.options.okCallback;
  499. this.selection = null;
  500. this.canSelectReadOnly = this.options.canSelectReadOnly;
  501. }
  502. com_ibm_cognos_cps.sp.SelectDialog.prototype = {
  503. getString: function (id, args) {
  504. if (this.messages && this.messages[id]) {
  505. var msg = this.messages[id];
  506. if (args) {
  507. for (var i = 0, l = args.length; i < l; i++) {
  508. msg = msg.replace('$' + (i + 1), args[i]);
  509. }
  510. }
  511. return msg;
  512. }
  513. return id + ' [' + (args ? args.toString() : '') + ']';
  514. },
  515. addClass: function (element, className) {
  516. if (!element.className) {
  517. element.className = className;
  518. } else {
  519. element.className = element.className + ' ' + className;
  520. }
  521. return element;
  522. },
  523. removeClass: function (element, className) {
  524. if (element.className) {
  525. element.className = element.className.replace(className, '').trim();
  526. }
  527. return element;
  528. },
  529. createDomNode: function () {
  530. if (!this.domNode) {
  531. this.domNode = document.createElement('div');
  532. this.domNode.style.height = this.height + 'px';
  533. this.domNode.style.width = this.width + 'px';
  534. // header
  535. var div = document.createElement('div');
  536. div.className = 's4-title';
  537. this.domNode.appendChild(div);
  538. var table = document.createElement('table');
  539. table.className = 's4-titletable';
  540. div.appendChild(table);
  541. var tr = document.createElement('tr');
  542. table.appendChild(tr);
  543. this.header = document.createElement('td');
  544. tr.appendChild(this.header);
  545. this.header.className = 's4-titletext';
  546. var divider = document.createElement('div');
  547. divider.className = 'ms-partline';
  548. div.appendChild(divider);
  549. //content
  550. this.content = document.createElement('div');
  551. this.content.style.paddingLeft = '5px';
  552. this.content.style.overflow = 'auto';
  553. this.content.appendChild(this.createTable());
  554. this.domNode.appendChild(this.content);
  555. //footer
  556. this.footer = document.createElement('div');
  557. this.footer.innerHTML = '<form style="padding:5px">' +
  558. ' <table style="display:none;" border="0" cellSpacing="0" cellPadding="2" width="100%">' +
  559. ' <tr><td height="1" colspan="2" class="ms-partline"><img height="1" width="1" alt="" src="/_layouts/images/blank.gif"></td></tr>' +
  560. ' <tr>' +
  561. ' <td class="ms-toolbar" nowrap="noWrap" style="padding:5px">' + this.getString('IDS_SP_DOCUMENT_NAME_LABEL') + '</td>' +
  562. ' <td class="ms-toolbar" nowrap="nowrap" width="99%" align="right" style="padding:5px">' +
  563. ' <input name="fileName" title="' + this.getString('IDS_SP_DOCUMENT_NAME_TOOLTIP') + '" type="text" style="width:100%">' +
  564. ' </td>' +
  565. ' </tr> ' +
  566. ' </table>' +
  567. ' <table class="ms-formtoolbar" border="0" cellSpacing="0" cellPadding="2" width="100%">' +
  568. ' <tr><td height="2" colspan="4" class="ms-partline"><img height="1" width="1" alt="" src="/_layouts/images/blank.gif"></td></tr>' +
  569. ' <tr><td colspan="4" class="ms-spaceBetContentAndButton"><img height="1" width="1" alt="" src="/_layouts/images/blank.gif"></td></tr>' +
  570. ' <tr>' +
  571. ' <td class="ms-toolbar" width="99%" nowrap="noWrap">&nbsp;</td>' +
  572. ' <td class="ms-toolbar" nowrap="nowrap" align="right">' +
  573. ' <input name="ok" accessKey="O" class="ms-ButtonHeightWidth" value="' + this.getString('IDS_SP_OK') + '" type="button"> ' +
  574. ' </td>' +
  575. ' <td class=ms-separator>&nbsp;</td>' +
  576. ' <td class="ms-toolbar" nowrap="nowrap" align="right">' +
  577. ' <input name="cancel" accessKey="c" class="ms-ButtonHeightWidth" value="' + this.getString('IDS_SP_CANCEL') + '" type="button"> ' +
  578. ' </td>' +
  579. ' </tr> ' +
  580. ' </table>' +
  581. '</form>';
  582. this.domNode.appendChild(this.footer);
  583. this.form = this.domNode.getElementsByTagName('form')[0];
  584. this.fileNameTable = this.form.elements[0];
  585. this.fileNameTable.width = '100%';
  586. // Attach behavior
  587. var _self = this;
  588. this.form['ok'].onclick = function () {
  589. _self.updateSelectionInfo();
  590. SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.OK, _self.selection);
  591. }
  592. this.form['cancel'].onclick = function () {
  593. SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.cancel);
  594. }
  595. this.form['fileName'].onchange = Function.createDelegate(this, function () {
  596. this.setValidSelection(this.fileNameTable.style.display === 'none' || this.form['fileName'].value !== '');
  597. });
  598. }
  599. return this.domNode;
  600. },
  601. createTable: function () {
  602. if (!this.table) {
  603. var table, tbody, tr, th;
  604. table = document.createElement('table');
  605. table.className = 'ms-listviewtable';
  606. table.style.borderSpacing = '0px';
  607. table.border = '0';
  608. table.width = '100%';
  609. tbody = document.createElement('tbody');
  610. table.appendChild(tbody);
  611. this.tbody = tbody;
  612. this.table = table;
  613. }
  614. return this.table;
  615. },
  616. createRow: function (container, index) {
  617. var title = container.title;
  618. var table = this.tbody;
  619. var tr, td, a, div;
  620. tr = document.createElement('tr');
  621. tr.onclick = Function.createDelegate(this, function () { this.selectRow(tr, container) });
  622. tr.className = 'ms-itmhover';
  623. if (index % 2 == 1) {
  624. this.addClass(tr, 'ms-alternating');
  625. }
  626. table.appendChild(tr);
  627. td = document.createElement('td');
  628. td.className = 'ms-vb-icon ms-vb-firstCell';
  629. tr.appendChild(td);
  630. var type = this.getObjectTypeLabel(container);
  631. td.innerHTML = '<img border="0" src="' + container.image + '" title="' + type + '" alt="' + title + '">';
  632. td = document.createElement('td');
  633. td.height = '100%';
  634. td.width = '99%';
  635. td.className = 'ms-vb-title ms-vb-lastCell';
  636. tr.appendChild(td);
  637. div = document.createElement('div');
  638. div.className = 'ms-vb itx';
  639. td.appendChild(div);
  640. a = document.createElement('a');
  641. a.onclick = Function.createDelegate(this, function () { this.drill(container) });
  642. a.href = 'javascript:';
  643. a.title = a.alt = title;
  644. a.innerHTML = title;
  645. div.appendChild(a);
  646. },
  647. setNameInput: function (filename) {
  648. this.fileNameTable.style.display = '';
  649. this.form['fileName'].value = filename;
  650. },
  651. setValidSelection: function (isValid) {
  652. if (isValid) {
  653. this.form['ok'].disabled = false;
  654. } else {
  655. this.form['ok'].disabled = true;
  656. }
  657. },
  658. setSelection: function (node) {
  659. this.selection = this.objectTree.getSelectionData(node);
  660. this.selection.typeLabel = this.getObjectTypeLabel(this.selection);
  661. this.setValidSelection(this.canSelectReadOnly || this.objectTree.canWriteToNode(node));
  662. },
  663. updateSelectionInfo: function () {
  664. this.selection.fileName = this.form['fileName'].value;
  665. },
  666. selectRow: function (row, folder) {
  667. if (this.selectedRow) {
  668. this.removeClass(this.selectedRow, 's4-itm-selected');
  669. }
  670. this.selectedRow = row;
  671. this.addClass(row, 's4-itm-selected');
  672. this.setSelection(folder);
  673. },
  674. drill: function (node) {
  675. this.updateContent(node);
  676. },
  677. updateBreadCrumbs: function (container) {
  678. this.header.innerHTML = '';
  679. var node = container;
  680. while (node != null) {
  681. var nodeText = document.createElement('h2');
  682. var a = document.createElement('a');
  683. a.onclick = this.createBreadCrumbOnclick(node);
  684. a.href = 'javascript:';
  685. a.title = a.alt = container.title;
  686. a.innerHTML = node.title;
  687. nodeText.appendChild(a);
  688. this.header.insertBefore(nodeText, this.header.firstChild);
  689. node = node.parent;
  690. if (node != null) {
  691. var sep = document.createElement('span');
  692. sep.style.padding = '3px';
  693. sep.innerHTML = '<span style="height: 11px; width: 11px; position: relative; display: inline-block; overflow: hidden;"><img style="border-width: 0px; position: absolute; left: 0px ! important; top: -585px ! important;" alt=":" src="/_layouts/images/fgimg.png"></span>';
  694. this.header.insertBefore(sep, this.header.firstChild);
  695. }
  696. }
  697. // add the image
  698. var img = document.createElement('img');
  699. img.src = container.image;
  700. img.title = img.alt = this.getObjectTypeLabel(container)
  701. img.style.marginRight = '5px';
  702. img.style.paddingBottom = '3px';
  703. img.style.verticalAlign = 'middle';
  704. this.header.insertBefore(img, this.header.firstChild);
  705. },
  706. createBreadCrumbOnclick: function (node) {
  707. return Function.createDelegate(this, function () { this.drill(node) });
  708. },
  709. updateContent: function (container, callback) {
  710. this.objectTree.setNode(container, true, Function.createDelegate(this, function () {
  711. var selected = this.objectTree.getNode();
  712. this.setSelection(selected);
  713. var nodes = selected.nodes;
  714. var rows = this.tbody.childNodes;
  715. for (var i = rows.length - 1; i >= 0; i--) {
  716. this.tbody.removeChild(rows[i]);
  717. }
  718. for (var i = 0, l = nodes.length; i < l; i++) {
  719. this.createRow(nodes[i], i);
  720. }
  721. this.updateBreadCrumbs(selected);
  722. //this.domNode.focus(); // causes the dialog not to show the second time .. after domNode was created..
  723. if (callback) {
  724. callback();
  725. }
  726. }));
  727. },
  728. getObjectTypeLabel: function (container) {
  729. var type;
  730. if (container.type === 'web') {
  731. type = this.getString('IDS_SP_OBJECT_TYPE_SITE');
  732. } else if (container.type === 'folder') {
  733. type = this.getString('IDS_SP_OBJECT_TYPE_FOLDER');
  734. } else if (container.type === 'list') {
  735. if (this.objectTree.listType === SP.ListTemplateType.documentLibrary) {
  736. type = this.getString('IDS_SP_OBJECT_TYPE_DOCUMENT_LIBRARY');
  737. } else if (this.objectTree.listType === SP.ListTemplateType.discussionBoard) {
  738. type = this.getString('IDS_SP_OBJECT_TYPE_DISCUSSION_LIST');
  739. }
  740. }
  741. return type;
  742. },
  743. resize: function () {
  744. this.content.style.height = (this.domNode.clientHeight - this.header.clientHeight - this.footer.clientHeight - 20) + 'px';
  745. },
  746. initialize: function (callback) {
  747. ExecuteOrDelayUntilScriptLoaded(
  748. Function.createDelegate(this, function () {
  749. if (!this.initialized) {
  750. this.objectTree.initialize(Function.createDelegate(this, function () {
  751. if (this.objectTree.error) {
  752. callback();
  753. return;
  754. }
  755. if (this.objectTree.ignoredUserSelection) {
  756. this.ignoredSelection = this.objectTree.getSelectionData(this.objectTree.ignoredUserSelection);
  757. this.ignoredSelection.typeLabel = this.getObjectTypeLabel(this.ignoredSelection);
  758. }
  759. this.createDomNode();
  760. this.setSelection(this.objectTree.getNode());
  761. this.initialized = true;
  762. callback();
  763. }));
  764. }
  765. }), 'core.js');
  766. },
  767. show: function (allowAutoSelection) {
  768. if (!this.initialized) {
  769. this.initialize(Function.createDelegate(this, this.show));
  770. return;
  771. }
  772. this.updateContent(this.objectTree.getNode(), Function.createDelegate(this, function () {
  773. var node = this.objectTree.getNode();
  774. var isPromptNotRequiredHint = this.objectTree.canWriteToNode(node);
  775. if (allowAutoSelection && isPromptNotRequiredHint && (this.isPrompted === undefined || !this.isPrompted)) {
  776. this.updateSelectionInfo();
  777. this.okCallback(this.selection);
  778. } else {
  779. var self = this;
  780. var options = {
  781. html: this.domNode,
  782. title: this.title,
  783. height: this.height,
  784. width: this.width,
  785. allowMaximize: false,
  786. showClose: true,
  787. dialogReturnValueCallback: function (result, data) {
  788. if (result === SP.UI.DialogResult.OK && self.okCallback) {
  789. self.okCallback(data);
  790. }
  791. }
  792. };
  793. this.isPrompted = true;
  794. this.dialogSP = SP.UI.ModalDialog.showModalDialog(options);
  795. this.domNode.focus();
  796. this.resize();
  797. }
  798. }));
  799. }
  800. }
  801. com_ibm_cognos_cps.sp.CPSCollaboration = function (context, id, messages) {
  802. this.context = context;
  803. this.id = id
  804. this.messages = messages;
  805. // start the initialization once the sp.js is loaded.
  806. ExecuteOrDelayUntilScriptLoaded(Function.createDelegate(this, this.initialize), 'sp.js');
  807. com_ibm_cognos_cps.sp.CPSCollaboration.prototype.instances[id] = this;
  808. }
  809. com_ibm_cognos_cps.sp.CPSCollaboration.prototype = {
  810. instances: {},
  811. initialize: function () {
  812. var initializeMenus = Function.createDelegate(this, function () {
  813. this.discussionSelectionDlg = new com_ibm_cognos_cps.sp.SelectDialog({
  814. title: this.getString('IDS_SP_EDT_SELECT_DLG_DISCUSSION_TITLE'),
  815. height: 350,
  816. width: 500,
  817. messages: this.messages,
  818. objectTree: new com_ibm_cognos_cps.sp.ObjectTree({
  819. listType: SP.ListTemplateType.discussionBoard,
  820. isShowRootWeb: false,
  821. isHideListFolders: true,
  822. selectionSpec: this.context.getProperty('parameters')['discussionSpec']
  823. })
  824. });
  825. this.discussionSelectionDlg.initialize(Function.createDelegate(this, function () {
  826. // hide discussion menu if we have security exception
  827. if (!this.discussionSelectionDlg.objectTree.error) {
  828. this.showDiscussMenu();
  829. }
  830. }));
  831. this.publishSelectionDlg = new com_ibm_cognos_cps.sp.SelectDialog({
  832. title: this.getString('IDS_SP_EDT_SELECT_DLG_PUBLISH_TITLE'),
  833. height: 350,
  834. width: 500,
  835. messages: this.messages,
  836. objectTree: new com_ibm_cognos_cps.sp.ObjectTree({
  837. listType: SP.ListTemplateType.documentLibrary,
  838. isShowRootWeb: false,
  839. selectionSpec: this.context.getProperty('parameters')['publishSpec']
  840. })
  841. });
  842. var _self = this;
  843. this.publishSelectionDlg.initialize(Function.createDelegate(this, function () {
  844. if (!this.publishSelectionDlg.objectTree.error) {
  845. _self.initializePublishMenu();
  846. }
  847. }));
  848. });
  849. this.getFeedEntry(initializeMenus);
  850. },
  851. /* Return a unique Id */
  852. getId: function (id) {
  853. return this.id + '.' + id;
  854. },
  855. /* Return the localized string */
  856. getString: function (id, args) {
  857. if (this.messages && this.messages[id]) {
  858. var msg = this.messages[id];
  859. if (args) {
  860. for (var i = 0, l = args.length; i < l; i++) {
  861. msg = msg.replace('$' + (i + 1), args[i]);
  862. }
  863. }
  864. return msg;
  865. }
  866. return id + ' [' + (args ? args.toString() : '') + ']';
  867. },
  868. /* Returns the href value of the feed entry link */
  869. getLink: function (entry, rel, type, location) {
  870. var links = this.insureArray(entry.link);
  871. for (var i = 0, l = links.length; i < l; i++) {
  872. if (links[i].rel === rel && links[i].type === type) {
  873. if (location === 'webcontent') {
  874. return this.context.getWebContentResource(links[i].href);
  875. } else {
  876. return this.context.getGatewayResource(links[i].href);
  877. }
  878. }
  879. }
  880. },
  881. /* Returns the text content of an xml node*/
  882. getElementText: function (document, path) {
  883. return com_ibm_cognos_cps._F_DOM.text(com_ibm_cognos_cps._F_DOM.selectSingleNode(document, path));
  884. },
  885. /* Returns the CM object id */
  886. getObjectId: function () {
  887. return this.context.getProperty('parameters')['reportStoreId'];
  888. },
  889. getObjectPath: function () {
  890. return this.context.getProperty('parameters')['searchPath'];
  891. },
  892. getObjectUrl: function () {
  893. return this.context.getProperty('parameters')['objectUrl'];
  894. },
  895. isPublishWithoutPrompt: function () {
  896. return this.context.getProperty('parameters')['publishWithoutPrompt'] === 'true';
  897. },
  898. isRunSupported: function () {
  899. return this.context.getProperty('parameters')['canRun'];
  900. },
  901. getSessionId: function () {
  902. return this.context.getProperty('parameters')['sessionId'];
  903. },
  904. /* Returns the gateway url */
  905. getGateway: function () {
  906. return this.context.getProperty('gateway');
  907. },
  908. /* Returns the webcontent url */
  909. getWebcontent: function () {
  910. return this.context.getProperty('webcontent');
  911. },
  912. /* Returns the content locale */
  913. getContentLocale: function () {
  914. return this.context.getProperty('contentLocale')
  915. },
  916. getSessionInfo: function () {
  917. var sessionController = this.context.getProperty('sessionController');
  918. return sessionController ? sessionController.sessionInfo : null;
  919. },
  920. toAbsolute: function (relativeUrl) {
  921. return document.location.protocol + '//' + document.location.host + (document.location.port ? (':' + document.location.port) : '') + relativeUrl;
  922. },
  923. /* Returns a string that can be evaluated to run a this.method(parameters) */
  924. createFunctionCall: function (functionName) {
  925. var call = 'com_ibm_cognos_cps.sp.CPSCollaboration.prototype.instances["' + this.id.replace(/"/g, '\\"') + '"].' + functionName + '(';
  926. for (var i = 1, l = arguments.length; i < l; i++) {
  927. if (i > 1) {
  928. call += ', ';
  929. }
  930. var arg = arguments[i];
  931. if (arg === undefined || arg === null) {
  932. call += 'null';
  933. } else if (typeof arg === 'boolean' || typeof arg === 'number') {
  934. call += arg;
  935. } else {
  936. call += '"' + arg.toString().replace(/"/g, '\\"') + '"';
  937. }
  938. }
  939. call += ')';
  940. return call;
  941. },
  942. /* Show a sharepoint notification */
  943. showNotification: function (notification, sticky) {
  944. this.removeNotification();
  945. var notificationId = SP.UI.Notify.addNotification(notification, sticky);
  946. if (!sticky) {
  947. this.notificationId = notificationId;
  948. }
  949. return notificationId;
  950. },
  951. /* Hide a sharepoint notification */
  952. removeNotification: function (id) {
  953. if (id) {
  954. SP.UI.Notify.removeNotification(id);
  955. } else if (this.notificationId) {
  956. SP.UI.Notify.removeNotification(this.notificationId);
  957. this.notificationId = null;
  958. }
  959. },
  960. /* Insure that the object is an array, if not an array with the object will be returned */
  961. insureArray: function (obj) {
  962. if (!obj || obj.length) {
  963. return obj;
  964. } else {
  965. return [obj];
  966. }
  967. },
  968. handleError: function (e, htmlErrorPage) {
  969. if (this.errorStatus) {
  970. SP.UI.Status.removeStatus(this.errorStatus);
  971. }
  972. var message = e.message ? e.message : e.toString();
  973. if (message === 'cps.invalidCredentials') {
  974. message = this.getString('IDS_SP_ERROR_SESSION_EXPIRED');
  975. } else if (htmlErrorPage) {
  976. // open up that HTML markup and let the end-user deal with it
  977. message = this.extractTagText(htmlErrorPage, 'ERROR_MSG');
  978. var w = window.open('', '_blank', 'width=700,height=600,resizable,status=no,menubar=no,toolbar=no,location=no');
  979. w.document.open();
  980. w.document.write(htmlErrorPage);
  981. w.document.close();
  982. w.focus();
  983. }
  984. this.errorStatus = SP.UI.Status.addStatus(this.getString('IDS_SP_ERROR_LABEL'), '', false);
  985. SP.UI.Status.setStatusPriColor(this.errorStatus, 'red');
  986. message = message + ' &nbsp;<a href="javascript:SP.UI.Status.removeStatus(\'' + this.errorStatus + '\')">' + this.getString('IDS_SP_ERROR_CLEAR') + '</a>';
  987. SP.UI.Status.updateStatus(this.errorStatus, message);
  988. },
  989. extractTagText: function (text, tagName) {
  990. var lowerText = text.toLowerCase();
  991. tagName = tagName.toLowerCase();
  992. var fromIndex = lowerText.indexOf('<' + tagName);
  993. if (fromIndex == -1) {
  994. return '';
  995. }
  996. // skip attributes
  997. fromIndex = lowerText.indexOf('>', fromIndex + tagName.length + 1);
  998. if (fromIndex == -1) {
  999. return '';
  1000. }
  1001. fromIndex++;
  1002. var toIndex = lowerText.indexOf('</' + tagName + '>', fromIndex);
  1003. if (toIndex == -1) {
  1004. return '';
  1005. }
  1006. return text.substring(fromIndex, toIndex);
  1007. },
  1008. showPublishMenu: function () {
  1009. // show the publish menu
  1010. document.getElementById(this.getId('id.toolbar')).style.display = '';
  1011. document.getElementById(this.getId('id.publish_menulink')).style.display = '';
  1012. },
  1013. showDiscussMenu: function () {
  1014. // show the publish menu
  1015. document.getElementById(this.getId('id.toolbar')).style.display = '';
  1016. document.getElementById(this.getId('id.discuss_menulink')).style.display = '';
  1017. },
  1018. /* helper function that sends an ajax request */
  1019. sendRequest: function (url, xhrOptions) {
  1020. try {
  1021. var xhr = this.context.getXHR();
  1022. var method = xhrOptions.method ? xhrOptions.method : 'GET';
  1023. xhr.open(method, xhrOptions.noProxy ? url : this.context.getProxiedResource(url), true);
  1024. if (method === 'POST') {
  1025. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  1026. }
  1027. if (xhrOptions.includeSessionHeader) {
  1028. xhr.setRequestHeader('com-ibm-congos-cps-session', this.getSessionInfo());
  1029. }
  1030. xhr.onreadystatechange = function () {
  1031. if (xhr.readyState == 4) {
  1032. if (xhr.status >= 200 && xhr.status < 300) {
  1033. if (xhrOptions.callback) {
  1034. xhrOptions.callback(xhr);
  1035. }
  1036. } else {
  1037. if (xhrOptions.callbackOnFailure) {
  1038. xhrOptions.callbackOnFailure(null);
  1039. }
  1040. }
  1041. }
  1042. }
  1043. xhr.send(xhrOptions.data ? xhrOptions.data : null);
  1044. } catch (e) {
  1045. this.handleError(e);
  1046. }
  1047. },
  1048. /* Get the CM object feed entry */
  1049. getFeedEntry: function (callback) {
  1050. var objId = this.getObjectId();
  1051. var url = this.getGateway() + '/icd/feeds/cm/id/' + objId + '?entry=&json=';
  1052. var self = this;
  1053. this.sendRequest(url, {
  1054. method: 'GET',
  1055. callback: Function.createDelegate(this, function (xhr) { this.getFieldEntryCallback(xhr, callback); })
  1056. });
  1057. },
  1058. /* feed entry ajax callback. Used to add the list of reports/outputs to the "publish" menu */
  1059. getFieldEntryCallback: function (xhr, callback) {
  1060. this.reports = [];
  1061. this.atomEntry = eval('(' + xhr.responseText + ')');
  1062. this.versionMap = {};
  1063. if (this.atomEntry.entry) {
  1064. this.objectTitle = this.atomEntry.entry.title._text;
  1065. }
  1066. if (callback) {
  1067. callback();
  1068. }
  1069. },
  1070. initializePublishMenu: function () {
  1071. var type = this.atomEntry.entry['cm$targetObjectClass'] ? this.atomEntry.entry['cm$targetObjectClass'] : this.atomEntry.entry['cm$objectClass'];
  1072. if (!PUBLISH_OBJECT_TYPES[type]) {
  1073. // object type does not support publishing.
  1074. return;
  1075. }
  1076. this.showPublishMenu();
  1077. if (this.atomEntry.entry.dashboard) {
  1078. this.isDashboard = true;
  1079. var cl = this.getContentLocale();
  1080. // find all reports in the dashboard and get version.
  1081. var pageArr = this.insureArray(this.atomEntry.entry.dashboard.page);
  1082. var i, l = pageArr.length;
  1083. for (i = 0; i < l; i++) {
  1084. var instanceArr = {};
  1085. if (pageArr[i].widgetInstance !== undefined) {
  1086. instanceArr = this.insureArray(pageArr[i].widgetInstance);
  1087. }
  1088. for (var z = 0; z < instanceArr.length; z++) {
  1089. var instance = instanceArr[z];
  1090. if (instance.url.indexOf('ViewerIWidget.xml') != -1) {
  1091. var report = {};
  1092. report.title = instance.title;
  1093. // Try to find localized custom title
  1094. if (instance.customTitles) {
  1095. if (instance.customTitles.title) {
  1096. var titleArray = this.insureArray(instance.customTitles.title);
  1097. for (var j = 0, jlength = titleArray.length; j < jlength; j++) {
  1098. if (titleArray[j].locale === cl) {
  1099. report.title = titleArray[j].value;
  1100. break;
  1101. }
  1102. }
  1103. }
  1104. }
  1105. this.reports.push(report);
  1106. if (instance.contentItemSet && instance.contentItemSet.item) {
  1107. var j, k = instance.contentItemSet.item.length;
  1108. for (j = 0; j < k; j++) {
  1109. var item = instance.contentItemSet.item[j];
  1110. if (item.id === 'savedReportId') {
  1111. report.id = item.value;
  1112. } else if (item.id === 'savedReportName') {
  1113. report.name = item.value;
  1114. } else if (item.id === 'objectClass') {
  1115. report.type = item.value;
  1116. }
  1117. }
  1118. }
  1119. var reportSubMenu = CASubM(this.getPublishMenu(), report.title);
  1120. this.getVersions(report, reportSubMenu);
  1121. }
  1122. }
  1123. }
  1124. } else {
  1125. var report = { id: this.getObjectId(), title: this.objectTitle, type: type };
  1126. this.reports.push(report);
  1127. this.getVersions(report, this.getPublishMenu());
  1128. }
  1129. },
  1130. /* Get the output feed of a report and add the outputs to the "publish* menu */
  1131. getVersions: function (report, publishMenu) {
  1132. var url = this.getGateway() + '/atom/cm/id/' + report.id + '?filter=content-version&json';
  1133. this.sendRequest(url, {
  1134. method: 'GET',
  1135. callback: Function.createDelegate(this, function (xhr) {
  1136. var response = eval('(' + xhr.responseText + ')');
  1137. report.versionsFeed = response.feed;
  1138. this.createReportMenu(report, publishMenu);
  1139. })
  1140. });
  1141. },
  1142. /* Return the publish menu object */
  1143. getPublishMenu: function () {
  1144. if (this.publishMenu == null) {
  1145. this.publishMenu = CMenu(this.getId('id.publish_menu'));
  1146. }
  1147. return this.publishMenu;
  1148. },
  1149. /* Open the "publish" menu item */
  1150. publishMenuClick: function () {
  1151. OMenu(this.getPublishMenu(), document.getElementById(this.getId('id.publish_menulink')), true, null, -1);
  1152. },
  1153. /* Populate the "publish" menu with the menu items associated with a report */
  1154. createReportMenu: function (report, parentMenu) {
  1155. if (this.isRunSupported()) {
  1156. if (PUBLISH_OBJECT_TYPES[report.type].runFormats) {
  1157. var formats = PUBLISH_OBJECT_TYPES[report.type].runFormats;
  1158. var l = formats.length;
  1159. if (l > 0) {
  1160. // add the formats menu
  1161. var formatsSubMenu = CASubM(parentMenu, this.getString('IDS_SP_MENU_RUN_PUBLISH')); // 'Run and publish');
  1162. for (var i = 0; i < l; i++) {
  1163. CAMOpt(formatsSubMenu, formats[i].name, this.createFunctionCall('runAndPublish', report.id, formats[i].value, report.title), this.getWebcontent() + formats[i].icon);
  1164. }
  1165. }
  1166. }
  1167. }
  1168. if (report.versionsFeed) {
  1169. var versions = this.insureArray(report.versionsFeed.entry);
  1170. if (versions && versions.length > 0) {
  1171. var subMenu = CASubM(parentMenu, this.getString('IDS_SP_MENU_VERSIONS')); // 'Versions'
  1172. var versionResponseArr = [];
  1173. for (var i = 0, l = versions.length; i < l; i++) {
  1174. var version = versions[i];
  1175. var name = version.title._text;
  1176. versionResponseArr.push({ name: name, received: false, text: null });
  1177. //call to build the version submenu
  1178. var outputUrl = this.getLink(version, 'alternate', 'application/atom+xml');
  1179. this.createReportOutputVersionSubMenu(report, subMenu, outputUrl, versionResponseArr, i, versions.length);
  1180. }
  1181. }
  1182. }
  1183. },
  1184. createReportOutputVersionSubMenu: function (report, subMenu, outputUrl, versionResponseArr, versionResponseIndex, expectedVersionCount) {
  1185. // do an ajax to get the outputs..
  1186. this.sendRequest(outputUrl, {
  1187. method: 'GET',
  1188. callback: Function.createDelegate(this, function (xhr) {
  1189. var name = versionResponseArr[versionResponseIndex].name;
  1190. versionResponseArr[versionResponseIndex] = { name: name, received: true, text: xhr.responseText };
  1191. this.tryPopulateOutputVersionSubMenu(report, subMenu, versionResponseArr, expectedVersionCount);
  1192. }),
  1193. callbackOnFailure: Function.createDelegate(this, function (xhr) {
  1194. var name = versionResponseArr[versionResponseIndex].name;
  1195. versionResponseArr[versionResponseIndex] = { name: name, received: true, text: null };
  1196. this.tryPopulateOutputVersionSubMenu(report, subMenu, versionResponseArr, expectedVersionCount, subMenu);
  1197. })
  1198. });
  1199. },
  1200. tryPopulateOutputVersionSubMenu: function (report, subMenu, versionResponseArr, expectedVersionCount) {
  1201. var responseCount = 0; // count the version outputs received so far
  1202. for (var i = 0; i < versionResponseArr.length; i++) {
  1203. if (versionResponseArr[i] != null && versionResponseArr[i].received) {
  1204. responseCount += 1;
  1205. }
  1206. }
  1207. var receivedAllVersionResponses = (responseCount == expectedVersionCount);
  1208. if (receivedAllVersionResponses) {
  1209. for (var i = 0; i < versionResponseArr.length; i++) {
  1210. var name = versionResponseArr[i].name;
  1211. var responseText = versionResponseArr[i].text;
  1212. if (responseText != null) {
  1213. try {
  1214. var output = eval('(' + responseText + ')');
  1215. this.createOutputMenu(subMenu, name, output.feed, report);
  1216. } catch (e) {
  1217. //ignore bad response
  1218. }
  1219. }
  1220. }
  1221. }
  1222. },
  1223. /* Create the output sub-menu */
  1224. createOutputMenu: function (versionsMenu, versionName, outputFeed, report) {
  1225. var versionMenu = null;
  1226. var outputs = this.insureArray(outputFeed.entry);
  1227. if (outputs && outputs.length > 0) {
  1228. var j, k = outputs.length;
  1229. for (j = 0; j < k; j++) {
  1230. var output = outputs[j];
  1231. var outputFormatName = output.title._text
  1232. var icon = this.getLink(output, 'icon', 'image/gif', 'webcontent');
  1233. var url = this.getLink(output, 'action.download', 'application/octet-stream');
  1234. if (url) {
  1235. if (versionMenu === null) {
  1236. versionMenu = CASubM(versionsMenu, versionName);
  1237. }
  1238. CAMOpt(versionMenu, outputFormatName, this.createFunctionCall('publishUrlContent', url, report.title), icon);
  1239. }
  1240. }
  1241. }
  1242. },
  1243. /* Do an Ajax request to run a report, then publish the content to the document library */
  1244. runAndPublish: function (reportId, format, title) {
  1245. if (this.getSessionInfo() == null) {
  1246. this.showNotification(this.getString('IDS_SP_PUBLISH_NO_SESSION'), false);
  1247. return;
  1248. }
  1249. var notification = null;
  1250. var runFunction = Function.createDelegate(this, function (runUrl, docLibUrl, filename, postData) {
  1251. if (!notification) {
  1252. notification = this.showNotification(this.getString('IDS_SP_RUNNING_REPORT'), true); // 'Running report ..'
  1253. }
  1254. this.sendRequest(runUrl, {
  1255. method: postData ? 'POST' : 'GET',
  1256. includeSessionHeader: true,
  1257. data: postData,
  1258. callback: Function.createDelegate(this, function (xhr) {
  1259. var response = eval('(' + xhr.responseText + ')');
  1260. if (response.status === 'complete') {
  1261. this.removeNotification(notification);
  1262. this.publishDocument(docLibUrl, this.getGateway() + '?' + response.url, filename);
  1263. } else if (response.status.indexOf('working') !== -1) {
  1264. // build the run url and poll..
  1265. var postParams = '';
  1266. for (var name in response.parameters) {
  1267. if (postParams !== '') {
  1268. postParams += '&';
  1269. }
  1270. postParams += name + '=' + encodeURIComponent(response.parameters[name]);
  1271. }
  1272. runFunction(this.getGateway(), docLibUrl, filename, postParams);
  1273. }
  1274. else if (response.status === 'prompting') {
  1275. this.removeNotification(notification);
  1276. this.handleError(this.getString('IDS_SP_PUBLISH_MISSING_PROMPTS'));
  1277. }
  1278. else if (response.fault) {
  1279. this.removeNotification(notification);
  1280. var error;
  1281. if (response.status === 'authenticationFault') {
  1282. error = this.getString('IDS_SP_ERROR_SESSION_EXPIRED');
  1283. } else {
  1284. var faultElement = com_ibm_cognos_cps._F_DOM.parseXml(response.fault);
  1285. var messageNode = com_ibm_cognos_cps._F_DOM.selectSingleNode(faultElement, '/SOAP-ENV:Envelope/SOAP-ENV:Body/SOAP-ENV:Fault/SOAP-ENV:detail/bus:exception/bus:message');
  1286. if (!messageNode) {
  1287. var messageNode = com_ibm_cognos_cps._F_DOM.selectSingleNode(faultElement, '/SOAP-ENV:Envelope/SOAP-ENV:Body/SOAP-ENV:Fault/detail/bus:exception/bus:message');
  1288. }
  1289. if (!messageNode) {
  1290. messageNode = com_ibm_cognos_cps._F_DOM.selectSingleNode(faultElement, '/SOAP-ENV:Envelope/SOAP-ENV:Body/SOAP-ENV:Fault/faultstring');
  1291. }
  1292. if (messageNode) {
  1293. error = com_ibm_cognos_cps._F_DOM.text(messageNode);
  1294. } else {
  1295. error = this.getString('IDS_SP_CANNOT_RUN_REPORT');
  1296. }
  1297. }
  1298. // conversation object does not exist. It must be because the report didn't run
  1299. if (error.indexOf('RSV-BBP-0028') != -1) {
  1300. this.showNotification(this.getString('IDS_SP_PUBLISH_NO_SESSION'), false);
  1301. return;
  1302. }
  1303. this.handleError(error);
  1304. }
  1305. })
  1306. });
  1307. });
  1308. var dlg = this.publishSelectionDlg;
  1309. dlg.okCallback = Function.createDelegate(this, function (data) {
  1310. var runUrl;
  1311. if (this.isDashboard) {
  1312. // if it's a dashboard we simply run the reports
  1313. runUrl = this.getGateway() + '?b_action=cognosViewer&ui.action=run&run.prompt=false&ui.object=storeID("' + reportId + '")&cv.responseFormat=downloadObjectJSON&run.outputFormat=' + format;
  1314. } else {
  1315. // Otherwise we use the render action to re-use existing conversation saved by the viewer
  1316. runUrl = this.getGateway() + '?b_action=cognosViewer&ui.action=render&cv.responseFormat=downloadObjectJSON&run.outputFormat=' + format + '&m_sessionConv=' + encodeURIComponent(this.getSessionId());
  1317. }
  1318. runFunction(runUrl, data.url, data.fileName);
  1319. });
  1320. dlg.setNameInput(title);
  1321. dlg.show(this.isPublishWithoutPrompt());
  1322. },
  1323. /* Publish a url content to the document library */
  1324. publishUrlContent: function (downloadUrl, title) {
  1325. var dlg = this.publishSelectionDlg;
  1326. dlg.okCallback = Function.createDelegate(this, function (data) {
  1327. this.publishDocument(data.url, downloadUrl, data.fileName);
  1328. });
  1329. dlg.setNameInput(title);
  1330. dlg.show(this.isPublishWithoutPrompt());
  1331. },
  1332. publishDocument: function (docLibUrl, downloadUrl, fileName, update) {
  1333. // we calcualte the the ajax service url from the proxy url.. otherwise, the session cookies will not be used in the request.
  1334. var ajaxUrl = this.context.getProxiedResource('').replace('/CognosResources/resource.axd', '/CognosServices/collaboration.axd');
  1335. ajaxUrl += '&op=addFile';
  1336. ajaxUrl += '&outputUrl=' + encodeURIComponent(downloadUrl);
  1337. ajaxUrl += '&documentLibrary=' + encodeURIComponent(this.toAbsolute(docLibUrl));
  1338. ajaxUrl += '&nameOverride=' + encodeURIComponent(fileName);
  1339. if (update) {
  1340. ajaxUrl += '&writeMode=update';
  1341. }
  1342. this.sendRequest(ajaxUrl, {
  1343. method: 'POST',
  1344. includeSessionHeader: true,
  1345. noProxy: true,
  1346. callback: Function.createDelegate(this, function (xhr) {
  1347. var response = xhr.responseXML;
  1348. var savedFileName = this.getElementText(response, './result/savedFilename');
  1349. var error = this.getElementText(response, './result/error');
  1350. if (error && error.length > 0) {
  1351. if (error === 'cps.file.exists') {
  1352. // prompt
  1353. var confirm = new ConfirmationDialog({
  1354. title: this.getString('IDS_SP_EDT_SELECT_DLG_PUBLISH_TITLE'),
  1355. buttons: [
  1356. { name: this.getString('IDS_SP_YES'),
  1357. accessKey: 'y',
  1358. callback: Function.createDelegate(this, function () {
  1359. this.publishDocument(docLibUrl, downloadUrl, fileName, true);
  1360. })
  1361. },
  1362. { name: this.getString('IDS_SP_NO'),
  1363. accessKey: 'n',
  1364. callback: Function.createDelegate(this, function () {
  1365. var dlg = this.publishSelectionDlg;
  1366. dlg.setNameInput(fileName);
  1367. dlg.okCallback = Function.createDelegate(this, function (data) {
  1368. this.publishDocument(data.url, downloadUrl, data.fileName, update);
  1369. });
  1370. dlg.show();
  1371. })
  1372. },
  1373. { name: this.getString('IDS_SP_CANCEL'),
  1374. accessKey: 'c'
  1375. }
  1376. ],
  1377. message: this.getString('IDS_SP_DOCUMENT_PUBLISH_EXISTS', [savedFileName]),
  1378. hint: this.getString('IDS_SP_DOCUMENT_PUBLISH_EXISTS_HINT', [savedFileName])
  1379. });
  1380. confirm.show();
  1381. } else {
  1382. var htmlErrorPage = this.getElementText(response, './result/htmlResponse');
  1383. this.handleError(error, htmlErrorPage);
  1384. }
  1385. } else {
  1386. var addUrl = this.getElementText(response, './result/addUrl');
  1387. var docLibTitle = this.publishSelectionDlg.selection.title;
  1388. var fileNameHtml = '<a target="new" href="' + addUrl + '" alt="' + this.getString("IDS_SP_VIEW_DOCUMENT_ALT") + '">' + savedFileName + '</a>';
  1389. var docLibHtml = '<a target="new" href="' + docLibUrl + '" alt="' + this.getString("IDS_SP_VIEW_DOCUMENT_LIBRARY_ALT") + '">' + docLibTitle + '</a>';
  1390. var notification = this.getString('IDS_SP_DOCUMENT_PUBLISHED', [fileNameHtml, docLibHtml]);
  1391. this.showNotification(notification);
  1392. }
  1393. })
  1394. });
  1395. },
  1396. /*
  1397. Discussion board support
  1398. */
  1399. discussMenuClick: function () {
  1400. if (this.discussMenu == null) {
  1401. this.discussMenu = CMenu(this.getId('id.discuss_menu'));
  1402. CAMOpt(this.discussMenu, this.getString('IDS_SP_MENU_DISCUSS_START'), this.createFunctionCall('createDiscussion'));
  1403. CAMOpt(this.discussMenu, this.getString('IDS_SP_MENU_DISCUSS_SHOW_RELATED'), this.createFunctionCall('getRelatedDiscussion'));
  1404. }
  1405. OMenu(this.discussMenu, document.getElementById(this.getId('id.discuss_menulink')), true, null, -1);
  1406. },
  1407. createDiscussion: function () {
  1408. var createDiscussionFunction = Function.createDelegate(this, function (listUrl, listId, webUrl) {
  1409. var context = new SP.ClientContext(webUrl);
  1410. var web = context.get_web();
  1411. var discussionList = web.get_lists().getById(listId);
  1412. var itemCreationInfo = new SP.ListItemCreationInformation();
  1413. itemCreationInfo.set_leafName(this.objectTitle);
  1414. var listItem = discussionList.addItem(itemCreationInfo);
  1415. listItem.set_item('Title', this.objectTitle);
  1416. // fix the url to show the banner and the toolbar, also remove the backurl.
  1417. var url = this.getObjectUrl().replace('cv.header=false', 'cv.header=true').replace('cv.toolbar=false', 'cv.toolbar=true').replace(/&ui.backURL=[^&]*/, "");
  1418. listItem.set_item('Body', this.getString('IDS_SP_DISCUSSION_BODY', ['<a target="_blank" href="' + url + '">' + this.objectTitle + '</a>']));
  1419. listItem.set_item('ThreadTopic', this.getObjectPath());
  1420. listItem.update();
  1421. context.load(listItem);
  1422. context.load(discussionList);
  1423. context.executeQueryAsync(Function.createDelegate(this, function () {
  1424. var myCallback = Function.createDelegate(this, function (response) {
  1425. if (response == 1) {
  1426. this.showNotification(
  1427. '<a target="_blank" href="' +
  1428. listUrl +
  1429. '" alt="Click to view">' + this.getString('IDS_SP_DISCUSSION_STARTED') + '</a>', false);
  1430. } else {
  1431. listItem.deleteObject();
  1432. context.executeQueryAsync(function () { }, function () { });
  1433. }
  1434. });
  1435. var runUrl = '/_layouts/listform.aspx?PageType=6&ListId=' + listId + '&id=' + listItem.get_id();
  1436. if (webUrl && webUrl != '/') {
  1437. runUrl = webUrl + runUrl;
  1438. }
  1439. var options = { url: runUrl, width: 650, dialogReturnValueCallback: myCallback };
  1440. SP.UI.ModalDialog.showModalDialog(options);
  1441. }),
  1442. Function.createDelegate(this, function (request, error) { this.handleError(error.get_message()) })
  1443. );
  1444. });
  1445. var dlg = this.discussionSelectionDlg;
  1446. dlg.okCallback = function (data) {
  1447. createDiscussionFunction(data.url, data.listId, data.webUrl);
  1448. }
  1449. dlg.show(true);
  1450. },
  1451. getRelatedDiscussion: function () {
  1452. var callback = Function.createDelegate(this, function (listUrl) {
  1453. var url = listUrl + '?FilterField1=ThreadTopic&FilterValue1=' + encodeURIComponent(this.getObjectPath());
  1454. var myCallback = function () { /*nothing*/ };
  1455. var options = { url: url, width: 650, height: 500, dialogReturnValueCallback: myCallback };
  1456. SP.UI.ModalDialog.showModalDialog(options);
  1457. });
  1458. var dlg = this.discussionSelectionDlg;
  1459. dlg.okCallback = function (data) {
  1460. callback(data.url);
  1461. }
  1462. dlg.show(true);
  1463. }
  1464. };
  1465. })();