Dashboards - Fixed issues + added 3 confirmation (on exit, save or cancel)

SVN:trunk[2199]
This commit is contained in:
Romain Quetiez
2012-09-21 15:15:05 +00:00
parent 4979a653ee
commit 2eddb57cbd
10 changed files with 161 additions and 23 deletions

View File

@@ -203,7 +203,7 @@ abstract class Dashboard
$oField = new DesignerLongTextField('dashboard_title', Dict::S('UI:DashboardEdit:DashboardTitle'), $this->sTitle);
$oForm->AddField($oField);
$this->SetFormParams($oForm);
$oForm->RenderAsPropertySheet($oPage);
$oForm->RenderAsPropertySheet($oPage, false, ':itop-dashboard');
$oPage->add('</div>');
$oPage->add_ready_script(
@@ -213,7 +213,7 @@ abstract class Dashboard
var sLayoutClass = $(this).val();
$(':itop-dashboard').dashboard('option', {layout_class: sLayoutClass});
} );
$('#row_attr_dashboard_title').property_field('option', {'do_apply': function() {
$('#row_attr_dashboard_title').property_field('option', {parent_selector: ':itop-dashboard', auto_apply: false, 'do_apply': function() {
var sTitle = $('#attr_dashboard_title').val();
$(':itop-dashboard').dashboard('option', {title: sTitle});
return true;
@@ -272,7 +272,7 @@ EOF
$oPage->add('<div class="dashlet_properties" id="dashlet_properties_'.$sId.'" style="display:none">');
$oForm = $oDashlet->GetForm();
$this->SetFormParams($oForm);
$oForm->RenderAsPropertySheet($oPage);
$oForm->RenderAsPropertySheet($oPage, false, ':itop-dashboard');
$oPage->add('</div>');
}
}
@@ -430,9 +430,15 @@ EOF
$sLayoutClass = addslashes($this->sLayoutClass);
$sTitle = addslashes($this->sTitle);
$sUrl = utils::GetAbsoluteUrlAppRoot().'pages/ajax.render.php';
$sExitConfirmationMessage = addslashes(Dict::S('UI:NavigateAwayConfirmationMessage'));
$sCancelConfirmationMessage = addslashes(Dict::S('UI:CancelConfirmationMessage'));
$sAutoApplyConfirmationMessage = addslashes(Dict::S('UI:AutoApplyConfirmationMessage'));
$oPage->add_ready_script(
<<<EOF
window.bLeavingOnUserAction = false;
$('#dashboard_editor').dialog({
height: $('body').height() - 50,
width: $('body').width() - 50,
@@ -440,9 +446,34 @@ $('#dashboard_editor').dialog({
title: '$sDialogTitle',
buttons: [
{ text: "$sOkButtonLabel", click: function() {
$('#dashboard_editor .ui-layout-center').dashboard('save'); /* $(this).dialog( "close" ); $(this).remove(); */
var oDashboard = $(':itop-dashboard').data('dashboard');
if (oDashboard.is_dirty())
{
if (!confirm('$sAutoApplyConfirmationMessage'))
{
return;
}
else
{
oDashboard.apply_changes();
}
}
window.bLeavingOnUserAction = true;
oDashboard.save();
} },
{ text: "$sCancelButtonLabel", click: function() {
var oDashboard = $(':itop-dashboard').data('dashboard');
if (oDashboard.is_modified())
{
if (!confirm('$sCancelConfirmationMessage'))
{
return;
}
}
window.bLeavingOnUserAction = true;
$(this).dialog( "close" );
$(this).remove();
} },
{ text: "$sCancelButtonLabel", click: function() { $(this).dialog( "close" ); $(this).remove(); } },
],
close: function() { $(this).remove(); }
});
@@ -497,6 +528,25 @@ $('#dashboard_editor').layout({
},
}
});
window.onbeforeunload = function() {
if (!window.bLeavingOnUserAction)
{
var oDashboard = $(':itop-dashboard').data('dashboard');
if (oDashboard)
{
if (oDashboard.is_dirty())
{
return '$sExitConfirmationMessage';
}
if (oDashboard.is_modified())
{
return '$sExitConfirmationMessage';
}
}
}
// return nothing ! safer for IE
};
EOF
);
$oPage->add_ready_script("");

View File

@@ -938,13 +938,13 @@ class DashletHeaderDynamic extends Dashlet
catch(Exception $e)
{
$oField = new DesignerTextField('group_by', Dict::S('UI:DashletHeaderDynamic:Prop-GroupBy'), $this->aProperties['group_by']);
$oField->SetMandatory();
$oField->SetReadOnly();
}
$oForm->AddField($oField);
$oField = new DesignerComboField('values', Dict::S('UI:DashletHeaderDynamic:Prop-Values'), $this->aProperties['values']);
$oField->MultipleSelection(true);
if (MetaModel::IsValidAttCode($sClass, $this->aProperties['group_by']))
if (isset($sClass) && MetaModel::IsValidAttCode($sClass, $this->aProperties['group_by']))
{
$aValues = MetaModel::GetAllowedValues_att($sClass, $this->aProperties['group_by']);
$oField->SetAllowedValues($aValues);

View File

@@ -144,7 +144,7 @@ class DesignerForm
}
public function RenderAsPropertySheet($oP, $bReturnHTML = false)
public function RenderAsPropertySheet($oP, $bReturnHTML = false, $sNotifyParentSelector = null)
{
$sReturn = '';
$sActionUrl = addslashes($this->sSubmitTo);
@@ -183,9 +183,11 @@ class DesignerForm
{
$sReturn .= $sValidationFields;
}
$sNotifyParentSelectorJS = is_null($sNotifyParentSelector) ? 'null' : "'".addslashes($sNotifyParentSelector)."'";
$sAutoApply = $oField->IsAutoApply() ? 'true' : 'false';
$this->AddReadyScript(
<<<EOF
$('#row_$sFieldId').property_field({field_id: '$sFieldId', value: '', submit_to: '$sActionUrl', submit_parameters: $sJSSubmitParams });
$('#row_$sFieldId').property_field({parent_selector: $sNotifyParentSelectorJS, field_id: '$sFieldId', auto_apply: $sAutoApply, value: '', submit_to: '$sActionUrl', submit_parameters: $sJSSubmitParams });
EOF
);
}
@@ -482,6 +484,7 @@ class DesignerFormField
protected $oForm;
protected $bMandatory;
protected $bReadOnly;
protected $bAutoApply;
public function __construct($sCode, $sLabel, $defaultValue)
{
@@ -490,6 +493,7 @@ class DesignerFormField
$this->defaultValue = $defaultValue;
$this->bMandatory = false;
$this->bReadOnly = false;
$this->bAutoApply = false;
}
public function GetCode()
@@ -517,7 +521,17 @@ class DesignerFormField
{
return ($this->oForm->IsReadOnly() || $this->bReadOnly);
}
public function SetAutoApply($bAutoApply)
{
$this->bAutoApply = $bAutoApply;
}
public function IsAutoApply()
{
return $this->bAutoApply;
}
public function Render(WebPage $oP, $sFormId, $sRenderMode='dialog')
{
$sId = $this->oForm->GetFieldId($this->sCode);
@@ -663,6 +677,8 @@ class DesignerComboField extends DesignerFormField
$this->aAllowedValues = array();
$this->bMultipleSelection = false;
$this->bOtherChoices = false;
$this->bAutoApply = true;
}
public function SetAllowedValues($aAllowedValues)
@@ -740,6 +756,7 @@ class DesignerBooleanField extends DesignerFormField
public function __construct($sCode, $sLabel = '', $defaultValue = '')
{
parent::__construct($sCode, $sLabel, $defaultValue);
$this->bAutoApply = true;
}
public function Render(WebPage $oP, $sFormId, $sRenderMode='dialog')
@@ -812,6 +829,7 @@ class DesignerIconSelectionField extends DesignerFormField
public function __construct($sCode, $sLabel = '', $defaultValue = '')
{
parent::__construct($sCode, $sLabel, $defaultValue);
$this->bAutoApply = true;
}
public function SetAllowedValues($aAllowedValues)