impersonateTenant.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Licensed Materials - Property of IBM
  2. //
  3. // IBM Cognos Products: ps
  4. //
  5. // (C) Copyright IBM Corp. 2013
  6. //
  7. // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8. function impersonateTenantSelector(context) {
  9. var _self = this;
  10. this.context = context;
  11. dojo.require("dijit.form.FilteringSelect");
  12. dojo.require("dojo.data.ItemFileReadStore");
  13. var id = 'impersonatedTenant';
  14. var showTenantContentOnlyChkBoxId = 'showTenantContentOnly';
  15. var ids = [id,showTenantContentOnlyChkBoxId];
  16. dijit.registry.forEach(function(w){
  17. if(dojo.indexOf(ids,w.id) >= 0){
  18. w.destroyRecursive(true);
  19. }
  20. });
  21. // create store instance referencing data from listTenants.xts
  22. var tenantStore = new dojo.data.ItemFileReadStore({
  23. url: '?b_action=xts.run&m=portal/tenants/listTenants.xts&src=listTenants&isImpersonate=true'
  24. });
  25. _self.filteringSelect = new dijit.form.FilteringSelect({
  26. name: id,
  27. value: (_self.context.writeAs == "") ? " " : _self.context.writeAs, //filteringSelect doesn't behave well with empty value
  28. store: tenantStore,
  29. maxHeight: -1,
  30. searchAttr: "name",
  31. pageSize: this.context.listSize,
  32. onChange: function(state){
  33. _self.context.onChange(dojo.byId(showTenantContentOnlyChkBoxId).checked ? 'read' : 'write', dojo.trim(new String(this.item.id)));
  34. }
  35. }, id);
  36. dojo.require("dijit.form.CheckBox");
  37. var checkBox = new dijit.form.CheckBox({
  38. name: "showTenantContentOnly",
  39. checked: context.readAs != null
  40. }, "showTenantContentOnly");
  41. dojo.connect(dijit.byId("showTenantContentOnly"), "onChange",
  42. function(isChecked) {
  43. doImpersonateTenant(isChecked ? 'read' : 'write', dojo.trim(new String(_self.filteringSelect.item.id)));
  44. }
  45. );
  46. _self.filteringSelect.startup();
  47. }
  48. function impersonateTenant(fragment, table_name) {
  49. var checkboxes = getCheckboxCheckParams(table_name);
  50. impersonateTenantImpl(fragment, '','cancel');
  51. }
  52. function impersonateTenantImpl(fragment, checkboxes, cmdType) {
  53. var params = checkboxes;
  54. params += '&ifrmcmd=impersonateTenant&cmdType=';
  55. params += cmdType;
  56. fragment.retrieve(encodeURI(params));
  57. }
  58. function createFragment(fragID, divID, xtsTargetURL) {
  59. var frag = new fragment("/xts"+encodeURI(xtsTargetURL), fragID, divID);
  60. if (frag.parent && !document.getElementById(divID)) {
  61. var div = document.createElement('div');
  62. div.id = divID;
  63. document.getElementById(frag.parent.div).appendChild(div);
  64. }
  65. return frag;
  66. }