SelectBusinessProcess.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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. dojo.provide("viewer.dialogs.SelectBusinessProcess");
  13. dojo.require("bux.dialogs.BaseCustomContentDialog");
  14. dojo.require("bux.layout.TableContainer");
  15. dojo.require("dijit.form.NumberTextBox");
  16. dojo.require("dijit.form.Button");
  17. dojo.declare( 'viewer.dialogs.SelectBusinessProcess', bux.dialogs.BaseCustomContentDialog, {
  18. sTitle : null,
  19. sLabel : null,
  20. okHandler : null, /* function */
  21. cancelHanlder : null, /* function */
  22. buildRendering : function() {
  23. this.aButtonsSpec = [
  24. {label: RV_RES.IDS_JS_BUSINESS_PROCESS_SELECT_DIALOG_START_BUTTON_LABEL, action: dojo.hitch(this, this.onOK), type: "button"},
  25. {label: RV_RES.CANCEL, action: dojo.hitch(this, this.onCancel), type: "button"}
  26. ];
  27. this.inherited( arguments );
  28. if( !this.BPMProcessesInfo || this.BPMProcessesInfo.length === 0 ){
  29. //Disable the start button
  30. this._buxBaseDialog._aButtonObjects[0].set( 'disabled',true );
  31. }
  32. },
  33. startup : function() {
  34. this.updateTitle( this.sTitle );
  35. this.inherited( arguments );
  36. this.set( 'role', 'group');
  37. var tableContainer = new bux.layout.TableContainer({
  38. classname: "bux-InformationDialog buxFilterConfigDiscreteValuesTable"},
  39. this.contentContainer );
  40. var row = new bux.layout.TableContainerRow({
  41. classname : "bux-dialog-label",
  42. parentContainer : tableContainer
  43. });
  44. var cell = new bux.layout.TableContainerCell({
  45. parentContainer : row
  46. });
  47. this.generateSelectProcessSection( cell );
  48. cell.addContent( document.createElement( 'br' ) );
  49. this.generateViewInputValuesSection( cell );
  50. cell.addContent( document.createElement( 'br' ) );
  51. },
  52. addDivContainer : function( oParentContainer, sID, sRole ) {
  53. var div = document.createElement( 'div');
  54. dojo.attr( div, { 'class' : 'buxFilterConfigFilterValue',
  55. 'aria-labelledby' : sID,
  56. role : sRole
  57. });
  58. oParentContainer.addContent( div );
  59. return div;
  60. },
  61. generateSelectProcessSection : function( oParentContainer ) {
  62. var sA11yId = this.id + '_selectProcess_a11ylabel';
  63. this.addTableDescription(oParentContainer, this.sLabel, sA11yId);
  64. var div = this.addDivContainer( oParentContainer, sA11yId, 'radiogroup' );
  65. var tableContainer = new bux.layout.TableContainer({
  66. classname: 'buxFilterConfigFilterValueTable'
  67. } );
  68. dojo.style( tableContainer.domNode, 'width', '325px' );
  69. this.addSelectProcessTableHeader( tableContainer );
  70. if( !this.BPMProcessesInfo || this.BPMProcessesInfo.length === 0) {
  71. this.addEmptySelectProcessTableContent( tableContainer );
  72. }else{
  73. this.addSelectProcessTableContent(tableContainer);
  74. }
  75. div.appendChild( tableContainer.domNode );
  76. },
  77. addSelectProcessTableHeader : function( tableContainer ) {
  78. var table_header_row = new bux.layout.TableContainerRow({
  79. classname : "buxFilterConfigFilterValueTableHeaderRow",
  80. parentContainer : tableContainer
  81. });
  82. var table_header_cell_1 = new bux.layout.TableContainerCell({
  83. classname : "buxListHeader buxFilterConfigFilterValueTableHeaderLeft",
  84. width : '25px',
  85. parentContainer : table_header_row
  86. });
  87. var table_header_cell_2 = new bux.layout.TableContainerCell({
  88. classname : "buxListHeader buxFilterConfigFilterValueTableHeader",
  89. width : '300px',
  90. parentContainer : table_header_row
  91. });
  92. table_header_cell_2.addContent(document.createTextNode(RV_RES.IDS_JS_BUSINESS_PROCESS_SELECT_DIALOG_TABLE_HEADER));
  93. },
  94. /**
  95. * Displays "None" in the table when no process is available to user
  96. */
  97. addEmptySelectProcessTableContent: function( tableContainer ) {
  98. var sA11yLabelId = this.id + '_processItemsRow_label_none';
  99. var row_process = new bux.layout.TableContainerRow({
  100. parentContainer : tableContainer
  101. });
  102. dojo.attr( row_process.domNode, { id : this.id + '_processItemsRow_none',
  103. 'aria-labelledby' : sA11yLabelId,
  104. tabindex : 0
  105. });
  106. var a11yLabel = this.createA11yLabel(RV_RES.IDS_JS_BUSINESS_PROCESS_SELECT_DIALOG_NO_PROCESS_A11Y, sA11yLabelId, true /*hidden*/);
  107. row_process.domNode.appendChild( a11yLabel );
  108. var cell = new bux.layout.TableContainerCell({
  109. parentContainer : row_process
  110. });
  111. cell.set( 'colspan', 2 );
  112. cell.addContent( this.createLabelElement( RV_RES.IDS_JS_BUSINESS_PROCESS_SELECT_DIALOG_NO_PROCESS) );
  113. },
  114. addSelectProcessTableContent : function( tableContainer ) {
  115. for( var i=0 ; i < this.BPMProcessesInfo.length; i++) {
  116. var radioButtonObj = new dijit.form.RadioButton({
  117. checked: (( i === 0 ) ? true : false),// check the first item by default
  118. name : this.id + '_processItem',
  119. disabled: false
  120. });
  121. var sCaption = html_encode( this.BPMProcessesInfo[i].sCaption );
  122. var sBPD_ID = this.BPMProcessesInfo[i].sBPD_ID;
  123. var sProcessAppID = this.BPMProcessesInfo[i].sProcessAppID;
  124. radioButtonObj.onChange = dojo.hitch( this, 'getProcessItemRadioChangeFunction', sBPD_ID, sProcessAppID, sCaption, radioButtonObj );
  125. var row_process = new bux.layout.TableContainerRow({
  126. parentContainer : tableContainer,
  127. classname : ((i === 0 ) ? 'buxFilterConfigFilterValueRowSelected' : '')
  128. });
  129. row_process.set( 'id', this.id + '_processItemsRow' + radioButtonObj.id );
  130. var cell_radio = new bux.layout.TableContainerCell({
  131. align : 'center',
  132. parentContainer : row_process
  133. });
  134. cell_radio.addContent( radioButtonObj.domNode );
  135. cell_radio.set( 'id', this.id + '_processItemsCell' + i );
  136. var cell_process = new bux.layout.TableContainerCell({
  137. classname : 'buxFilterConfigFilterItemName text_overflow_ellipsis_ie',
  138. width : '300px',
  139. valign : 'top',
  140. parentContainer : row_process
  141. });
  142. var _label = document.createElement("label");
  143. _label.appendChild(document.createTextNode( sCaption ));
  144. _label.setAttribute("for", radioButtonObj.id);
  145. cell_process.addContent(_label);
  146. }
  147. this.setDefaultProcessSelectedInfo();
  148. },
  149. setDefaultProcessSelectedInfo : function(){
  150. this._selectedBPD_ID = this.BPMProcessesInfo[0].sBPD_ID;
  151. this._selectedProcessAppId = this.BPMProcessesInfo[0].sProcessAppID;
  152. this._selectedProcessName = html_encode( this.BPMProcessesInfo[0].sCaption );
  153. },
  154. getProcessItemRadioChangeFunction : function( sBPD_ID, sProcessAppId, sProcessName, radio) {
  155. if( radio.get( 'value') === 'on') {
  156. dojo.byId(this.id + '_processItemsRow' + radio.id).className = 'buxFilterConfigFilterValueRowSelected';
  157. this._selectedBPD_ID = sBPD_ID;
  158. this._selectedProcessAppId = sProcessAppId;
  159. this._selectedProcessName = sProcessName;
  160. } else {
  161. dojo.byId(this.id + '_processItemsRow' + radio.id).className = '';
  162. }
  163. },
  164. generateViewInputValuesSection : function( oParentContainer ) {
  165. var sContainerAllyId = this.id + '_viewInputValues_a11ylabel';
  166. this.addTableDescription( oParentContainer, RV_RES.IDS_JS_BUSINESS_PROCESS_VIEW_INPUT_VALUES_TABLE_DESCRIPTION, sContainerAllyId);
  167. this.addViewInputValuesTable( oParentContainer, sContainerAllyId );
  168. },
  169. addViewInputValuesTable : function( oParentContainer, sContainerAllyId ) {
  170. oParentContainer.addContent( this.generateViewInputValuesTable( sContainerAllyId) );
  171. },
  172. addTableDescription : function( oParentContainer, sDescription, sID ) {
  173. var div = document.createElement( 'div');
  174. dojo.attr( div, { 'class' : 'bux-label',
  175. id : sID
  176. });
  177. div.appendChild( document.createTextNode(html_encode( sDescription ) ) );
  178. oParentContainer.addContent( div );
  179. },
  180. /**
  181. * Returns div that contains the table
  182. */
  183. generateViewInputValuesTable : function(sContainerAllyId) {
  184. var oInputParameters = this.bpAction.getInputParameter();
  185. var div = document.createElement( 'div');
  186. dojo.attr(div, { 'class' : 'buxFilterConfigFilterValue',
  187. style : 'height:80px',
  188. role : 'group',
  189. 'aria-labelledby': sContainerAllyId
  190. });
  191. var tableContainer = new bux.layout.TableContainer({
  192. classname: 'buxFilterConfigFilterValueTable'
  193. } );
  194. dojo.style( tableContainer.domNode, 'width', '335px' );
  195. tableContainer.set( 'role', 'list');
  196. div.appendChild( tableContainer.domNode );
  197. var table_header_row = new bux.layout.TableContainerRow({
  198. classname : "buxFilterConfigFilterValueTableHeaderRow",
  199. parentContainer : tableContainer
  200. });
  201. var table_header_cell_1 = new bux.layout.TableContainerCell({
  202. classname : "buxListHeader buxFilterConfigFilterValueTableHeaderLeft",
  203. width : '40%',
  204. parentContainer : table_header_row
  205. });
  206. table_header_cell_1.addContent(document.createTextNode(RV_RES.IDS_JS_BUSINESS_PROCESS_VIEW_INPUT_VALUES_TABLE_COLUMN_HEADER_DATA_ITEM));
  207. var table_header_cell_2 = new bux.layout.TableContainerCell({
  208. classname : "buxListHeader buxFilterConfigFilterValueTableHeader",
  209. width : '60%',
  210. parentContainer : table_header_row
  211. });
  212. table_header_cell_2.addContent(document.createTextNode(RV_RES.IDS_JS_BUSINESS_PROCESS_VIEW_INPUT_VALUES_TABLE_COLUMN_HEADER_DISPLAY_VALUE_HEADER));
  213. var cognosParm = oInputParameters.cognosParameter;
  214. var bAlreadySetDefaultFocus = false;
  215. for( var i=0 ; i < cognosParm.length; i++) {
  216. var rowIndex = 0;
  217. var widgetContextValues = this.getWidgetContextValues(cognosParm[i]);
  218. for( var dataItem in widgetContextValues ) {
  219. var row = new bux.layout.TableContainerRow({
  220. parentContainer : tableContainer
  221. });
  222. var rowAttributes = { id : this.id + '_inputValueRow_' + rowIndex,
  223. role : 'listitem' };
  224. //set focus on first row only
  225. if( !bAlreadySetDefaultFocus ){
  226. rowAttributes.tabindex = 0;
  227. bAlreadySetDefaultFocus = true;
  228. }
  229. dojo.attr( row.domNode, rowAttributes);
  230. this.addRowAccessibility(row, rowIndex, dataItem, widgetContextValues[dataItem]);
  231. //data item
  232. var dataItemCell = new bux.layout.TableContainerCell({
  233. classname : 'buxFilterConfigFilterItemName text_overflow_ellipsis_ie',
  234. width : '40%',
  235. valign : 'top',
  236. parentContainer : row
  237. });
  238. dataItemCell.set( 'id', this.id + '_dataItem_' + i );
  239. dataItemCell.addContent( this.createLabelElement( dataItem ) );
  240. //display value
  241. var displayValueCell = new bux.layout.TableContainerCell({
  242. classname : 'buxFilterConfigFilterItemName text_overflow_ellipsis_ie',
  243. width : '60%',
  244. valign : 'top',
  245. parentContainer : row
  246. });
  247. displayValueCell.set( 'id', this.id + '_displayValue_' + i );
  248. displayValueCell.addContent( this.createLabelElement( widgetContextValues[dataItem][0] ) );
  249. rowIndex++;
  250. }
  251. }
  252. return div;
  253. },
  254. getWidgetContextValues : function( widgetContext ){
  255. return values = widgetContext['com.ibm.widget.context'].values;
  256. },
  257. addRowAccessibility : function( row, rowIndex, sDataItem, sDataValue ) {
  258. // add aria-labelledby label
  259. var sA11yLabelId = this.id + '_inputValueRow_label_' + rowIndex;
  260. dojo.attr( row.domNode, { 'aria-labelledby' : sA11yLabelId } );
  261. var sA11yLabel = RV_RES.IDS_JS_BUSINESS_PROCESS_VIEW_INPUT_VALUES_TABLE_COLUMN_HEADER_DATA_ITEM + ' ' + sDataItem + ' ' +
  262. RV_RES.IDS_JS_BUSINESS_PROCESS_START_PROCESS_A11Y_DESC_VALUE + ' ' + sDataValue;
  263. row.domNode.appendChild( this.createA11yLabel( sA11yLabel, sA11yLabelId, true /*hidden*/ ) );
  264. //add keyboard navigation
  265. dojo.connect( row.domNode, "onkeypress", dojo.hitch( this, this._rowOnKeyPress));
  266. },
  267. _rowOnKeyPress : function( evt ) {
  268. switch( evt.keyCode ) {
  269. case dojo.keys.DOWN_ARROW :
  270. this.changeNodeFocus( evt, evt.target, evt.target.nextSibling );
  271. break;
  272. case dojo.keys.UP_ARROW :
  273. this.changeNodeFocus( evt, evt.target, evt.target.previousSibling );
  274. break;
  275. }
  276. },
  277. changeNodeFocus : function( evt, currentNode, targetNode) {
  278. if( !targetNode || ( targetNode && targetNode.id && targetNode.id.indexOf( '_inputValueRow_' ) === -1 ) ){
  279. return;
  280. }
  281. dojo.attr( currentNode, {tabindex : -1 } );
  282. dojo.attr( targetNode, { tabindex : 0 } );
  283. dijit.focus( targetNode );
  284. if (dojo.isIE || dojo.isTrident) {
  285. evt.keyCode = 0;
  286. }
  287. dojo.stopEvent(evt);
  288. },
  289. createA11yLabel : function( sLabelText, sLabelId, hidden ) {
  290. var _eSpan = this.createLabelElement( sLabelText );
  291. var attribs = { id :sLabelId };
  292. if( hidden ){attribs.style = 'visibility:hidden;display:none';}
  293. dojo.attr( _eSpan, attribs);
  294. return _eSpan;
  295. },
  296. createLabelElement : function( sLabelText ) {
  297. var _eSpan = document.createElement("span");
  298. _eSpan.appendChild(document.createTextNode( html_encode( sLabelText ) ));
  299. return _eSpan;
  300. },
  301. onOK : function() {
  302. this.hide();
  303. this.bpAction.startProcess( this._selectedBPD_ID, this._selectedProcessAppId, this._selectedProcessName );
  304. }
  305. });