cvSubscriptionManager.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *| IBM Cognos Products: Viewer
  5. *| (C) Copyright IBM Corp. 2001, 2012
  6. *|
  7. *| US Government Users Restricted Rights - Use, duplication or
  8. *| disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  9. *|
  10. *+------------------------------------------------------------------------+
  11. */
  12. // constants
  13. CSubscriptionManager.k_SubscriptionWizardName = "subscriptionWizard";
  14. function CSubscriptionManager(cv)
  15. {
  16. this.m_cv = cv;
  17. /**
  18. @type boolean
  19. @private
  20. */
  21. this.m_bInitialized = false;
  22. /**
  23. @type array
  24. @private
  25. */
  26. this.m_aWatchRules = null;
  27. /**
  28. @type string
  29. @private
  30. */
  31. this.m_sEmail = "";
  32. /**
  33. @type string
  34. @private
  35. */
  36. this.m_sAlertNewVersionConfirm = "";
  37. /**
  38. @type boolean
  39. @private
  40. */
  41. this.m_sQueryNotificationResponse = "";
  42. /**
  43. @type boolean
  44. @private
  45. */
  46. this.m_bAllowNotification = false;
  47. /**
  48. @type boolean
  49. @private
  50. */
  51. this.m_bAllowSubscription = false;
  52. /**
  53. @type boolean
  54. @private
  55. */
  56. this.m_bCanCreateNewWatchRule = false;
  57. /**
  58. @type boolean
  59. @private
  60. */
  61. this.m_bCanGetNotified = false;
  62. /**
  63. @type boolean
  64. @private
  65. */
  66. this.m_bAllowAnnotations = false;
  67. /**
  68. @type boolean
  69. @private
  70. */
  71. this.m_bCanCreateAnnotations = false;
  72. /**
  73. @type string
  74. @private
  75. */
  76. this.m_windowOptions = "width=450,height=350,toolbar=0,location=0,status=0,menubar=0,resizable,scrollbars=1";
  77. //"width=500,height=350,toolbar=0,location=0,status=0,menubar=0,resizable,scrollbars=1";
  78. }
  79. CSubscriptionManager.prototype.getViewer = function() {
  80. return this.m_cv;
  81. };
  82. /**
  83. Initialize the subscription member variables with the server response
  84. */
  85. CSubscriptionManager.prototype.Initialize = function(response)
  86. {
  87. try
  88. {
  89. var oJSONResponse = response.getJSONResponseObject();
  90. var formWarpRequest = document.forms['formWarpRequest' + this.m_cv.getId()];
  91. if (oJSONResponse["annotationInfo"]) {
  92. var oAnnotationInfo = oJSONResponse["annotationInfo"];
  93. this.m_AnnotationsCount = oAnnotationInfo.annotations.length;
  94. // Push the whole annotations in current session
  95. this.m_annotations = oAnnotationInfo.annotations;
  96. this.m_bAllowAnnotations = oAnnotationInfo.allowAnnotations;
  97. this.m_bCanCreateAnnotations = oAnnotationInfo.traverse == "true";
  98. return true;
  99. }
  100. if (oJSONResponse["subscriptionInfo"])
  101. {
  102. var oSubscriptionInfo = oJSONResponse["subscriptionInfo"];
  103. if (!this.m_bInitialized)
  104. {
  105. this.m_sEmail = oSubscriptionInfo.sEmail;
  106. this.m_bAllowNotification = oSubscriptionInfo.bAllowNotification;
  107. this.m_bAllowSubscription = oSubscriptionInfo.bAllowSubscription;
  108. this.m_sAlertNewVersionConfirm = oSubscriptionInfo.sAlertNewVersionConfirm;
  109. if (formWarpRequest["ui.action"] && formWarpRequest["ui.action"].value == 'view')
  110. {
  111. /*
  112. Can the user create new watch rules
  113. - Report output is in HTML with interactive information
  114. - User has the 'Create and Run Watch Rules' capability
  115. - Alerts using watch rules are allowed for the report
  116. */
  117. if (formWarpRequest["ui.format"])
  118. {
  119. this.m_bCanCreateNewWatchRule = (formWarpRequest["ui.format"].value == 'HTML') && this.m_cv.bCanUseCognosViewerConditionalSubscriptions && this.m_bAllowSubscription;
  120. }
  121. /*
  122. Can the user subscribe to notifications
  123. - the report must not be bursted
  124. - user cannot have scheduled the report
  125. - report must allow notifications
  126. */
  127. this.m_bCanGetNotified = (!formWarpRequest["ui.burstKey"] || (formWarpRequest["ui.burstKey"] && formWarpRequest["ui.burstKey"].value == "")) && this.m_bAllowNotification;
  128. }
  129. }
  130. if (oSubscriptionInfo.sQueryNotificationResponse)
  131. {
  132. this.m_sQueryNotificationResponse = oSubscriptionInfo.sQueryNotificationResponse;
  133. }
  134. if (oSubscriptionInfo.aWatchRules)
  135. {
  136. var aWatchRules = oSubscriptionInfo.aWatchRules;
  137. this.m_aWatchRules = [];
  138. for (var i=0; i < aWatchRules.length; i++)
  139. {
  140. this.m_aWatchRules.push( aWatchRules[i] );
  141. }
  142. }
  143. this.m_bInitialized = true;
  144. return true;
  145. }
  146. }
  147. catch(exception)
  148. {
  149. return false;
  150. }
  151. return false;
  152. };
  153. /**
  154. Checks the current selection to see if it's valid for creating a new Watch Rule
  155. */
  156. CSubscriptionManager.prototype.IsValidSelectionForNewRule = function()
  157. {
  158. var selectionController = this.m_cv.getSelectionController();
  159. if (selectionController && !selectionController.hasSelectedChartNodes())
  160. {
  161. var selectedObjects = selectionController.getAllSelectedObjects();
  162. if (selectedObjects.length === 1)
  163. {
  164. if (selectedObjects[0] != null && selectedObjects[0].getLayoutType() != 'columnTitle')
  165. {
  166. return true;
  167. }
  168. }
  169. }
  170. return false;
  171. };
  172. /**
  173. Can the user create new watch rules
  174. */
  175. CSubscriptionManager.prototype.CanCreateNewWatchRule = function()
  176. {
  177. if (typeof this.m_cv.UIBlacklist != "undefined" && this.m_cv.UIBlacklist.indexOf(' RV_TOOLBAR_BUTTONS_ALERT_USING_NEW_WATCH_RULE ') != -1)
  178. {
  179. return false;
  180. }
  181. // if we haven't been initialized yet and we're looking at saved output
  182. if (!this.m_bInitialized && this.getViewer().envParams["ui.action"] == 'view')
  183. {
  184. var oCV = this.getViewer();
  185. var request = new JSONDispatcherEntry(oCV);
  186. request.setKey("subscriptionManager");
  187. request.forceSynchronous();
  188. request.addFormField("ui.action", "getSubscriptionInfo");
  189. request.addFormField("cv.responseFormat", "subscriptionManager");
  190. request.addFormField("contextMenu", "true");
  191. this.addCommonFormFields(request);
  192. request.setCallbacks({"complete":{"object":this, "method":this.Initialize}});
  193. oCV.dispatchRequest(request);
  194. }
  195. return this.m_bCanCreateNewWatchRule;
  196. };
  197. /**
  198. Has the logic to determine if the current user can modify the Watch Rules
  199. */
  200. CSubscriptionManager.prototype.CanModifyWatchRule = function()
  201. {
  202. return this.m_cv.bCanUseCognosViewerConditionalSubscriptions && this.m_bAllowSubscription;
  203. };
  204. /**
  205. Has the logic to determine if the current user can subscribe to notifications
  206. */
  207. CSubscriptionManager.prototype.CanGetNotified = function()
  208. {
  209. if (typeof this.m_cv.UIBlacklist != "undefined" && this.m_cv.UIBlacklist.indexOf(' RV_TOOLBAR_BUTTONS_ALERT_ABOUT_NEW_VERSIONS ') != -1)
  210. {
  211. return false;
  212. }
  213. return this.m_bCanGetNotified;
  214. };
  215. /**
  216. Updates the subscription dropdown menu
  217. */
  218. CSubscriptionManager.prototype.UpdateSubscribeMenu = function()
  219. {
  220. var toolbar = this.getStandaloneViewerToolbarControl();
  221. var subscribeButton = toolbar? toolbar.getItem("watchNewVersions") : null;
  222. var sWebContentRoot = this.m_cv.getWebContentRoot();
  223. var sSkin = this.m_cv.getSkin();
  224. if (subscribeButton)
  225. {
  226. var subscribeDropDownMenu = subscribeButton.getMenu();
  227. // Clear the menu
  228. this.ClearSubscriptionMenu();
  229. var bAddSeperator = false;
  230. if ( this.CanGetNotified() )
  231. {
  232. if (this.m_sQueryNotificationResponse == 'on')
  233. {
  234. new CMenuItem(subscribeDropDownMenu, RV_RES.RV_DO_NOT_ALERT_NEW_VERSION, "javascript:" + this.m_cv.getObjectId() + ".getSubscriptionManager().DeleteNotification();", sWebContentRoot + '/rv/images/action_remove_from_list.gif', gMenuItemStyle, sWebContentRoot, sSkin);
  235. bAddSeperator = true;
  236. }
  237. else if (this.m_sQueryNotificationResponse == 'off' && this.m_sEmail != "")
  238. {
  239. new CMenuItem(subscribeDropDownMenu, RV_RES.RV_ALERT_NEW_VERSION, "javascript:" + this.m_cv.getObjectId() + ".getSubscriptionManager().AddNotification();", sWebContentRoot + '/rv/images/action_add_to_list.gif', gMenuItemStyle, sWebContentRoot, sSkin);
  240. bAddSeperator = true;
  241. }
  242. }
  243. if (this.CanCreateNewWatchRule())
  244. {
  245. if (bAddSeperator)
  246. {
  247. subscribeDropDownMenu.add(gMenuSeperator);
  248. }
  249. var newSubscription = new CMenuItem(subscribeDropDownMenu, RV_RES.RV_NEW_WATCH_RULE, "javascript:" + this.m_cv.getObjectId() + ".getSubscriptionManager().NewSubscription();", sWebContentRoot + '/rv/images/action_new_subscription.gif', gMenuItemStyle, sWebContentRoot, sSkin);
  250. if (!this.IsValidSelectionForNewRule())
  251. {
  252. newSubscription.disable();
  253. }
  254. bAddSeperator = true;
  255. }
  256. var sBlacklist = "";
  257. if (typeof this.m_cv.UIBlacklist != "undefined")
  258. {
  259. sBlacklist = this.m_cv.UIBlacklist;
  260. }
  261. var noWatchRules;
  262. //iterate through existing subscriptions
  263. if (sBlacklist.indexOf(' RV_TOOLBAR_BUTTONS_RULES ') == -1)
  264. {
  265. if (bAddSeperator)
  266. {
  267. subscribeDropDownMenu.add(gMenuSeperator);
  268. }
  269. if ( this.m_aWatchRules && this.m_aWatchRules.length > 0)
  270. {
  271. var bCanModifyWatchRules = this.CanModifyWatchRule();
  272. for(var sub = 0; sub < this.m_aWatchRules.length; ++sub)
  273. {
  274. var menu = new CMenuItem(subscribeDropDownMenu, this.m_aWatchRules[sub].name, "", sWebContentRoot + "/rv/images/icon_subscription.gif", gMenuItemStyle, sWebContentRoot, sSkin);
  275. var subMenu = menu.createCascadedMenu(gMenuStyle);
  276. subMenu.m_oCV = this.m_cv;
  277. if (bCanModifyWatchRules && sBlacklist.indexOf(' RV_TOOLBAR_BUTTONS_RULES_MODIFY ') == -1) {
  278. new CMenuItem(subMenu, RV_RES.RV_MODIFY_WATCH_RULE, this.m_cv.getObjectId() + ".getSubscriptionManager().ModifySubscription("+sub+");", sWebContentRoot + '/rv/images/action_edit.gif', gMenuItemStyle, sWebContentRoot, sSkin);
  279. }
  280. if (sBlacklist.indexOf(' RV_TOOLBAR_BUTTONS_RULES_DELETE ') == -1)
  281. {
  282. new CMenuItem(subMenu, RV_RES.RV_DELETE_WATCH_RULE, this.m_cv.getObjectId() + ".getSubscriptionManager().DeleteSubscription("+sub+");", sWebContentRoot + '/rv/images/action_delete.gif', gMenuItemStyle, sWebContentRoot, sSkin);
  283. }
  284. }
  285. }
  286. else
  287. {
  288. noWatchRules = new CMenuItem(subscribeDropDownMenu, RV_RES.RV_NO_WATCH_RULES, "", '', gMenuItemStyle, sWebContentRoot, sSkin);
  289. noWatchRules.disable();
  290. }
  291. }
  292. if (subscribeDropDownMenu.getNumItems() == 0)
  293. {
  294. noWatchRules = new CMenuItem(subscribeDropDownMenu, RV_RES.RV_NO_WATCH_RULES, "", '', gMenuItemStyle, sWebContentRoot, sSkin);
  295. noWatchRules.disable();
  296. }
  297. // make sure we don't use the callback when drawing the menu
  298. subscribeDropDownMenu.setForceCallback(false);
  299. subscribeDropDownMenu.draw();
  300. if (subscribeDropDownMenu.isVisible()) {
  301. subscribeDropDownMenu.show();
  302. }
  303. // make sure our callback is used when the menu gets opened again
  304. subscribeDropDownMenu.setForceCallback(true);
  305. }
  306. };
  307. /**
  308. Updates the subscription dropdown menu
  309. */
  310. CSubscriptionManager.prototype.UpdateAnnotationMenu = function()
  311. {
  312. var toolbar = this.getStandaloneViewerToolbarControl();
  313. var annotationButton = toolbar? toolbar.getItem("addAnnotations") : null;
  314. var sWebContentRoot = this.m_cv.getWebContentRoot();
  315. var sSkin = this.m_cv.getSkin();
  316. var annotDropDownMenu = annotationButton.getMenu();
  317. // Clear the menu
  318. this.ClearAnnotationMenu();
  319. // add the create menu item
  320. var menu = new CMenuItem(annotDropDownMenu, RV_RES.RV_NEW_COMMENT, "javascript:" + this.m_cv.getObjectId() + ".getSubscriptionManager().NewAnnotation();", sWebContentRoot + "/rv/images/action_comment_add.gif", gMenuItemStyle, sWebContentRoot, sSkin);
  321. var annotationsCount = this.m_annotations.length;
  322. if (annotationsCount > 0) {
  323. annotDropDownMenu.add(gMenuSeperator);
  324. }
  325. // disable the item if allowAnnotations is false.
  326. if (!this.m_bAllowAnnotations || !this.m_bCanCreateAnnotations)
  327. {
  328. menu.disable();
  329. }
  330. //iterate through existing annotations
  331. var menuName;
  332. var bidi = isViewerBidiEnabled() ? BidiUtils.getInstance() : null;
  333. for(var i=0; i<annotationsCount; i++){
  334. var defName = this.m_annotations[i].defaultName ;
  335. menuName = defName.length>60 ? defName.substring(0, 60)+'...' : defName;
  336. if(isViewerBidiEnabled()){
  337. menuName = bidi.btdInjectUCCIntoStr(menuName, getViewerBaseTextDirection());
  338. }
  339. // check all the permissions
  340. var readPermission = Boolean(this.m_annotations[i].permissions.read);
  341. var modifyPermission = Boolean(this.m_annotations[i].permissions.write);
  342. var deletePermission = Boolean(this.m_annotations[i].permissions.traverse) && Boolean(this.m_annotations[i].permissions.write);
  343. var dispCmd = "javascript:" + this.m_cv.getObjectId() + ".getSubscriptionManager().ViewAnnotation("+i+");";
  344. var alertMsg = "javascript:alert('Permission denied')" ;
  345. dispCmd = readPermission ? dispCmd : alertMsg;
  346. // decide if we want to add a separator - which we do if the layoutElementId has changed
  347. if (i > 0 && this.m_annotations[i].layoutElementId != this.m_annotations[i-1].layoutElementId) {
  348. annotDropDownMenu.add(gMenuSeperator);
  349. }
  350. var menuItemImage = "/rv/images/action_comment.gif";
  351. if (this.m_annotations[i].layoutElementId != "") {
  352. menuItemImage = "/rv/images/action_subscribe.gif";
  353. }
  354. menu = new CMenuItem(annotDropDownMenu, menuName, dispCmd, sWebContentRoot + menuItemImage, gMenuItemStyle, sWebContentRoot, sSkin);
  355. // we only create the cascaded menu if can alter things
  356. var subMenu = menu.createCascadedMenu(gMenuStyle);
  357. // add an info pane to the top of the menu
  358. var infoPanel = new CInfoPanel("300px", sWebContentRoot, subMenu.getId() + "_comments");
  359. infoPanel.setParent(subMenu);
  360. // add all the properties that we want
  361. defName = this.m_annotations[i].defaultName ;
  362. var menuName1 = defName.length>60 ? defName.substring(0, 60)+'...' : defName;
  363. if(isViewerBidiEnabled()){
  364. menuName1 = bidi.btdInjectUCCIntoStr(menuName1, getViewerBaseTextDirection());
  365. }
  366. infoPanel.addProperty(RV_RES.RV_VIEW_COMMENT_NAME,html_encode(menuName1));
  367. infoPanel.addSpacer(4);
  368. var cmnt = this.m_annotations[i].description ;
  369. var shortComment = cmnt.length>590 ? cmnt.substring(0, 590)+'...' : cmnt;
  370. if(isViewerBidiEnabled()){
  371. shortComment = bidi.btdInjectUCCIntoStr(shortComment, getViewerBaseTextDirection());
  372. }
  373. infoPanel.addProperty(RV_RES.RV_VIEW_COMMENT_CONTENTS, replaceNewLine(html_encode(shortComment)));
  374. infoPanel.addSpacer(4);
  375. var modifyTime = this.m_annotations[i].modificationTime ;
  376. if(isViewerBidiEnabled()){
  377. modifyTime = bidi.btdInjectUCCIntoStr(modifyTime, getViewerBaseTextDirection());
  378. }
  379. infoPanel.addProperty(RV_RES.RV_VIEW_COMMENT_MODTIME,modifyTime);
  380. var ownerName = this.m_annotations[i].owner.defaultName ;
  381. if(isViewerBidiEnabled()){
  382. ownerName = bidi.btdInjectUCCIntoStr(ownerName, getViewerBaseTextDirection());
  383. }
  384. infoPanel.addProperty(RV_RES.RV_VIEW_COMMENT_OWNER, ownerName);
  385. // add the pane to the menu
  386. subMenu.add(infoPanel);
  387. // add a separator if we have actions
  388. if (modifyPermission || deletePermission) {
  389. subMenu.add(gMenuSeperator);
  390. }
  391. new CMenuItem(subMenu, RV_RES.RV_VIEW_COMMENT, this.m_cv.getObjectId() + ".getSubscriptionManager().ViewAnnotation("+i+");", sWebContentRoot + '/rv/images/action_comment_view.gif', gMenuItemStyle, sWebContentRoot, sSkin);
  392. if (modifyPermission) {
  393. new CMenuItem(subMenu, RV_RES.RV_MODIFY_WATCH_RULE, this.m_cv.getObjectId() + ".getSubscriptionManager().ModifyAnnotation("+i+");", sWebContentRoot + '/rv/images/action_comment_modify.gif', gMenuItemStyle, sWebContentRoot, sSkin);
  394. }
  395. if (deletePermission)
  396. {
  397. new CMenuItem(subMenu, RV_RES.RV_DELETE_WATCH_RULE, this.m_cv.getObjectId() + ".getSubscriptionManager().DeleteAnnotation("+i+");", sWebContentRoot + '/rv/images/action_comment_delete.gif', gMenuItemStyle, sWebContentRoot, sSkin);
  398. }
  399. }
  400. // make sure we don't use the callback when drawing the menu
  401. annotDropDownMenu.setForceCallback(false);
  402. annotDropDownMenu.draw();
  403. if (annotDropDownMenu.isVisible()) {
  404. annotDropDownMenu.show();
  405. }
  406. // make sure our callback is used when the menu gets opened again
  407. annotDropDownMenu.setForceCallback(true);
  408. };
  409. /**
  410. Called when the user clicked on the 'Alert Me About New Versions' link
  411. */
  412. CSubscriptionManager.prototype.AddNotification = function()
  413. {
  414. alert(this.m_sAlertNewVersionConfirm);
  415. var oCV = this.getViewer();
  416. var request = new DataDispatcherEntry(oCV);
  417. request.setKey("subscriptionManager");
  418. request.addFormField("ui.action", "addNotification");
  419. request.addFormField("cv.responseFormat", "data");
  420. this.addCommonFormFields(request);
  421. oCV.dispatchRequest(request);
  422. };
  423. /**
  424. Called when the user clicked on the 'Do Not Alert Me About New Versions' link
  425. */
  426. CSubscriptionManager.prototype.DeleteNotification = function()
  427. {
  428. alert(RV_RES.RV_DO_NOT_ALERT_NEW_VERSION_CONFIRM);
  429. var oCV = this.getViewer();
  430. var request = new DataDispatcherEntry(oCV);
  431. request.setKey("subscriptionManager");
  432. request.addFormField("ui.action", "deleteNotification");
  433. request.addFormField("cv.responseFormat", "data");
  434. this.addCommonFormFields(request);
  435. oCV.dispatchRequest(request);
  436. };
  437. /**
  438. Called when the user clicked on the 'Add annotation' link
  439. */
  440. CSubscriptionManager.prototype.NewAnnotation = function()
  441. {
  442. var oFWR = document.forms["formWarpRequest" + this.m_cv.getId()];
  443. var searchPath = oFWR["ui.object"].value;
  444. var form = GUtil.createHiddenForm("subscriptionForm", "post", this.m_cv.getId(), CSubscriptionManager.k_SubscriptionWizardName);
  445. GUtil.createFormField(form, "ui.object", searchPath);
  446. GUtil.createFormField(form, "b_action", "xts.run");
  447. GUtil.createFormField(form, "m", "rv/annotation1.xts");
  448. GUtil.createFormField(form, "backURL", "javascript:window.close();");
  449. GUtil.createFormField(form, "action_hint", "create");
  450. var sPath = this.m_cv.getWebContentRoot() + "/rv/blankSubscriptionWin.html?cv.id=" + this.m_cv.getId();
  451. window.open(sPath, form.target, this.m_windowOptions);
  452. };
  453. /**
  454. Called when the user clicked on an annotation' link
  455. */
  456. CSubscriptionManager.prototype.ViewAnnotation = function(idx)
  457. {
  458. var sub = this.m_annotations[idx];
  459. var searchPath = sub.searchPath;
  460. var form = GUtil.createHiddenForm("subscriptionForm", "post", this.m_cv.getId(), CSubscriptionManager.k_SubscriptionWizardName);
  461. GUtil.createFormField(form, "ui.object", searchPath);
  462. GUtil.createFormField(form, "b_action", "xts.run");
  463. GUtil.createFormField(form, "m", "rv/annotation1.xts");
  464. GUtil.createFormField(form, "backURL", "javascript:window.close();");
  465. var sPath = this.m_cv.getWebContentRoot() + "/rv/blankSubscriptionWin.html?cv.id=" + this.m_cv.getId();
  466. window.open(sPath, form.target, this.m_windowOptions);
  467. };
  468. /**
  469. User clicked the 'Modify...' link for a Watch Rule
  470. @param idx - index of the rule that was clicked on
  471. */
  472. CSubscriptionManager.prototype.ModifyAnnotation = function(idx)
  473. {
  474. var sub = this.m_annotations[idx];
  475. var searchPath = this.m_annotations[idx].searchPath;
  476. // we need report version here
  477. if (sub && searchPath)
  478. {
  479. var form = GUtil.createHiddenForm("subscriptionForm", "post", this.m_cv.getId(),
  480. CSubscriptionManager.k_SubscriptionWizardName);
  481. GUtil.createFormField(form, "ui.object", searchPath);
  482. GUtil.createFormField(form, "b_action", "xts.run");
  483. GUtil.createFormField(form, "m", "rv/annotation1.xts");
  484. GUtil.createFormField(form, "backURL", "javascript:window.close();");
  485. GUtil.createFormField(form, "action_hint", "save");
  486. var sPath = this.m_cv.getWebContentRoot() + "/rv/blankSubscriptionWin.html?cv.id=" + this.m_cv.getId();
  487. window.open(sPath, form.target, this.m_windowOptions);
  488. }
  489. };
  490. /**
  491. Deletes an Annotation
  492. @param idx - index of the rule that was clicked on
  493. */
  494. CSubscriptionManager.prototype.DeleteAnnotation = function(idx)
  495. {
  496. var sub = this.m_annotations[idx];
  497. if (sub && sub.searchPath && confirm(RV_RES.RV_CONFIRM_DELETE_WATCH_RULE))
  498. {
  499. var oCV = this.getViewer();
  500. var request = new DataDispatcherEntry(oCV);
  501. request.setKey("subscriptionManager");
  502. request.addFormField("ui.action", "deleteAnnotation");
  503. request.addFormField("cv.responseFormat", "data");
  504. this.addCommonFormFields(request, sub.searchPath);
  505. oCV.dispatchRequest(request);
  506. }
  507. };
  508. /**
  509. Called when the user clicked on the 'Alert Using New Watch Rule' link
  510. */
  511. CSubscriptionManager.prototype.NewSubscription = function()
  512. {
  513. var sc = this.m_cv.getSelectionController();
  514. var oFWR = document.forms["formWarpRequest" + this.m_cv.getId()];
  515. var searchPath = oFWR.reRunObj.value;
  516. if (searchPath && sc && sc.getAllSelectedObjects().length === 1 )
  517. {
  518. var form = GUtil.createHiddenForm("subscriptionForm", "post", this.m_cv.getId(), CSubscriptionManager.k_SubscriptionWizardName);
  519. var fWR = document.getElementById("formWarpRequest" + this.m_cv.getId());
  520. var selectionXml = new CSelectionXml( fWR["ui.burstID"].value,
  521. fWR["ui.contentLocale"].value,
  522. fWR["ui.outputLocale"].value
  523. );
  524. selectionXml.BuildSelectionFromController(sc);
  525. //display a selectable-prompt containing the xml output -- TESTING ONLY
  526. //prompt("SelectionXML: ", selectionXml.toXml());
  527. GUtil.createFormField(form, "rv.selectionSpecXML", selectionXml.toXml());
  528. GUtil.createFormField(form, "rv.periodicalProducer", searchPath);
  529. GUtil.createFormField(form, "b_action", "xts.run");
  530. GUtil.createFormField(form, "m", "subscribe/conditional_subscribe1.xts");
  531. GUtil.createFormField(form, "backURL", "javascript:window.close();");
  532. var sPath = this.m_cv.getWebContentRoot() + "/rv/blankSubscriptionWin.html?cv.id=" + this.m_cv.getId();
  533. window.open(sPath, form.target, "toolbar,location,status,menubar,resizable,scrollbars=1");
  534. }
  535. else
  536. {
  537. // for debugging
  538. // alert("Invalid Context: sc: " + sc + "\n searchPath: " + searchPath);
  539. }
  540. };
  541. /**
  542. Deletes a watch rule
  543. @param idx - index of the rule that was clicked on
  544. */
  545. CSubscriptionManager.prototype.DeleteSubscription = function(idx)
  546. {
  547. var sub = this.m_aWatchRules[idx];
  548. if (sub && sub.searchPath && confirm(RV_RES.RV_CONFIRM_DELETE_WATCH_RULE))
  549. {
  550. var oCV = this.getViewer();
  551. var request = new DataDispatcherEntry(oCV);
  552. request.setKey("subscriptionManager");
  553. request.addFormField("ui.action", "deleteSubscription");
  554. request.addFormField("cv.responseFormat", "data");
  555. this.addCommonFormFields(request, sub.searchPath);
  556. oCV.dispatchRequest(request);
  557. }
  558. };
  559. /**
  560. User clicked the 'Modify...' link for a Watch Rule
  561. @param idx - index of the rule that was clicked on
  562. */
  563. CSubscriptionManager.prototype.ModifySubscription = function(idx)
  564. {
  565. var sub = this.m_aWatchRules[idx];
  566. if (sub && sub.searchPath)
  567. {
  568. var form = GUtil.createHiddenForm("subscriptionForm", "post", this.m_cv.getId(),
  569. CSubscriptionManager.k_SubscriptionWizardName);
  570. GUtil.createFormField(form, "m_obj", sub.searchPath);
  571. GUtil.createFormField(form, "m_name", sub.name);
  572. GUtil.createFormField(form, "b_action", "xts.run");
  573. GUtil.createFormField(form, "m_class", "reportDataServiceAgentDefinition");
  574. GUtil.createFormField(form, "m", "portal/properties_subscription.xts");
  575. GUtil.createFormField(form, "backURL", "javascript:window.close();");
  576. var sPath = this.m_cv.getWebContentRoot() + "/rv/blankSubscriptionWin.html?cv.id=" + this.m_cv.getId();
  577. window.open(sPath, form.target, "toolbar,location,status,menubar,resizable,scrollbars=1");
  578. }
  579. };
  580. /**
  581. Does an AJAX call to get the needed information, and then updated the
  582. drop down menu
  583. */
  584. CSubscriptionManager.prototype.OpenSubscriptionMenu = function()
  585. {
  586. var oCV = this.getViewer();
  587. var request = new JSONDispatcherEntry(oCV);
  588. request.setKey("subscriptionManager");
  589. request.addFormField("ui.action", "getSubscriptionInfo");
  590. request.addFormField("cv.responseFormat", "subscriptionManager");
  591. this.addCommonFormFields(request);
  592. request.setCallbacks({"complete":{"object":this, "method":this.OpenSubscriptionMenuResponse}});
  593. oCV.dispatchRequest(request);
  594. };
  595. /**
  596. Does an AJAX call to get the needed information, and then updated the
  597. drop down menu
  598. */
  599. CSubscriptionManager.prototype.OpenAnnotationMenu = function()
  600. {
  601. var oCV = this.getViewer();
  602. var request = new JSONDispatcherEntry(oCV);
  603. request.setKey("subscriptionManager");
  604. request.addFormField("ui.action", "getAnnotationInfo");
  605. request.addFormField("cv.responseFormat", "getAnnotations");
  606. var uiObject = oCV.envParams["ui.object"];
  607. this.addCommonFormFields(request, uiObject ? uiObject : "");
  608. request.setCallbacks({"complete":{"object":this, "method":this.OpenAnnotationMenuResponse}});
  609. oCV.dispatchRequest(request);
  610. };
  611. /**
  612. OpenSubscriptionMenuCallback will initialzie the CSubscriptionManager object and open the menu
  613. @param {httpRequest} the XML response from the viewer
  614. */
  615. CSubscriptionManager.prototype.OpenAnnotationMenuResponse = function(response)
  616. {
  617. if (this.Initialize(response)) {
  618. this.UpdateAnnotationMenu();
  619. }
  620. else {
  621. // something bad happened, just clear the menu
  622. this.ClearAnnotationMenu();
  623. }
  624. };
  625. /**
  626. OpenSubscriptionMenuCallback will initialzie the CSubscriptionManager object and open the menu
  627. @param {httpRequest} the XML response from the viewer
  628. */
  629. CSubscriptionManager.prototype.OpenSubscriptionMenuResponse = function(response)
  630. {
  631. if (this.Initialize(response))
  632. {
  633. this.UpdateSubscribeMenu();
  634. }
  635. else
  636. {
  637. // something bad happened, just clear the menu
  638. this.AddEmptySubscriptionMenuItem();
  639. }
  640. };
  641. CSubscriptionManager.prototype.addCommonFormFields = function(request, searchPath) {
  642. if (searchPath && searchPath != "") {
  643. request.addFormField("ui.object", searchPath);
  644. }
  645. else {
  646. var formWarpRequest = document["formWarpRequest" + this.getViewer().getId()];
  647. if (formWarpRequest && formWarpRequest["reRunObj"]) {
  648. request.addFormField("ui.object", formWarpRequest["reRunObj"].value);
  649. }
  650. }
  651. // if we're already initialized it'll cut down on the number of CM queries we need to do
  652. if (request.getFormField("ui.action") == "getSubscriptionInfo") {
  653. request.addFormField("initialized", this.m_bInitialized ? "true" : "false");
  654. }
  655. request.addFormField("cv.id", this.getViewer().getId());
  656. };
  657. /**
  658. * When there's nothing else to show in the Subscription menu, show
  659. * a disabled menu item
  660. */
  661. CSubscriptionManager.prototype.AddEmptySubscriptionMenuItem = function()
  662. {
  663. var toolbar = this.getStandaloneViewerToolbarControl();
  664. if (toolbar)
  665. {
  666. var subscribeButton = toolbar.getItem("watchNewVersions");
  667. if (subscribeButton)
  668. {
  669. subscribeButton.getMenu().clear();
  670. }
  671. var sWebContentRoot = this.m_cv.getWebContentRoot();
  672. var sSkin = this.m_cv.getSkin();
  673. var subscribeDropDownMenu = subscribeButton.getMenu();
  674. var noWatchRules = new CMenuItem(subscribeDropDownMenu, RV_RES.RV_NO_WATCH_RULES, "", '', gMenuItemStyle, sWebContentRoot, sSkin);
  675. noWatchRules.disable();
  676. // make sure we don't use the callback when drawing the menu
  677. subscribeDropDownMenu.setForceCallback(false);
  678. subscribeDropDownMenu.draw();
  679. if (subscribeDropDownMenu.isVisible()) {
  680. subscribeDropDownMenu.show();
  681. }
  682. // make sure our callback is used when the menu gets opened again
  683. subscribeDropDownMenu.setForceCallback(true);
  684. }
  685. };
  686. /**
  687. Removes all the menu items from the 'Watch New Versions' menu
  688. */
  689. CSubscriptionManager.prototype.ClearSubscriptionMenu = function()
  690. {
  691. var toolbar = this.getStandaloneViewerToolbarControl();
  692. if (toolbar)
  693. {
  694. var subscribeButton = toolbar.getItem("watchNewVersions");
  695. if (subscribeButton)
  696. {
  697. subscribeButton.getMenu().clear();
  698. }
  699. }
  700. };
  701. /**
  702. Removes all the menu items from the 'add Annotations' menu
  703. */
  704. CSubscriptionManager.prototype.ClearAnnotationMenu = function()
  705. {
  706. var toolbar = this.getStandaloneViewerToolbarControl();
  707. if (toolbar)
  708. {
  709. var annotationButton = toolbar.getItem("addAnnotations");
  710. if (annotationButton)
  711. {
  712. annotationButton.getMenu().clear();
  713. }
  714. }
  715. };
  716. /**
  717. Removes all the menu items from the 'add Annotations' menu
  718. */
  719. CSubscriptionManager.prototype.ClearContextAnnotationMenu = function()
  720. {
  721. var contextMenu = this.getStandaloneViewerContextMenu();
  722. if (contextMenu)
  723. {
  724. var commentFindAnnotationsMenu = contextMenu.getFindCommentMenuItem();
  725. if (commentFindAnnotationsMenu)
  726. {
  727. commentFindAnnotationsMenu.getMenu().clear();
  728. }
  729. }
  730. };
  731. CSubscriptionManager.prototype.getStandaloneViewerToolbarControl = function()
  732. {
  733. if(typeof this.m_cv.rvMainWnd != "undefined" && this.m_cv.rvMainWnd != null && typeof this.m_cv.rvMainWnd.getToolbarControl == "function")
  734. {
  735. return this.m_cv.rvMainWnd.getToolbarControl();
  736. }
  737. else
  738. {
  739. return null;
  740. }
  741. };
  742. CSubscriptionManager.prototype.getStandaloneViewerContextMenu = function()
  743. {
  744. if(typeof this.m_cv.rvMainWnd != "undefined" && this.m_cv.rvMainWnd != null && typeof this.m_cv.rvMainWnd.getContextMenu == "function")
  745. {
  746. return this.m_cv.rvMainWnd.getContextMenu();
  747. }
  748. else
  749. {
  750. return null;
  751. }
  752. };