Commit 2cf07e41 authored by Athina Bekakou's avatar Athina Bekakou Committed by Giorgos Korfiatis

admin-ui: Add mechanism for actions with extra data

This mechanism detects if there are inputs for each item that the action
targets and if there are, it adds in the request the name and the value
of the input.

Also, with this commit the mechanism is used for the action "modify
e-mail".
parent bb2b0930
snf = { snf = {
filters: {}, filters: {},
modals: { modals: {
performAction: function(modal, notificationArea, warningMsg, itemsCount, countAction) {
performAction: function(modal, notificationArea, warningMsg, itemsData, itemsCount, countAction) {
var $modal = $(modal); var $modal = $(modal);
var $notificationArea = $(notificationArea); var $notificationArea = $(notificationArea);
var $actionBtn = $modal.find('.apply-action') var $actionBtn = $modal.find('.apply-action')
var url = $actionBtn.attr('data-url'); var url = $actionBtn.attr('data-url');
var actionName = $actionBtn.find('span').text(); var actionName = $actionBtn.find('span').text();
var logID = 'action-'+countAction; var logID = 'action-'+countAction;
var ids = $actionBtn.attr('data-ids').slice(1,-1).split(','); var ids = JSON.stringify(itemsData);
ids.forEach(function(item, i, ids) {
ids[i] = '{"id": '+ '"'+ item+'"}';
});
var idsString = "["+ids.toString()+"]"
var data = { var data = {
op: $actionBtn.attr('data-op'), op: $actionBtn.attr('data-op'),
target: $actionBtn.attr('data-target'), target: $actionBtn.attr('data-target'),
ids: idsString ids: ids
} }
var contactAction = (data.op === 'contact' ? true : false); var contactAction = (data.op === 'contact' ? true : false);
...@@ -195,8 +194,8 @@ snf = { ...@@ -195,8 +194,8 @@ snf = {
}); });
}, },
html: { html: {
singleItemInfo: '<dl class="dl-horizontal info-list"><dt>Name:</dt><dd><%= name %></dd><dt>ID:</dt><dd><%= id %></dd><dl>', singleItemInfo: '<dl class="dl-horizontal info-list" data-itemid=<%= id %>><dt>Name:</dt><dd><%= name %></dd><dt>ID:</dt><dd><%= id %></dd><dl>',
singleItemInfoWithEmailInput: '<dl class="dl-horizontal info-list"><dt>Name:</dt><dd><%= name %></dd><dt>ID:</dt><dd><%= id %></dd><dt>New e-mail:</dt><dd><input placeholder="new e-mail" class="new-email"><a data-error="invalid-email" data-toggle="popover" data-trigger="hover" class="error-sign snf-exclamation-sign" href="#" rel="tooltip" data-content="Invalid e&#8209mail address."></a></dd><dl>', singleItemInfoWithEmailInput: '<dl class="dl-horizontal info-list" data-itemid=<%= id %>><dt>Name:</dt><dd><%= name %></dd><dt>ID:</dt><dd><%= id %></dd><dt>New e-mail:</dt><dd><input placeholder="new e-mail" class="new-email" data-key="new_email"><a data-error="invalid-email" data-toggle="popover" data-trigger="hover" class="error-sign snf-exclamation-sign" href="#" rel="tooltip" data-content="Invalid e&#8209mail address."></a></dd><dl>',
removeLogLine: '<a href="" class="remove-icon remove-log" title="Remove this line">X</a>', removeLogLine: '<a href="" class="remove-icon remove-log" title="Remove this line">X</a>',
notifyPending: '<p class="log" id="<%= logID %>"><span class="pending state-icon snf-font-admin snf-exclamation-sign"></span>Action <b>"<%= actionName %>"</b><% if (itemsCount==1) { %> for <%= itemsCount %> item <% } else if (itemsCount>0) { %> for <%= itemsCount %> items <% } %> is <b class="pending">pending</b>.<%= removeBtn %></p>', notifyPending: '<p class="log" id="<%= logID %>"><span class="pending state-icon snf-font-admin snf-exclamation-sign"></span>Action <b>"<%= actionName %>"</b><% if (itemsCount==1) { %> for <%= itemsCount %> item <% } else if (itemsCount>0) { %> for <%= itemsCount %> items <% } %> is <b class="pending">pending</b>.<%= removeBtn %></p>',
notifySuccess: '<p class="log"><span class="success state-icon snf-font-admin snf-ok"></span>Action <b>"<%= actionName %>"</b><% if (itemsCount==1) { %> for <%= itemsCount %> item <% } else if (itemsCount>0) { %> for <%= itemsCount %> items <% } %> <b class="succeed">succeeded</b>.<%= removeBtn %></p>', notifySuccess: '<p class="log"><span class="success state-icon snf-font-admin snf-ok"></span>Action <b>"<%= actionName %>"</b><% if (itemsCount==1) { %> for <%= itemsCount %> item <% } else if (itemsCount>0) { %> for <%= itemsCount %> items <% } %> <b class="succeed">succeeded</b>.<%= removeBtn %></p>',
...@@ -210,7 +209,7 @@ snf = { ...@@ -210,7 +209,7 @@ snf = {
warningDuplicates: '<p class="warning-duplicate">Duplicate accounts have been detected.</p>', warningDuplicates: '<p class="warning-duplicate">Duplicate accounts have been detected.</p>',
commonRow: '<tr data-itemid=<%= itemID %> <% if(hidden) { %> class="hidden-row" <% } %> ><td class="item-name"><%= itemName %></td><td class="item-id"><%= itemID %></td><td class="owner-name"><%= ownerName %></td><td class="owner-email"><div class="wrap"><a class="remove" title="Remove item from selection">X</a><%= ownerEmail %></div></td></tr>', commonRow: '<tr data-itemid=<%= itemID %> <% if(hidden) { %> class="hidden-row" <% } %> ><td class="item-name"><%= itemName %></td><td class="item-id"><%= itemID %></td><td class="owner-name"><%= ownerName %></td><td class="owner-email"><div class="wrap"><a class="remove" title="Remove item from selection">X</a><%= ownerEmail %></div></td></tr>',
contactRow: '<tr <% if(showAssociations) { %> title="related with: <%= associations %>" <% } %> data-itemid=<%= itemID %> <% if(hidden) { %> class="hidden-row" <% } %> ><td class="full-name"><%= fullName %></td><td class="email"><div class="wrap"><a class="remove" title="Remove item from selection">X</a><%= email %></div></td></tr>', contactRow: '<tr <% if(showAssociations) { %> title="related with: <%= associations %>" <% } %> data-itemid=<%= itemID %> <% if(hidden) { %> class="hidden-row" <% } %> ><td class="full-name"><%= fullName %></td><td class="email"><div class="wrap"><a class="remove" title="Remove item from selection">X</a><%= email %></div></td></tr>',
modifyEmailRow: '<tr data-itemid=<%= itemID %> <% if(hidden) { %> class="hidden-row" <% } %> ><td class="full-name"><%= fullName %></td><td class="item-id"><%= itemID %></td><td class="email"><div class="wrap"><%= email %></div></td><td class="wrap td-with-input"><input placeholder="new e-mail" class="new-email"><a data-error="invalid-email" data-toggle="popover" data-trigger="hover" class="error-sign snf-exclamation-sign" href="#" rel="tooltip" data-content="Invalid e&#8209mail address."></a><a class="remove" title="Remove item from selection">X</a></td></tr>', modifyEmailRow: '<tr data-itemid=<%= itemID %> <% if(hidden) { %> class="hidden-row" <% } %> ><td class="full-name"><%= fullName %></td><td class="item-id"><%= itemID %></td><td class="email"><div class="wrap"><%= email %></div></td><td class="wrap td-with-input"><input placeholder="new e-mail" class="new-email" data-key="new_email"><a data-error="invalid-email" data-toggle="popover" data-trigger="hover" class="error-sign snf-exclamation-sign" href="#" rel="tooltip" data-content="Invalid e&#8209mail address."></a><a class="remove" title="Remove item from selection">X</a></td></tr>',
} }
}, },
......
...@@ -143,6 +143,23 @@ $(document).ready(function() { ...@@ -143,6 +143,23 @@ $(document).ready(function() {
}; };
function collectActionData(modal) {
var $list = $(modal).find('.info-list');
var actionData = [];
var hasInputs = $list.find('dd input').length > 0;
var itemData = {};
itemData['id'] = $list.attr('data-itemid');
if(hasInputs) {
itemData['data'] = {};
var key = $list.find('dd input').attr('data-key');
var value = $list.find('dd input').val();
itemData['data'][key] = value;
}
actionData.push(itemData)
return actionData;
};
$('.modal').find('.cancel').click(function() { $('.modal').find('.cancel').click(function() {
$modal =$(this).closest('.modal'); $modal =$(this).closest('.modal');
snf.modals.resetInputs($modal); snf.modals.resetInputs($modal);
...@@ -169,7 +186,7 @@ $(document).ready(function() { ...@@ -169,7 +186,7 @@ $(document).ready(function() {
e.stopPropagation(); e.stopPropagation();
} }
else { else {
snf.modals.performAction($modal, $notificationArea, snf.modals.html.notifyRefreshPage, 0, countAction); snf.modals.performAction($modal, $notificationArea, snf.modals.html.notifyRefreshPage, collectActionData($modal), 0, countAction);
snf.modals.resetInputs($modal); snf.modals.resetInputs($modal);
snf.modals.resetErrors($modal); snf.modals.resetErrors($modal);
resetItemInfo($modal); resetItemInfo($modal);
......
$(document).ready(function() { $(document).ready(function() {
var $actionbar = $('.actionbar'); var $actionbar = $('.actionbar');
if($actionbar.length > 0) { if($actionbar.length > 0) {
sticker(); sticker();
...@@ -682,6 +682,27 @@ $(document).ready(function() { ...@@ -682,6 +682,27 @@ $(document).ready(function() {
$modal.find('.toggle-more').find('span').text('Show all'); $modal.find('.toggle-more').find('span').text('Show all');
}; };
function collectActionData(modal) {
var $table = $(modal).find('.table-selected');
var actionData = [];
var hasInputs = $table.find('tr:first input').length > 0;
var itemData = {};
if(hasInputs) {
itemData['data'] = {};
}
$table.find('tr').each(function() {
itemData['id'] = $(this).attr('data-itemid');
if(hasInputs) {
$(this).find('input').each(function() {
var key = $(this).attr('data-key');
itemData['data'][key] = $(this).val();
})
}
actionData.push(itemData)
});
return actionData;
};
$('.modal .cancel').click(function(e) { $('.modal .cancel').click(function(e) {
$('[data-toggle="popover"]').popover('hide'); $('[data-toggle="popover"]').popover('hide');
var $modal = $(this).closest('.modal'); var $modal = $(this).closest('.modal');
...@@ -705,6 +726,7 @@ $(document).ready(function() { ...@@ -705,6 +726,7 @@ $(document).ready(function() {
var $modal = $(this).closest('.modal'); var $modal = $(this).closest('.modal');
var noError = true; var noError = true;
var itemsNum = $modal.find('tbody tr').length; var itemsNum = $modal.find('tbody tr').length;
var itemsData;
if(selected.items.length === 0) { if(selected.items.length === 0) {
snf.modals.showError($modal, 'no-selected'); snf.modals.showError($modal, 'no-selected');
noError = false; noError = false;
...@@ -723,7 +745,8 @@ $(document).ready(function() { ...@@ -723,7 +745,8 @@ $(document).ready(function() {
} }
else { else {
$('[data-toggle="popover"]').popover('hide'); $('[data-toggle="popover"]').popover('hide');
snf.modals.performAction($modal, $notificationArea, snf.modals.html.notifyReloadTable, itemsNum, countAction); itemsData = collectActionData($modal);
snf.modals.performAction($modal, $notificationArea, snf.modals.html.notifyReloadTable, itemsData, itemsNum, countAction);
snf.modals.resetErrors($modal); snf.modals.resetErrors($modal);
snf.modals.resetInputs($modal); snf.modals.resetInputs($modal);
removeWarningDupl($modal); removeWarningDupl($modal);
......
...@@ -19,7 +19,7 @@ $total-black: #222; ...@@ -19,7 +19,7 @@ $total-black: #222;
// Dimensions // Dimensions
$nav-side-padding: 20px; $nav-side-padding: 20px;
$sidebar-width: 110px; $sidebar-width: 116px;
$datatabled-actions-height: 35px; $datatabled-actions-height: 35px;
$details-title-height: 35px; $details-title-height: 35px;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment