Skip to content

Commit

Permalink
#322 - more updates to RendererProviderHTML to use the new bootstrapc…
Browse files Browse the repository at this point in the history
…onfirmokay.phtml template fragment duplicated JS code
  • Loading branch information
alphadevx committed May 19, 2018
1 parent 9d86cd5 commit 55adb83
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 83 deletions.
Expand Up @@ -16,7 +16,7 @@ if(window.jQuery) {
label: 'Okay',
cssClass: 'btn btn-default btn-xs',
action: function(dialogItself) {
$('[Id="<?= $buttonPressedId ?>"]').attr('value', '<?= $buttonName ?>');
$('[Id="<?= $formFieldId ?>"]').attr('value', '<?= $formFieldValue ?>');
$('#<?= $formId ?>').submit();
dialogItself.close();
}
Expand Down
96 changes: 14 additions & 82 deletions Alpha/View/Renderer/Html/RendererProviderHTML.php
Expand Up @@ -163,32 +163,10 @@ public function editView($fields = array())
$button = new Button('submit', 'Save', 'saveBut');
$fields['saveButton'] = $button->render();

$js = "if(window.jQuery) {
BootstrapDialog.show({
title: 'Confirmation',
message: 'Are you sure you wish to delete this item?',
buttons: [
{
icon: 'glyphicon glyphicon-remove',
label: 'Cancel',
cssClass: 'btn btn-default btn-xs',
action: function(dialogItself){
dialogItself.close();
}
},
{
icon: 'glyphicon glyphicon-ok',
label: 'Okay',
cssClass: 'btn btn-default btn-xs',
action: function(dialogItself) {
$('[id=\"".($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('ActiveRecordID')) : 'ActiveRecordID')."\"]').attr('value', '".$this->record->getID()."');
$('#deleteForm').submit();
dialogItself.close();
}
}
]
});
}";
$formFieldId = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('ActiveRecordID')) : 'ActiveRecordID');

$js = View::loadTemplateFragment('html', 'bootstrapconfirmokay.phtml', array('prompt' => 'Are you sure you wish to delete this item?', 'formFieldId' => $formFieldId, 'formFieldValue' => $this->record->getID(), 'formId' => 'deleteForm'));

$button = new Button($js, 'Delete', 'deleteBut');
$fields['deleteButton'] = $button->render();

Expand Down Expand Up @@ -319,32 +297,9 @@ public function listView($fields = array())
$html .= $button->render();
$html .= '&nbsp;&nbsp;';

$js = "if(window.jQuery) {
BootstrapDialog.show({
title: 'Confirmation',
message: 'Are you sure you wish to delete this item?',
buttons: [
{
icon: 'glyphicon glyphicon-remove',
label: 'Cancel',
cssClass: 'btn btn-default btn-xs',
action: function(dialogItself){
dialogItself.close();
}
},
{
icon: 'glyphicon glyphicon-ok',
label: 'Okay',
cssClass: 'btn btn-default btn-xs',
action: function(dialogItself) {
$('[id=\"".($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('ActiveRecordID')) : 'ActiveRecordID')."\"]').attr('value', '".$this->record->getID()."');
$('#deleteForm').submit();
dialogItself.close();
}
}
]
});
}";
$formFieldId = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('ActiveRecordID')) : 'ActiveRecordID');

$js = View::loadTemplateFragment('html', 'bootstrapconfirmokay.phtml', array('prompt' => 'Are you sure you wish to delete this item?', 'formFieldId' => $formFieldId, 'formFieldValue' => $this->record->getID(), 'formId' => 'deleteForm'));

$button = new Button($js, 'Delete', 'delete'.$this->record->getID().'But');
$html .= $button->render();
Expand Down Expand Up @@ -392,32 +347,9 @@ public function detailedView($fields = array())
}
$html .= $button->render();

$js = "if(window.jQuery) {
BootstrapDialog.show({
title: 'Confirmation',
message: 'Are you sure you wish to delete this item?',
buttons: [
{
icon: 'glyphicon glyphicon-remove',
label: 'Cancel',
cssClass: 'btn btn-default btn-xs',
action: function(dialogItself){
dialogItself.close();
}
},
{
icon: 'glyphicon glyphicon-ok',
label: 'Okay',
cssClass: 'btn btn-default btn-xs',
action: function(dialogItself) {
$('[id=\"".($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('ActiveRecordID')) : 'ActiveRecordID')."\"]').attr('value', '".$this->record->getID()."');
$('#deleteForm').submit();
dialogItself.close();
}
}
]
});
}";
$formFieldId = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('ActiveRecordID')) : 'ActiveRecordID');

$js = View::loadTemplateFragment('html', 'bootstrapconfirmokay.phtml', array('prompt' => 'Are you sure you wish to delete this item?', 'formFieldId' => $formFieldId, 'formFieldValue' => $this->record->getID(), 'formId' => 'deleteForm'));

$button = new Button($js, 'Delete', 'deleteBut');
$html .= $button->render();
Expand Down Expand Up @@ -502,19 +434,19 @@ public function adminView($fields = array())
// recreate and update table buttons (if required)
$html = '';
if ($this->record->checkTableNeedsUpdate() && $this->record->checkTableExists()) {
$buttonPressedId = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('admin_'.stripslashes(get_class($this->record)).'_button_pressed')) : 'admin_'.stripslashes(get_class($this->record)).'_button_pressed');
$formFieldId = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('admin_'.stripslashes(get_class($this->record)).'_button_pressed')) : 'admin_'.stripslashes(get_class($this->record)).'_button_pressed');

$js = View::loadTemplateFragment('html', 'bootstrapconfirmokay.phtml', array('prompt' => 'Are you sure you wish to recreate this class table (all data will be lost)?', 'buttonPressedId' => $buttonPressedId, 'buttonName' => 'recreateTableBut', 'formId' => 'admin_'.stripslashes(get_class($this->record))));
$js = View::loadTemplateFragment('html', 'bootstrapconfirmokay.phtml', array('prompt' => 'Are you sure you wish to recreate this class table (all data will be lost)?', 'formFieldId' => $formFieldId, 'formFieldValue' => 'recreateTableBut', 'formId' => 'admin_'.stripslashes(get_class($this->record))));

$button = new Button($js, 'Recreate Table', 'recreateTableBut');
$html .= $button->render();
// hidden field so that we know which class to recreate the table for
$html .= '<input type="hidden" name="recreateTableClass" value="'.get_class($this->record).'"/>';
$html .= '&nbsp;&nbsp;';

$buttonPressedId = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('admin_'.stripslashes(get_class($this->record)).'_button_pressed')) : 'admin_'.stripslashes(get_class($this->record)).'_button_pressed');
$formFieldId = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('admin_'.stripslashes(get_class($this->record)).'_button_pressed')) : 'admin_'.stripslashes(get_class($this->record)).'_button_pressed');

$js = View::loadTemplateFragment('html', 'bootstrapconfirmokay.phtml', array('prompt' => 'Are you sure you wish to attempt to modify this class table by adding new attributes?', 'buttonPressedId' => $buttonPressedId, 'buttonName' => 'recreateTableBut', 'formId' => 'admin_'.stripslashes(get_class($this->record))));
$js = View::loadTemplateFragment('html', 'bootstrapconfirmokay.phtml', array('prompt' => 'Are you sure you wish to attempt to modify this class table by adding new attributes?', 'formFieldId' => $formFieldId, 'formFieldValue' => 'recreateTableBut', 'formId' => 'admin_'.stripslashes(get_class($this->record))));

$button = new Button($js, 'Update Table', 'updateTableBut');
$html .= $button->render();
Expand Down

0 comments on commit 55adb83

Please sign in to comment.