123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752 |
- function CognosViewerAnnotation() {
- this.m_oCV = null;
- }
- CognosViewerAnnotation.prototype.setCognosViewer = function(oCV) {
- this.m_oCV = oCV;
- };
- CognosViewerAnnotation.prototype.getCognosViewer = function() {
- return this.m_oCV;
- };
- CognosViewerAnnotation.prototype.isEnabled = function(placeType) {};
- CognosViewerAnnotation.prototype.areAnnotationsEnabled = function() {
- var widget = this.m_oCV.getViewerWidget();
- return widget.getAnnotationHelper().isEnabled();
- };
- CognosViewerAnnotation.prototype.getMenuItemBaseString = function(){
- };
- CognosViewerAnnotation.prototype.getMenuItemIconClass = function(){
- };
- CognosViewerAnnotation.prototype.getSelections = function(){
- var selections = [];
- var viewer = this.getCognosViewer();
- if (viewer) {
- var selCon = viewer.getSelectionController();
- if (selCon) {
- selections = selCon.getSelections();
- }
- }
- return selections;
- };
- CognosViewerAnnotation.prototype.hasAnnotation = function(){
- var has = false;
- var viewer = this.getCognosViewer();
- if (viewer) {
- var widget = viewer.getViewerWidget();
- if (widget) {
- var store = widget.getAnnotationStore();
- if (store) {
- has = store.hasAnnotation();
- }
- }
- }
- return has;
- };
- function CognosViewerCellAnnotation(){}
- CognosViewerCellAnnotation.prototype = new CognosViewerAnnotation();
- CognosViewerCellAnnotation.prototype.getMenuItemString = function(defaultText){
- var selText = defaultText;
- var selections = this.getSelections();
- if (selections && selections.length == 1) {
- var sel = selections[0];
- selText = sel.getDisplayValues()[0];
- }
- var text = this.getMenuItemBaseString();
- if (selText && selText.length > 0) {
- text += " - " + enforceTextDir(selText);
- }
- return text;
- };
- CognosViewerCellAnnotation.prototype.hasAnnotaionsOnSelectedCell = function(){
- var selections = this.getSelections();
- if (selections && selections.length == 1) {
- var cellRef = selections[0].getCellRef();
- var ctxId = this.getCognosViewer().findCtx(cellRef);
- var viewerWidget = this.getCognosViewer().getViewerWidget();
- if (viewerWidget) {
- var annotationStore = viewerWidget.getAnnotationStore();
- if (annotationStore) {
- var annotations = annotationStore.get(ctxId);
- if (annotations && annotations.length > 0) {
- return true;
- }
- }
- }
- }
- return false;
- };
- CognosViewerCellAnnotation.prototype.getChangeableAnnotation = function(){
- var selections = this.getSelections();
- if (selections && selections.length == 1) {
- var cellRef = selections[0].getCellRef();
- var ctxId = this.getCognosViewer().findCtx(cellRef);
- var viewerWidget = this.getCognosViewer().getViewerWidget();
- if (viewerWidget) {
- var annotationStore = viewerWidget.getAnnotationStore();
- if (annotationStore) {
- return annotationStore.getChangeableAnnotation(ctxId);
- }
- }
- }
- return null;
- };
- CognosViewerCellAnnotation.prototype.hasValidContextOnSelectedCell = function() {
- var selections = this.getSelections();
- if (selections && selections.length == 1) {
- var cellRef = selections[0].getCellRef();
- var ctxId = this.getCognosViewer().findCtx(cellRef);
- if (ctxId) {
- var ids = AnnotationCTXLookup.generateIDArrayFromCellCtxValue(ctxId);
- for (var i = 0; i < ids.length; i++) {
- var id = ids[i];
- if(id !== "*" && !(/^\d+$/).test(id)) {
- return false;
- }
- }
- return true;
- }
- }
- return false;
- };
- function NewAnnotation() {}
- NewAnnotation.prototype = new CognosViewerCellAnnotation();
- NewAnnotation.prototype.isEnabled = function(placeType) {
- return this.areAnnotationsEnabled() && (placeType!=='widgetActions') && this.hasValidContextOnSelectedCell();
- };
- NewAnnotation.prototype.getMenuItemBaseString = function(){
- return RV_RES.IDS_JS_ANNOTATION_NEW;
- };
- NewAnnotation.prototype.getMenuItemIconClass = function(){
- return 'NewAnnotation';
- };
- function EditAnnotation() {}
- EditAnnotation.prototype = new CognosViewerCellAnnotation();
- EditAnnotation.prototype.isEnabled = function(placeType) {
- return this.areAnnotationsEnabled() && (placeType!=='widgetActions') && this.getChangeableAnnotation() !== null;
- };
- EditAnnotation.prototype.getMenuItemBaseString = function(){
- return RV_RES.IDS_JS_ANNOTATION_EDIT;
- };
- EditAnnotation.prototype.getMenuItemIconClass = function(){
- return 'EditAnnotation';
- };
- function DeleteAnnotation() {}
- DeleteAnnotation.prototype = new CognosViewerCellAnnotation();
- DeleteAnnotation.prototype.isEnabled = function(placeType) {
- return this.areAnnotationsEnabled() && (placeType!=='widgetActions') && this.getChangeableAnnotation() !== null;
- };
- DeleteAnnotation.prototype.getMenuItemString = function(defaultText){
- return this.getMenuItemBaseString();
- };
- DeleteAnnotation.prototype.getMenuItemBaseString = function(){
- return RV_RES.IDS_JS_ANNOTATION_DELETE;
- };
- DeleteAnnotation.prototype.getMenuItemIconClass = function(){
- return 'DeleteAnnotation';
- };
- function CognosViewerWidgetAnnotation(){}
- CognosViewerWidgetAnnotation.prototype = new CognosViewerAnnotation();
- CognosViewerWidgetAnnotation.prototype.getMenuItemString = function(){
- var widgetText = this.getCognosViewer().getViewerWidget().getDisplayName();
- var text = this.getMenuItemBaseString();
- if (widgetText && widgetText.length > 0) {
- widgetText = enforceTextDir(widgetText);
- text += " - " + widgetText;
- }
- return text;
- };
- CognosViewerWidgetAnnotation.prototype.hasWidgetLevelAnnotations = function(){
- var hasAnnotations = false;
- var viewerWidget = this.getCognosViewer().getViewerWidget();
- if (viewerWidget) {
- var annotationStore = viewerWidget.getAnnotationStore();
- var widgetAnnotations = annotationStore.get(annotationStore.WIDGET_CONTEXT);
- if (widgetAnnotations && widgetAnnotations.length > 0) {
- hasAnnotations = true;
- }
- }
- return hasAnnotations;
- };
- CognosViewerWidgetAnnotation.prototype.getWidgetLevelChangeableAnnotation = function(){
- var viewerWidget = this.getCognosViewer().getViewerWidget();
- if (viewerWidget) {
- var annotationStore = viewerWidget.getAnnotationStore();
- if (annotationStore) {
- return annotationStore.getChangeableAnnotation(annotationStore.WIDGET_CONTEXT);
- }
- }
- return null;
- };
- CognosViewerWidgetAnnotation.prototype.hasValidSelection = function(placeType) {
- var selectionController = this.m_oCV.getSelectionController();
- var selections = selectionController.getSelections();
- var chartItemSelected = false;
- if(selectionController.hasSelectedChartNodes()) {
- chartItemSelected = (selectionController.getSelectedChartNodes()[0].m_contextIds.length > 0);
- }
- return (placeType==='widgetActions') || (selections.length != 1 && !chartItemSelected);
- };
- function NewWidgetAnnotation() {}
- NewWidgetAnnotation.prototype = new CognosViewerWidgetAnnotation();
- NewWidgetAnnotation.prototype.isEnabled = function(placeType) {
- return this.areAnnotationsEnabled() && (placeType!=='contextMenu') && this.hasValidSelection(placeType);
- };
- NewWidgetAnnotation.prototype.getMenuItemBaseString = function(){
- return RV_RES.IDS_JS_WIDGET_ANNOTATION_NEW;
- };
- NewWidgetAnnotation.prototype.getMenuItemIconClass = function(){
- return 'NewWidgetAnnotation';
- };
- function EditWidgetAnnotation() {}
- EditWidgetAnnotation.prototype = new CognosViewerWidgetAnnotation();
- EditWidgetAnnotation.prototype.isEnabled = function(placeType) {
- return (this.areAnnotationsEnabled() &&(placeType!=='contextMenu') && this.hasValidSelection(placeType) && this.getWidgetLevelChangeableAnnotation()) ? true : false;
- };
- EditWidgetAnnotation.prototype.getMenuItemBaseString = function(){
- return RV_RES.IDS_JS_WIDGET_ANNOTATION_EDIT;
- };
- EditWidgetAnnotation.prototype.getMenuItemIconClass = function(){
- return 'EditWidgetAnnotation';
- };
- function DeleteWidgetAnnotation() {}
- DeleteWidgetAnnotation.prototype = new CognosViewerWidgetAnnotation();
- DeleteWidgetAnnotation.prototype.isEnabled = function(placeType) {
- return (this.areAnnotationsEnabled() &&(placeType!=='contextMenu') && this.hasValidSelection(placeType) && this.getWidgetLevelChangeableAnnotation()) ? true : false;
- }
- DeleteWidgetAnnotation.prototype.getMenuItemBaseString = function(){
- return RV_RES.IDS_JS_WIDGET_ANNOTATION_DELETE;
- };
- DeleteWidgetAnnotation.prototype.getMenuItemIconClass = function(){
- return 'DeleteWidgetAnnotation';
- };
- function AnnotationCTXLookup(ccdManager) {
- this.m_ccdManager = ccdManager;
- this.m_md = this.m_ccdManager.m_md;
- this.m_cd = this.m_ccdManager.m_cd;
- this.m_RDIVALUE_KEY = 'annotationHook';
- this.m_oContextDetailsMap = {};
- }
- AnnotationCTXLookup.prototype.populateCtxDetailsForAllAnnotations = function(annotationArray) {
- for (var i = 0, len = annotationArray.length; i < len; i++) {
- var anno = annotationArray[i];
- var ctx = anno.ctx;
- if (ctx) {
- this._populateCtxDetailsForOneCtxValue(ctx);
- }
- }
- };
- AnnotationCTXLookup.prototype._populateCtxDetailsForOneCtxValue = function(ctxValue) {
- if(ctxValue) {
- var ctxIDs = this.generateIDArrayFromCellCtxValue(ctxValue);
- for (var i = 0, len = ctxIDs.length; i < len; i++) {
- var id = ctxIDs[i];
- this._populateCtxDetailsForOneId(id);
- }
- }
- };
- AnnotationCTXLookup.generateIDArrayFromCellCtxValue = function(ctxValue) {
- if (ctxValue) {
- return ctxValue.replace(/::/g, ':').split(':');
- }
- return null;
- };
- AnnotationCTXLookup.prototype.generateIDArrayFromCellCtxValue = AnnotationCTXLookup.generateIDArrayFromCellCtxValue;
- AnnotationCTXLookup.prototype._populateCtxDetailsForOneId = function(id) {
- if (id.match(/\*/)) {
- return;
- }
-
- var detail = this.m_oContextDetailsMap[id];
- if(detail) {
- return;
- } else {
- detail = {};
- var contextData = this.m_cd[id];
- if(contextData) {
- if (contextData.u) { detail['u'] = contextData.u; }
- if (contextData.r) {
- detail['r'] = contextData.r;
- var metadata = this.m_md[contextData.r];
- if(metadata) {
- if (metadata.usage!== 'undefined') {
- detail['usage'] = metadata.usage;
- }
-
- if (metadata.dtype) {
- detail.dtype = metadata.dtype;
- }
- }
- }
- this._populateRdiValueInDetail(detail, id);
- this.m_oContextDetailsMap[id] = detail;
- }
- }
- };
- AnnotationCTXLookup.prototype._getMDValue = function(item, key1, key2) {
- if(typeof key2 == 'undefined') {
-
- key2 = key1;
- }
- if (typeof item[key1] != 'undefined' && typeof this.m_md[item[key1]][key2] != 'undefined') {
- return this.m_md[item[key1]][key2];
- }
- return null;
- };
- AnnotationCTXLookup.prototype._findMDValue = function(item, aKeys) {
-
- for(var i = 0; i < aKeys.length; i++) {
- var value = this._getMDValue(item, aKeys[i]);
- if(value !== null) {
- return value;
- }
- }
- return null;
- };
- AnnotationCTXLookup.prototype._populateRdiValueInDetail = function(detail, id) {
- var item = this.m_cd[id];
- var aKeys = [];
- var oRdi = {};
-
- oRdi[1] = this._findMDValue(item, ["l", "h", "i", "r"]);
-
- if (this._getMDValue(item, "r", "usage") == 2) {
-
- oRdi[2] = this._findMDValue(item, ["i", "m", "r"]);
- }
- detail[this.m_RDIVALUE_KEY] = oRdi;
- };
- AnnotationCTXLookup.prototype.getDetail = function(id) {
- if (!id) {
- return null;
- }
- return this.m_oContextDetailsMap[id];
- };
- AnnotationCTXLookup.prototype.isAnnotatedId = function(annoFirstId, annotation, id) {
- if (!annoFirstId || !id) {
- return false;
- }
- if (annoFirstId.match(/\*/)) {
- var detail = this.getDetail(id);
- if (detail && detail[this.m_RDIVALUE_KEY]) {
- var rdi = detail[this.m_RDIVALUE_KEY][1];
- if(annotation.version >= 2 && detail[this.m_RDIVALUE_KEY][2]) {
-
-
-
- rdi = detail[this.m_RDIVALUE_KEY][2];
- }
- return this._compareWithoutNS(annotation.rdi, rdi);
- } else {
- return false;
- }
- } else {
- return annoFirstId === id;
- }
- };
- AnnotationCTXLookup.prototype._compareWithoutNS = function(rdi1, rdi2){
- if(!rdi1 || !rdi2){
- return false;
- }
- if(rdi1 !== rdi2){
- var iDotPos = rdi2.indexOf("].[");
- if(iDotPos > 0){
- return rdi1.lastIndexOf(rdi2.substr(iDotPos))>0;
- }
-
- return false;
- }
- return true;
- };
- AnnotationCTXLookup.prototype.isAnnotatedCell = function(annotation, cellCtxValue) {
- if (!annotation || !annotation.ctx || !cellCtxValue) {
- return false;
- }
- this._populateCtxDetailsForOneCtxValue(cellCtxValue);
- var annoIDArray = this.generateIDArrayFromCellCtxValue(annotation.ctx);
- var cellIDArray = this.generateIDArrayFromCellCtxValue(cellCtxValue);
-
- if( !this.isAnnotatedId(annoIDArray[0], annotation, cellIDArray[0]) ) {
- return false;
- }
-
- var annoDataItemIdArray = this._generateDataItemIDArrayFromAnnotationIDs(annoIDArray);
- var cellDataItemIdArray = this._generateDataItemIDArrayFromCellIDs(cellIDArray);
- if ( annoDataItemIdArray.length > cellDataItemIdArray.length) {
- return false;
- }
- for (var i=0, len=annoDataItemIdArray.length; i<len; i++) {
- for(var j=0, jLen=cellDataItemIdArray.length; j<jLen; j++) {
- if (annoDataItemIdArray[i] === cellDataItemIdArray[j] ) {
- annoDataItemIdArray[i] = true;
- cellDataItemIdArray[j] = true;
- break;
- }
- }
- }
- for (i = 0, len = annoDataItemIdArray.length; i < len; i++) {
- if (annoDataItemIdArray[i] !== true) {
- return false;
- }
- }
- for (i = 0, len = cellDataItemIdArray.length; i < len; i++) {
- if (cellDataItemIdArray[i] !== true) {
- return false;
- }
- }
- return true;
- };
- AnnotationCTXLookup.prototype._generateDataItemIDArrayFromCellIDs = function(cellIDArray) {
- var dataItemIDs = [];
- for(var i=1, len=cellIDArray.length; i<len; i++){
- var id = cellIDArray[i];
- var detail = this.getDetail(id);
- if( this._isDataItem(detail) ) {
- dataItemIDs.splice(0,0, id);
- }
- }
- return dataItemIDs;
- };
- AnnotationCTXLookup.dtypeLookup = {"1" : true,"25" : true,"26" : true,"27" : true,"28" : true,"29" : true,"30" : true,"31" : true,"32" : true,"34" : true,"35" : true,"36" : true,"43" : true,"45" : true,"55" : true,"56" : true};
- AnnotationCTXLookup.prototype._isDataItem = function(detail) {
- if (detail) {
- var usage = detail.usage;
- var dtype = detail.dtype;
- if (usage === 0 || usage === 1 || (usage === 3 && AnnotationCTXLookup.dtypeLookup[dtype] === true)) {
- return true;
- }
- }
- return false;
- };
- AnnotationCTXLookup.prototype._generateDataItemIDArrayFromAnnotationIDs = function(annoIDArray) {
- var dataItemIDs = [];
- for(var i=1, len=annoIDArray.length; i<len; i++){
- var id = annoIDArray[i];
- if (id.match(/\*/) === null) {
- dataItemIDs.splice(0,0, id);
- }
- }
- return dataItemIDs;
- };
|