BUG 10084 I added a functionality to save order the dashlet SOLVED
I added a functionality to save order the dashlet
This commit is contained in:
@@ -26,7 +26,73 @@ class Dashboard extends Controller
|
||||
public function index ($httpData)
|
||||
{
|
||||
try {
|
||||
$this->setJSVar( 'dashletsInstances', $this->getDashletsInstancesForCurrentUser() );
|
||||
$dashletsExist = $this->getDashletsInstancesForCurrentUser();
|
||||
$dashletsHide = array();
|
||||
$dashletColumns = 3;
|
||||
|
||||
G::LoadClass( 'configuration' );
|
||||
$oConfiguration = new Configurations();
|
||||
$aConfiguration = $oConfiguration->load('Dashboard', '', '', $_SESSION['USER_LOGGED']);
|
||||
if (is_array($aConfiguration) && count($aConfiguration) != 0) {
|
||||
if (isset($aConfiguration["COLUMNS"])) {
|
||||
$dashletColumns = $aConfiguration["COLUMNS"];
|
||||
}
|
||||
|
||||
if (isset($aConfiguration["ORDER"])) {
|
||||
|
||||
$listDashletAux = array();
|
||||
$listDashletAuxShow = array();
|
||||
foreach ($dashletsExist as $key => $value) {
|
||||
$listDashletAux[$value['DAS_INS_UID']] = $key;
|
||||
}
|
||||
|
||||
$dashletsShow['0'] = array();
|
||||
foreach ($aConfiguration['ORDER']['0'] as $value) {
|
||||
if (isset($listDashletAux[$value])) {
|
||||
$listDashletAuxShow[] = $value;
|
||||
$dashletsShow['0'][] = $dashletsExist[$listDashletAux[$value]];
|
||||
}
|
||||
}
|
||||
|
||||
$dashletsShow['1'] = array();
|
||||
foreach ($aConfiguration['ORDER']['1'] as $value) {
|
||||
if (isset($listDashletAux[$value])) {
|
||||
$listDashletAuxShow[] = $value;
|
||||
$dashletsShow['1'][] = $dashletsExist[$listDashletAux[$value]];
|
||||
}
|
||||
}
|
||||
|
||||
$dashletsShow['2'] = array();
|
||||
foreach ($aConfiguration['ORDER']['2'] as $value) {
|
||||
if (isset($listDashletAux[$value])) {
|
||||
$listDashletAuxShow[] = $value;
|
||||
$dashletsShow['2'][] = $dashletsExist[$listDashletAux[$value]];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$col = 0;
|
||||
foreach ($dashletsExist as $value) {
|
||||
$dashletsShow[$col][] = $value;
|
||||
$col++;
|
||||
if ($col == 3) {
|
||||
$col = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$col = 0;
|
||||
foreach ($dashletsExist as $value) {
|
||||
$dashletsShow[$col][] = $value;
|
||||
$col++;
|
||||
if ($col == 3) {
|
||||
$col = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->setJSVar( 'dashletsAll', $dashletsExist);
|
||||
$this->setJSVar( 'dashletsInstances', $dashletsShow);
|
||||
$this->setJSVar( 'dashletsColumns', $dashletColumns);
|
||||
$this->includeExtJS( 'dashboard/index' );
|
||||
$this->includeExtJSLib( 'ux/portal' );
|
||||
G::RenderPage( 'publish', 'extJs' );
|
||||
@@ -35,6 +101,39 @@ class Dashboard extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
public function saveOrderDashlet ($data)
|
||||
{
|
||||
$this->setResponseType( 'json' );
|
||||
try {
|
||||
$orderDashlet[0] = json_decode($data->postionCol0);
|
||||
$orderDashlet[1] = json_decode($data->postionCol1);
|
||||
$orderDashlet[2] = json_decode($data->postionCol2);
|
||||
|
||||
G::loadClass('configuration');
|
||||
$oConfiguration = new Configurations();
|
||||
$aConfiguration = $oConfiguration->load('Dashboard', '', '', $_SESSION['USER_LOGGED']);
|
||||
$dataDashboard = array();
|
||||
if (isset($aConfiguration["CFG_VALUE"])) {
|
||||
$dataDashboard = $aConfiguration["CFG_VALUE"];
|
||||
}
|
||||
$dataNow['ORDER'] = $orderDashlet;
|
||||
|
||||
if (isset($data->columns)) {
|
||||
$dataNow['COLUMNS'] = json_decode($data->columns);
|
||||
}
|
||||
|
||||
$dataDashboard = array_merge($dataDashboard, $dataNow);
|
||||
|
||||
$oConfiguration->aConfig = $dataDashboard;
|
||||
$oConfiguration->saveConfig('Dashboard', '', '', $_SESSION['USER_LOGGED']);
|
||||
|
||||
$result->success = '1';
|
||||
return $result;
|
||||
} catch (Exception $error) {
|
||||
//ToDo: Display a error message
|
||||
}
|
||||
}
|
||||
|
||||
public function renderDashletInstance ($data)
|
||||
{
|
||||
try {
|
||||
|
||||
@@ -1,3 +1,22 @@
|
||||
function generatedOrder () {
|
||||
var orderNow = new Array();
|
||||
orderNow[0] = new Array();
|
||||
orderNow[1] = new Array();
|
||||
orderNow[2] = new Array();
|
||||
|
||||
for (var i = 0; i < Ext.getCmp('columnPos0').items.items.length; i++) {
|
||||
orderNow[0][i] = Ext.getCmp('columnPos0').items.items[i].dasInsUid;
|
||||
}
|
||||
for (var i = 0; i < Ext.getCmp('columnPos1').items.items.length; i++) {
|
||||
orderNow[1][i] = Ext.getCmp('columnPos1').items.items[i].dasInsUid;
|
||||
}
|
||||
for (var i = 0; i < Ext.getCmp('columnPos2').items.items.length; i++) {
|
||||
orderNow[2][i] = Ext.getCmp('columnPos2').items.items[i].dasInsUid;
|
||||
}
|
||||
|
||||
return orderNow;
|
||||
}
|
||||
|
||||
Ext.onReady(function(){
|
||||
|
||||
Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
|
||||
@@ -22,13 +41,18 @@ Ext.onReady(function(){
|
||||
xtype: 'tbbutton',
|
||||
text : _("ID_DASHBOARD_BTNCOLUMNS3"),
|
||||
handler : function(a) {
|
||||
Ext.MessageBox.show({
|
||||
msg: _('ID_LOADING'),
|
||||
progressText: 'Saving...',
|
||||
width:300,
|
||||
wait:true,
|
||||
waitConfig: {interval:200},
|
||||
animEl: 'mb7'
|
||||
});
|
||||
|
||||
var vp = Ext.getCmp('viewportDashboard');
|
||||
var pd = Ext.getCmp('portalDashboard');
|
||||
|
||||
for (var i = 0; i <= dashletsInstances.length - 1; i++) {
|
||||
pd.items.items[i % 3].add(pd.items.items[i % 2].items.items[0]);
|
||||
}
|
||||
|
||||
pd.items.items[0].columnWidth = 0.33;
|
||||
pd.items.items[1].columnWidth = 0.33;
|
||||
pd.items.items[2].columnWidth = 0.33;
|
||||
@@ -36,18 +60,57 @@ Ext.onReady(function(){
|
||||
|
||||
tbDashboard.items.items[0].setDisabled(true);
|
||||
tbDashboard.items.items[1].setDisabled(false);
|
||||
|
||||
var orderNow = generatedOrder();
|
||||
Ext.Ajax.request({
|
||||
params: {
|
||||
postionCol0: Ext.encode(orderNow[0]),
|
||||
postionCol1: Ext.encode(orderNow[1]),
|
||||
postionCol2: Ext.encode(orderNow[2]),
|
||||
columns: 3
|
||||
},
|
||||
url: 'dashboard/saveOrderDashlet',
|
||||
success: function (retorno) {
|
||||
var data = Ext.decode(retorno.responseText);
|
||||
if (data.success) {
|
||||
Ext.MessageBox.hide();
|
||||
}
|
||||
},
|
||||
failure: function () {
|
||||
Ext.MessageBox.alert('Error', 'Error al Guardar');
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
{
|
||||
xtype: 'tbbutton',
|
||||
text : _("ID_DASHBOARD_BTNCOLUMNS2"),
|
||||
handler : function(a) {
|
||||
Ext.MessageBox.show({
|
||||
msg: _('ID_LOADING'),
|
||||
progressText: 'Saving...',
|
||||
width:300,
|
||||
wait:true,
|
||||
waitConfig: {interval:200},
|
||||
animEl: 'mb7'
|
||||
});
|
||||
|
||||
var vp = Ext.getCmp('viewportDashboard');
|
||||
var pd = Ext.getCmp('portalDashboard');
|
||||
|
||||
for (var i = 0; i <= dashletsInstances.length - 1; i++) {
|
||||
pd.items.items[i % 2].add(pd.items.items[i % 3].items.items[0]);
|
||||
var dashletMove = new Array();
|
||||
for (var i = 0; i < Ext.getCmp('columnPos2').items.items.length; i++) {
|
||||
dashletMove.push(Ext.getCmp('columnPos2').items.items[i].id);
|
||||
}
|
||||
var flag = 0;
|
||||
for (var i = 0; i < dashletMove.length; i++) {
|
||||
Ext.getCmp('columnPos' + flag).add(Ext.getCmp(dashletMove[i]));
|
||||
if (flag == 0) {
|
||||
flag = 1;
|
||||
} else {
|
||||
flag = 0;
|
||||
}
|
||||
};
|
||||
|
||||
pd.items.items[0].columnWidth = 0.49;
|
||||
pd.items.items[1].columnWidth = 0.49;
|
||||
@@ -56,6 +119,26 @@ Ext.onReady(function(){
|
||||
|
||||
tbDashboard.items.items[0].setDisabled(false);
|
||||
tbDashboard.items.items[1].setDisabled(true);
|
||||
|
||||
var orderNow = generatedOrder();
|
||||
Ext.Ajax.request({
|
||||
params: {
|
||||
postionCol0: Ext.encode(orderNow[0]),
|
||||
postionCol1: Ext.encode(orderNow[1]),
|
||||
postionCol2: Ext.encode(orderNow[2]),
|
||||
columns: 2
|
||||
},
|
||||
url: 'dashboard/saveOrderDashlet',
|
||||
success: function (retorno) {
|
||||
var data = Ext.decode(retorno.responseText);
|
||||
if (data.success) {
|
||||
Ext.MessageBox.hide();
|
||||
}
|
||||
},
|
||||
failure: function () {
|
||||
Ext.MessageBox.alert('Error', 'Error al Guardar');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
]
|
||||
@@ -74,58 +157,112 @@ Ext.onReady(function(){
|
||||
id : 'portalDashboard',
|
||||
items:[{
|
||||
columnWidth:.33,
|
||||
id : 'columnPos0',
|
||||
style:'padding:10px 0 10px 10px',
|
||||
items:[]
|
||||
},{
|
||||
columnWidth:.33,
|
||||
style:'padding:10px 0 10px 10px',
|
||||
items:[]
|
||||
columnWidth:.33,
|
||||
id : 'columnPos1',
|
||||
style:'padding:10px 0 10px 10px',
|
||||
items:[]
|
||||
},{
|
||||
columnWidth:.33,
|
||||
style:'padding:10px',
|
||||
items:[]
|
||||
}]
|
||||
columnWidth:.33,
|
||||
id : 'columnPos2',
|
||||
style:'padding:10px',
|
||||
items:[]
|
||||
}],
|
||||
listeners: {
|
||||
'drop': function(e) {
|
||||
var orderNow = generatedOrder();
|
||||
Ext.MessageBox.show({
|
||||
msg: _('ID_LOADING'),
|
||||
progressText: 'Saving...',
|
||||
width:300,
|
||||
wait:true,
|
||||
waitConfig: {interval:200},
|
||||
animEl: 'mb7'
|
||||
});
|
||||
|
||||
/*
|
||||
* Uncomment this block to test handling of the drop event. You could use this
|
||||
* to save portlet position state for example. The event arg e is the custom
|
||||
* event defined in Ext.ux.Portal.DropZone.
|
||||
*/
|
||||
// ,listeners: {
|
||||
// 'drop': function(e){
|
||||
// Ext.Msg.alert('Portlet Dropped', e.panel.title + '<br />Column: ' +
|
||||
// e.columnIndex + '<br />Position: ' + e.position);
|
||||
// }
|
||||
// }
|
||||
if (tbDashboard.items.items[0].disabled == true) {
|
||||
var colum = 3;
|
||||
} else {
|
||||
var colum = 2;
|
||||
}
|
||||
Ext.Ajax.request({
|
||||
params: {
|
||||
postionCol0: Ext.encode(orderNow[0]),
|
||||
postionCol1: Ext.encode(orderNow[1]),
|
||||
postionCol2: Ext.encode(orderNow[2]),
|
||||
columns: colum
|
||||
},
|
||||
url: 'dashboard/saveOrderDashlet',
|
||||
success: function (retorno) {
|
||||
var data = Ext.decode(retorno.responseText);
|
||||
if (data.success) {
|
||||
Ext.MessageBox.hide();
|
||||
}
|
||||
},
|
||||
failure: function () {
|
||||
Ext.MessageBox.alert('Error', 'Error al Guardar');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}]
|
||||
});
|
||||
|
||||
var pd = Ext.getCmp('portalDashboard');
|
||||
|
||||
var con = 0;
|
||||
for (var i = 0; i < dashletsInstances.length; i++) {
|
||||
var np = new Ext.ux.Portlet({
|
||||
title: dashletsInstances[i].DAS_TITLE,
|
||||
index: i,
|
||||
dasInsUid : dashletsInstances[i].DAS_INS_UID,
|
||||
html: 'Gauge Placeholder',
|
||||
listeners: {
|
||||
'resize': function(p, w, h) {
|
||||
var template = new Ext.XTemplate(dashletsInstances[p.index].DAS_XTEMPLATE).apply({
|
||||
id: p.dasInsUid,
|
||||
page: 'dashboard/renderDashletInstance',
|
||||
width: w - 12,
|
||||
random: Math.floor(Math.random() * 1000000)
|
||||
})
|
||||
p.update(template);
|
||||
}
|
||||
}
|
||||
});
|
||||
for(var d = 0; d < dashletsInstances[i].length; d++) {
|
||||
|
||||
pd.items.items[i % 3].add(np);
|
||||
var np = new Ext.ux.Portlet({
|
||||
title: dashletsInstances[i][d].DAS_TITLE,
|
||||
index: con,
|
||||
indicei: i,
|
||||
indiced: d,
|
||||
dasInsUid : dashletsInstances[i][d].DAS_INS_UID,
|
||||
html: 'Gauge Placeholder',
|
||||
listeners: {
|
||||
'resize': function(p, w, h) {
|
||||
var template = new Ext.XTemplate(dashletsInstances[p.indicei][p.indiced].DAS_XTEMPLATE).apply({
|
||||
id: p.dasInsUid,
|
||||
page: 'dashboard/renderDashletInstance',
|
||||
width: w - 12,
|
||||
random: Math.floor(Math.random() * 1000000)
|
||||
})
|
||||
p.update(template);
|
||||
}
|
||||
}
|
||||
});
|
||||
pd.items.items[i].add(np);
|
||||
|
||||
con++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pd.doLayout();
|
||||
|
||||
tbDashboard.items.items[0].setDisabled(true);
|
||||
tbDashboard.items.items[1].setDisabled(false);
|
||||
if (dashletsColumns == 2) {
|
||||
tbDashboard.items.items[0].setDisabled(false);
|
||||
tbDashboard.items.items[1].setDisabled(true);
|
||||
|
||||
var pd = Ext.getCmp('portalDashboard');
|
||||
|
||||
pd.items.items[0].columnWidth = 0.49;
|
||||
pd.items.items[1].columnWidth = 0.49;
|
||||
pd.items.items[2].columnWidth = 0.01;
|
||||
pd.doLayout();
|
||||
} else {
|
||||
var pd = Ext.getCmp('portalDashboard');
|
||||
|
||||
pd.items.items[0].columnWidth = 0.33;
|
||||
pd.items.items[1].columnWidth = 0.33;
|
||||
pd.items.items[2].columnWidth = 0.33;
|
||||
pd.doLayout();
|
||||
|
||||
tbDashboard.items.items[0].setDisabled(true);
|
||||
tbDashboard.items.items[1].setDisabled(false);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user