Commit 9e730074 authored by Athina Bekakou's avatar Athina Bekakou Committed by Giorgos Korfiatis

admin-ui: Inject data-keys in template and extract for js

Also, rename the attribute "ids" to "items". This attribute is used in
the "actions" request.
parent 184fa11e
snf = {
filters: {},
modals: {
performAction: function(modal, notificationArea, warningMsg, itemsData, itemsCount, countAction) {
var $modal = $(modal);
var $notificationArea = $(notificationArea);
......@@ -10,12 +8,12 @@ snf = {
var url = $actionBtn.attr('data-url');
var actionName = $actionBtn.find('span').text();
var logID = 'action-'+countAction;
var ids = JSON.stringify(itemsData);
var items = JSON.stringify(itemsData);
var data = {
op: $actionBtn.attr('data-op'),
target: $actionBtn.attr('data-target'),
ids: ids
items: items
}
var contactAction = (data.op === 'contact' ? true : false);
......@@ -207,7 +205,7 @@ snf = {
<dl class="dl-horizontal info-list with-inputs"> \
<dt>New e-mail:</dt> \
<dd> \
<input placeholder="new e-mail" class="new-email" name="new_email"> \
<input placeholder="new e-mail" class="new-email" name=<%= inputName %>> \
<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>',
......@@ -288,7 +286,7 @@ snf = {
<div class="wrap"><%= email %></div> \
</td> \
<td class="wrap td-with-input"> \
<input placeholder="new e-mail" class="new-email" name="new_email"> \
<input placeholder="new e-mail" class="new-email" name=<%= inputName %>> \
<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>',
......
......@@ -131,15 +131,31 @@ $(document).ready(function() {
}
function drawModalSingleItem(modalID, itemName, itemID) {
var tpl;
var html;
var $summary = $(modalID).find('.modal-body .summary');
var $actionBtn = $(modalID).find('.apply-action');
var tpl = snf.modals.html.singleItemInfo;
if (modalID == '#user-modify_email') {
tpl = snf.modals.html.singleItemInfoWithEmailInput;
}
var html = _.template(tpl);
// cannot use JSON.parse because data-keys inlude single quotes
var inputsNames = $actionBtn.attr('data-keys').slice(1, -1).replace(/ /g,'').split(',');
inputsNames = inputsNames.map(function(item) {
return item.slice(1, -1); // remove extra quotes
});
if (modalID == '#user-modify_email') {
tpl = snf.modals.html.singleItemInfoWithEmailInput;
html = _.template(tpl,
{
name: itemName,
id: itemID,
inputName: inputsNames[0] // modify_email has only 1 input
}
);
}
else{
tpl = snf.modals.html.singleItemInfo;
html = _.template(tpl, {name: itemName, id: itemID});
}
$actionBtn.attr('data-ids','['+itemID+']');
$summary.append(html({name: itemName, id: itemID}));
$summary.append(html);
};
......
......@@ -686,19 +686,18 @@ $(document).ready(function() {
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() {
var itemData = {};
itemData['id'] = $(this).attr('data-itemid');
if(hasInputs) {
itemData['data'] = {};
$(this).find('input').each(function() {
var key = $(this).attr('name');
itemData['data'][key] = $(this).val();
})
});
}
actionData.push(itemData)
actionData.push(itemData);
});
return actionData;
};
......@@ -802,6 +801,12 @@ $(document).ready(function() {
var idsArray = [];
var warningMsg = snf.modals.html.warningDuplicates;
var warningInserted = false;
// cannot use JSON.parse because data-keys inlude single quotes
var inputsNames = $actionBtn.attr('data-keys').slice(1, -1).replace(/ /g,'').split(',');
inputsNames = inputsNames.map(function(item) {
return item.slice(1, -1); // remove extra quotes
});
// association tracks for each user the related resource
// use to contact by selecting the resource of the user, not the user himself
var associations = {};
......@@ -856,7 +861,8 @@ $(document).ready(function() {
itemID: selected.items[i].contact_id,
fullName: selected.items[i].contact_name,
email: selected.items[i].contact_email,
hidden: (i > maxVisible)
hidden: (i > maxVisible),
inputName: inputsNames[0] // modify_email has only 1 input
}
);
htmlRows += currentRow;
......
{% load admin_tags %}
<!--<div class="modal fade" id="{{type}}-{{ op }}" data-type="{{ op }}" data-backdrop="static" data-keyboard="false">-->
<div class="modal fade" data-item ={{ action.target }} id="{{action.target}}-{{ op }}" data-backdrop="static" data-keyboard="true" tabindex="-1" data-karma={{ action.karma }} data-caution={{ action.caution_level }} data-type={{ op }}>
<div class="modal-dialog {% if op == 'modify_email' %} modal-lg {% else %} modal-md {% endif %}">
<div class="modal-dialog {% if op == 'modify_email' and view_type == 'list' %} modal-lg {% else %} modal-md {% endif %}">
<div class="modal-content area">
<div class="modal-header">
<a class="close cancel" data-dismiss="modal">×</a>
......@@ -61,7 +61,7 @@
</div>
<div class="modal-footer">
<a href="#" class="custom-btn cancel" data-dismiss="modal"><span>Cancel</span></a>
<a href="#" data-url={% url admin-actions %} data-op={{ op }} data-ids="" data-target={{ action.target }} class="custom-btn apply-action" data-karma={{ action.karma }} data-caution={{ action.caution_level }} data-dismiss="modal"><span>{{ action.name|safe }}</span></a>
<a href="#" data-url={% url admin-actions %} data-op={{ op }} data-ids="" data-target={{ action.target }} class="custom-btn apply-action" data-karma={{ action.karma }} data-caution={{ action.caution_level }} data-keys="{{ action.data_keys|safe }}" data-dismiss="modal"><span>{{ action.name|safe }}</span></a>
</div>
</div>
</div>
......
......@@ -308,7 +308,7 @@ def admin_actions(request):
target = objs['target']
op = objs['op']
items = json.loads(objs['ids'])
items = json.loads(objs['items'])
ids = [item['id'] for item in items]
......
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