Name
global.VizDesignerUtil
Description
No description available
Script
var VizDesignerUtil = Class.create();
VizDesignerUtil.prototype = {
initialize: function() {
},
_removeVizFromUserPreference: function(gr, vizId) {
var preference = gr.getValue('value');
if (!preference)
return;
var favorites = JSON.parse(preference);
if (!Array.isArray(favorites))
return;
var idx = favorites.indexOf(vizId);
if (idx < 0)
return;
favorites.splice(idx, 1);
gr.setValue('value', JSON.stringify(favorites));
gr.update();
},
_getTitlePropertyName: function(macroponentId) {
// List
if (macroponentId == '2b1c080881e05dc63b917044290b233f')
return 'listTitle';
// Scorecard
if (macroponentId == '9d31ba4d773ce32ef350d4555b673f6e')
return 'heading';
// Calendar
if (macroponentId == '259e0221ff18a75c5f5f0fb28fa5d32f')
return 'componentTitle';
},
_canViewViz: function(vizId) {
var grs = new GlideRecordSecure('par_visualization');
return grs.get(vizId);
},
_getUserRoleSysIds: function(roles) {
var roleSysIds = [];
var gr = new GlideRecord('sys_user_role');
gr.addQuery('name', 'IN', roles);
gr.query();
while (gr.next())
roleSysIds.push(gr.getUniqueValue());
return roleSysIds;
},
_getSharingQCOnUserRoleGroup: function() {
var gr = new GlideRecord('par_visualization_permission');
var qc = gr.addQuery('user', gs.getUserID());
qc.addOrCondition('group', 'IN', gs.getUser().getMyGroups());
qc.addOrCondition('role', 'IN', this._getUserRoleSysIds(gs.getUser().getRoles()));
return qc;
},
removeVizFromUserPreferences: function(vizId) {
var gr = new GlideRecord('sys_user_preference');
gr.addQuery('name', 'viz-designer-favorites');
gr.query();
while (gr.next())
this._removeVizFromUserPreference(gr, vizId);
},
getTitleFromProperties: function(macroponentId, stringifiedProperties) {
var properties = JSON.parse(stringifiedProperties);
var titlePropertyName = this._getTitlePropertyName(macroponentId);
if (titlePropertyName)
return properties[titlePropertyName];
},
getNameFromProperties: function(macroponentId, stringifiedProperties) {
var title = this.getTitleFromProperties(macroponentId, stringifiedProperties);
if (title)
return title;
return 'Untitled';
},
ownViz: function(vizId) {
var gr = new GlideRecord('par_visualization_permission');
gr.addQuery('component', vizId);
gr.addQuery('user', gs.getUserID());
gr.addQuery('owner', true);
gr.query();
return gr.hasNext();
},
canShareViz: function(vizId) {
if (!this._canViewViz(vizId))
return false;
if (this.ownViz(vizId))
return true;
var gr = new GlideRecord('par_visualization_permission');
gr.addQuery('component', vizId);
var qc = gr.addQuery('can_share', true);
qc.addCondition(this._getSharingQCOnUserRoleGroup());
gr.setLimit(1);
gr.query();
return gr.hasNext();
},
isVizSharedWithMeOrIamOwner: function(vizId) {
var gr = new GlideRecord('par_visualization_permission');
var qc = gr.addQuery('component', vizId);
qc.addCondition(this._getSharingQCOnUserRoleGroup());
gr.setLimit(1);
gr.query();
return gr.hasNext();
},
isVizSharedWithMeWithEditModeOrIamOwner: function(vizId) {
var gr = new GlideRecord('par_visualization_permission');
gr.addQuery('component', vizId);
var qc = gr.addQuery('write', true);
qc.addCondition(this._getSharingQCOnUserRoleGroup());
gr.setLimit(1);
gr.query();
return gr.hasNext();
},
type: 'VizDesignerUtil'
};
Sys ID
55bdc042c3a10110d938e4788940dd7d