#11216 Duplicate widget
This commit is contained in:
parent
1d0eaa2738
commit
6d848b9fd3
|
@ -269,6 +269,10 @@ function initialiceLayout(data) {
|
|||
$("#configure-widget-" + id).click(function() {
|
||||
getSizeModalConfiguration(id, widgetId);
|
||||
});
|
||||
|
||||
$("#copy-widget-" + id).click(function() {
|
||||
duplicateWidget(id, widgetId);
|
||||
});
|
||||
},
|
||||
error: function(error) {
|
||||
console.error(error);
|
||||
|
@ -299,6 +303,31 @@ function initialiceLayout(data) {
|
|||
return false;
|
||||
}
|
||||
|
||||
function duplicateWidget(original_cellId, original_widgetId) {
|
||||
let duplicate_cellId = insertCellLayoutForDuplicate();
|
||||
|
||||
$.ajax({
|
||||
method: "post",
|
||||
url: data.url,
|
||||
data: {
|
||||
page: data.page,
|
||||
method: "duplicateWidget",
|
||||
dashboardId: data.dashboardId,
|
||||
widgetId: original_widgetId,
|
||||
cellId: original_cellId,
|
||||
duplicateCellId: duplicate_cellId
|
||||
},
|
||||
dataType: "json",
|
||||
success: function(success) {
|
||||
console.log(success);
|
||||
},
|
||||
error: function(error) {
|
||||
console.log(error);
|
||||
return [];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function saveLayout() {
|
||||
var items = $(".grid-stack > .grid-stack-item:visible")
|
||||
.map(function(i, el) {
|
||||
|
@ -394,6 +423,37 @@ function initialiceLayout(data) {
|
|||
});
|
||||
}
|
||||
|
||||
function insertCellLayoutForDuplicate() {
|
||||
let duplicateCellId = 0;
|
||||
$.ajax({
|
||||
async: false,
|
||||
method: "post",
|
||||
url: data.url,
|
||||
data: {
|
||||
page: data.page,
|
||||
method: "insertCellLayout",
|
||||
dashboardId: data.dashboardId,
|
||||
auth_class: data.auth.class,
|
||||
auth_hash: data.auth.hash,
|
||||
id_user: data.auth.user
|
||||
},
|
||||
dataType: "json",
|
||||
success: function(data) {
|
||||
// By default x and y = 0
|
||||
// width and height = 4
|
||||
// position auto = true.
|
||||
if (data.cellId !== 0) {
|
||||
addCell(data.cellId, 0, 0, 4, 4, true, 0, 2000, 0, 2000, 0, true);
|
||||
duplicateCellId = data.cellId;
|
||||
}
|
||||
},
|
||||
error: function(error) {
|
||||
console.error(error);
|
||||
}
|
||||
});
|
||||
return duplicateCellId;
|
||||
}
|
||||
|
||||
function configurationWidget(cellId, widgetId, size) {
|
||||
load_modal({
|
||||
target: $("#modal-config-widget"),
|
||||
|
@ -722,6 +782,10 @@ function initialiceLayout(data) {
|
|||
getSizeModalConfiguration(cellId, widgetId);
|
||||
});
|
||||
|
||||
$("#copy-widget-" + cellId).click(function() {
|
||||
duplicateWidget(cellId, widgetId);
|
||||
});
|
||||
|
||||
saveLayout();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -160,6 +160,13 @@ class Manager implements PublicLogin
|
|||
*/
|
||||
private $publicLink;
|
||||
|
||||
/**
|
||||
* Duplicate Id Cell.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $duplicateCellId;
|
||||
|
||||
/**
|
||||
* Allowed methods to be called using AJAX request.
|
||||
*
|
||||
|
@ -181,6 +188,7 @@ class Manager implements PublicLogin
|
|||
'formSlides',
|
||||
'callWidgetMethod',
|
||||
'getSizeModalConfiguration',
|
||||
'duplicateWidget',
|
||||
];
|
||||
|
||||
|
||||
|
@ -283,6 +291,7 @@ class Manager implements PublicLogin
|
|||
$this->widgetId = (int) $extradata['widgetId'];
|
||||
} else {
|
||||
$this->cellId = (int) \get_parameter('cellId', []);
|
||||
$this->duplicateCellId = (int) \get_parameter('duplicateCellId', []);
|
||||
$this->offset = (int) \get_parameter('offset', 0);
|
||||
|
||||
$this->dashboardId = (int) \get_parameter('dashboardId', 0);
|
||||
|
@ -597,6 +606,42 @@ class Manager implements PublicLogin
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Duplicate widget.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function duplicateWidget():int
|
||||
{
|
||||
$original_widget = [];
|
||||
|
||||
$original_cellId = $this->cellId;
|
||||
foreach ($this->cells as $cells) {
|
||||
if ($cells['id'] == $original_cellId) {
|
||||
$original_widget['id_widget'] = $cells['id_widget'];
|
||||
$original_widget['options'] = $cells['options'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$options = json_decode($original_widget['options'], true);
|
||||
$options['title'] = __('Copy of %s', $options['title']);
|
||||
$options_json = json_encode($options);
|
||||
|
||||
$values = [
|
||||
'options' => $options_json,
|
||||
'id_widget' => $original_widget['id_widget'],
|
||||
];
|
||||
$res = \db_process_sql_update(
|
||||
'twidget_dashboard',
|
||||
$values,
|
||||
['id' => $this->duplicateCellId]
|
||||
);
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy Dashboard and asociate widgets.
|
||||
*
|
||||
|
|
|
@ -47,6 +47,18 @@ $output .= '<div class="header-options">';
|
|||
|
||||
if ($manageDashboards !== 0 || $writeDashboards !== 0) {
|
||||
if ((int) $cellData['id_widget'] !== 0) {
|
||||
$output .= '<a id="copy-widget-'.$cellData['id'].'" class="">';
|
||||
$output .= html_print_image(
|
||||
'images/copy.svg',
|
||||
true,
|
||||
[
|
||||
'width' => '16px',
|
||||
'title' => __('Copy widget'),
|
||||
'class' => 'invert_filter',
|
||||
]
|
||||
);
|
||||
$output .= '</a> ';
|
||||
|
||||
$output .= '<a id="configure-widget-'.$cellData['id'].'" class="">';
|
||||
$output .= html_print_image(
|
||||
'images/configuration@svg.svg',
|
||||
|
|
Loading…
Reference in New Issue