").dxButton( {
text : "Add Selected Widget",
disabled : true,
onClick : function( e ) {
let selectedItems = instance.availableWidgetsList.option( "selectedItems" );
selectedItems.forEach( function( widgetData ) {
let widgetId = 0;
let added = false;
let widgetKey = null;
let userWidget = null;
while( ! added ) {
widgetKey = `${widgetData.portletId}:${widgetId}`;
let index = instance.userWidgetsData.findIndex((item) => item.widgetKey === widgetKey);
if( index >= 0 ) {
widgetId = widgetId -1;
} else {
userWidget = {
widgetKey : widgetKey,
widgetId : null,
portletId : widgetData.portletId,
initialPortletName : widgetData.initialPortletName,
portletName : widgetData.initialPortletName,
displayMode : widgetData.displayMode
}
let dataSource = instance.userWidgetsDataGrid.getDataSource();
dataSource.store().insert(userWidget).then(function() {
dataSource.reload().done( function( x ) {
instance.userWidgetsDataGrid.navigateToRow( userWidget.widgetKey );
});
})
added = true;
}
}
instance.availableWidgetsList.option( "selectedItems", [] );
})
}
}).dxButton("instance");
return instance.addWidgetButton;
}
DashboardPreferencesPopup.prototype.createUserWidgetsDataGrid = function () {
let instance = this;
instance.userWidgetsDataGrid = $("
").dxDataGrid( {
scrolling : { mode : "virtual" },
height : 312, // 350,
showBorders : true,
editing : {
allowUpdating : instance.shared ? false : true,
allowDeleting : instance.shared ? false : true,
mode : "batch",
useIcons : true
},
onToolbarPreparing : function( e ) {
let newItems = [];
if( e.toolbarOptions.items ) {
e.toolbarOptions.items.forEach( function( item ) {
if( item.name == "saveButton" || item.name == "revertButton" ) {
return;
}
newItems.push( item )
})
}
e.toolbarOptions.items = newItems;
//console.log( newItems );
},
keyExpr : "widgetKey",
sorting : {
mode : "none" // because we are using row dragging to put them in a specific order
},
rowDragging : {
allowReordering : instance.shared ? false : true,
onReorder : function(e) {
const visibleRows = e.component.getVisibleRows();
const toIndex = instance.userWidgetsData.findIndex((item) => item.widgetKey === visibleRows[e.toIndex].data.widgetKey);
const fromIndex = instance.userWidgetsData.findIndex((item) => item.widgetKey === e.itemData.widgetKey);
instance.userWidgetsData.splice(fromIndex, 1);
instance.userWidgetsData.splice(toIndex, 0, e.itemData);
e.component.refresh();
}
},
columns : [
{ dataField : "initialPortletName", caption : "Widget Type", allowEditing : false },
{ dataField : "portletName", caption : "Display Name", editorOptions : { maxLength : 50 } },
{ dataField : "displayMode", caption : "Size", width : 100,
calculateCellValue : function( rowData ) {
return rowData.displayMode ? rowData.displayMode : "?"
},
lookup : {
dataSource : {
store : {
type : "array",
data : [
{ text : "normal", value : "normal" },
{ text : "wide", value : "wide" },
{ text : "tall", value : "tall" },
{ text : "wide & tall", value : "wideAndTall" },
{ text : "1 Wide x 1 Tall", value : "1x1" },
{ text : "1 Wide x 2 Tall", value : "1x2" },
{ text : "1 Wide x 3 Tall", value : "1x3" },
{ text : "2 Wide x 1 Tall", value : "2x1" },
{ text : "2 Wide x 2 Tall", value : "2x2" },
{ text : "2 Wide x 3 Tall", value : "2x3" },
{ text : "3 Wide x 1 Tall", value : "3x1" },
{ text : "3 Wide x 2 Tall", value : "3x2" },
{ text : "3 Wide x 3 Tall", value : "3x3" },
{ text : "default", value : '?' }
],
key : "value"
}
},
displayExpr : "text",
valueExpr : "value",
allowClearing : false
}}
]
}).dxDataGrid( "instance" );
return instance.userWidgetsDataGrid;
}
DashboardPreferencesPopup.prototype.createDashboardForm = function() {
let instance = this;
instance.dashboardForm = $("
").dxForm( {
items : [
{ dataField : "dashboardName", label : { text : "View Name" }, editorOptions : { maxLength : 50 }, isRequired : true }
],
formData : {
dashboard : instance.userDashboard,
dashboardName : instance.userDashboardName
}
}).dxForm( "instance" );
return instance.dashboardForm;
}
DashboardPreferencesPopup.prototype.applyPreferences = function() {
let instance = this;
let dashboard = instance.dashboard;
let selectedPortlets = [];
let items = instance.userWidgetsDataGrid.getVisibleRows();
items.forEach( function( item ) {
if( item.removed ) return;
selectedPortlets.push( {
portletId : item.data.portletId,
widgetId : item.data.widgetId ? item.data.widgetId : 0,
portletName : item.data.portletName,
displayMode : item.data.displayMode
} );
})
let formData = instance.dashboardForm.option( "formData" );
let saveURL = $("link#PortalDocRootURL").attr("href") + "/apps/CRM/index.cfm?do=saveDashboardPreferences&mode=direct";
$.post( saveURL, $.param( { dashboard : formData.dashboard, dashboardName : formData.dashboardName, portlets : JSON.stringify(selectedPortlets) } ), function(saveResponse) {
if( ! instance.preferenceOptions.afterApply ) {
let userDashboardsDS = Fse.Data.newDataSource( { object : "STP.userDashboards", keyField : "dashboard", objectParams : { dashboard : dashboard.dashboardOptions.dashboard } } );
userDashboardsDS.load().done( function( userDashboards ) {
dashboard.userDashboards = userDashboards;
let selectOptions = {
dataSource : {
store : { type : "array", data : dashboard.userDashboards, key : "dashboard" }
},
value : saveResponse.dashboard
}
// dashboard.userDashboardAdded = true;
if( instance.preferenceOptions.newDashboard ) {
dashboard.loadDashboardOnChange = false;
}
dashboard.userDashboardSelectBox.option( selectOptions );
if( instance.preferenceOptions.newDashboard ) {
setTimeout( function() {
dashboard.loadDashboard().done( function() {
dashboard.loadDashboardOnChange = true;
});
}, 50 );
}
})
} else {
instance.preferenceOptions.afterApply( instance.preferenceOptions.newDashboard, saveResponse )
}
} );
}
DashboardPreferencesPopup.prototype.show = function() {
let instance = this;
let popupToolbarItems = [];
if( instance.allowDelete ) {
popupToolbarItems.push(
{ toolbar : "bottom", location : "after", widget : "dxButton",
options : {
text : "Delete View",
onClick : function( e ) {
if( confirm( "Delete this dashboard?" )) {
let saveURL = $("link#PortalDocRootURL").attr("href") + "/apps/CRM/index.cfm?do=deleteUserDashboard&mode=direct";
$.post( saveURL, $.param( { dashboard : instance.userDashboard } ), function() {
window.location.reload();
});
instance.popup.hide();
}
}
}
}
);
}
if( instance.shared ) {
popupToolbarItems.push(
{ toolbar : "bottom", location : "after", widget : "dxButton", options : { text : "Close", onClick : function( e ) {
instance.popup.hide();
} }}
);
} else {
popupToolbarItems.push(
{ toolbar : "bottom", location : "after", widget : "dxButton", options : { text : "Apply", type : "default", onClick : function( e ) {
let vr = instance.dashboardForm.validate();
if( ! vr.isValid ) {
return;
}
instance.popup.hide();
instance.applyPreferences();
} }}
);
}
instance.popup = $("
").dxPopup( {
visible : false,
title : instance.shared ? "Shared Dashboard View" : "Dashboard View Options",
width : instance.shared ? 545 : 825,
height : instance.shared ? "auto" : 620,
contentTemplate : function() {
if( instance.shared ) {
let content = $("
")
.append( instance.createUserWidgetsDataGrid().element() );
return content;
} else {
let availableWidgetsToolbar = $("
").dxToolbar( {
items : [
{ location : "after",
template : function() { return instance.createAddWidgetsButton().element() }
}
]
}).dxToolbar( "instance" );
let box = $("
").dxBox( {
width : 800,
items : [
{
ratio : 2,
template : function() {
let content = $("
")
.append( $("
").text( "Selected Widgets" ).css( { "font-size" : "16px", "margin-top" : "3px", "margin-bottom" : "4px" }))
.append( instance.createUserWidgetsDataGrid().element() );
return content;
}
},
{
ratio : 1,
template : function() {
return $("
")
.css( { "padding-left": "8px" })
.append( $("
").text( "Available Widgets" ).css( { "font-size" : "16px", "margin-top" : "3px", "margin-bottom" : "4px" }))
.append( instance.createAvailableWidgetsList().element().addClass( "dx-theme-border-color" ).css( { "border-width" : "1px", "border-style" : "solid" } ) )
.append( availableWidgetsToolbar.element().css( { "margin-top" : "5px" } ) )
}
}
]
}).dxBox( "instance" );
let contentElement = $("
")
.append( instance.createDashboardForm().element() )
.append( $("
").append( "Select the desired widgets on the right and click add, drag the icon at the left up and down to rearrange. Click the Display Name and Size of a widget to change values.") )
.append( box.element() )
.append( instance.createTeaserTextDisplay().element() );
return contentElement;
}
},
onHidden : function( e ) {
instance.popup = null;
e.component.dispose();
},
onShown : function( e ) {
instance.load();
},
toolbarItems : popupToolbarItems
}).dxPopup("instance");
$("body").append( instance.popup.element() );
instance.popup.show();
}