Commit 69c60285 authored by Pat Kira's avatar Pat Kira Committed by Son Nguyen
Browse files

Fix edit group modal dialog (bug:1506034)

behatnotneeded

Change-Id: I7bebd67a8a860d707eeaa0b867352559910223b5
parent 7edf4f90
......@@ -21,104 +21,69 @@
* through which recipients can access the Corresponding Source.
* @licend
*/
jQuery(function($) {
"use strict";
// array compare method
Array.prototype.compare = function(testArr) {
if (this.length != testArr.length) return false;
for (var i = 0; i < testArr.length; i++) {
if (this[i].compare) {
if (!this[i].compare(testArr[i])) return false;
// array compare method
Array.prototype.compare = function(testArr) {
if (this.length != testArr.length) return false;
for (var i = 0; i < testArr.length; i++) {
if (this[i].compare) {
if (!this[i].compare(testArr[i])) return false;
}
if (this[i] !== testArr[i]) return false;
}
if (this[i] !== testArr[i]) return false;
}
return true;
};
var ul = null;
var initialgroups = new Array();
function showGroupBox(event, user_id) {
replaceChildNodes('messages');
if (event.preventDefault) {
event.preventDefault();
} else {
event.returnValue = false;
}
if (!$('groupbox')) {
appendChildNodes(
getFirstElementByTagAndClassName('body'),
DIV({'id':'groupbox','class':'groupbox hidden'})
);
}
if (hasElementClass('groupbox', 'hidden')) {
getitems(user_id, function() {
removeElementClass('groupbox', 'hidden');
});
}
else {
addElementClass('groupbox', 'hidden');
}
return false;
}
return true;
};
function changemembership(event, user_id, addtype) {
replaceChildNodes('messages');
var initialgroups = new Array();
if (event.preventDefault) {
event.preventDefault();
} else {
event.returnValue = false;
function getAllCheckedElemValues (groups) {
var resultgroups = new Array();
for (var i = 0; i < groups.length; i++ ) {
if (groups[i].checked) {
resultgroups.push(groups[i].value);
}
}
return resultgroups;
}
var groups = document.getElementsByName(addtype+'group_'+user_id);
var resultgroups = new Array();
forEach(groups, function(group) {
if (group.checked == true ) {
resultgroups.push(group.value);
// Initialise edit group modal
$('.js-edit-group').on('click', function(e){
e.preventDefault();
var userid = $(this).data('userid');
if ($('.js-editgroup-' + userid).length) {
$('.js-editgroup-' + userid).remove();
}
});
// apply changes only if something has been changed
if (!initialgroups[addtype].compare(resultgroups)){
sendjsonrequest('../group/changegroupsmembership.json.php',
{
'addtype':addtype,
'userid':user_id,
'resultgroups':resultgroups.join(','),
'initialgroups':initialgroups[addtype].join(',')
}, 'POST',
function() {
addElementClass('groupbox', 'hidden');
sendjsonrequest('../group/controlledgroups.json.php', {
'userid':userid
}, 'GET', function(data) {
initialgroups = data.data.initialgroups;
$(data.data.html).modal('show');
});
}
}
function getitems(user_id, successfunction) {
sendjsonrequest('../group/controlledgroups.json.php', {
'userid':user_id
}, 'GET',
function(data) {
replaceChildNodes('groupbox');
$('groupbox').innerHTML = data.data.html;
var jt = getElementsByTagAndClassName('div', 'jointype', 'groupbox');
});
var gbwidth = jt.length == 2 ? 640 : 315;
var d = getElementDimensions('groupbox');
var vpdim = getViewportDimensions();
var newtop = getViewportPosition().y + Math.max((vpdim.h - d.h) / 2, 5);
setStyle('groupbox', {
'width': gbwidth + 'px',
'left': (vpdim.w - d.w) / 2 + 'px',
'top': newtop + 'px',
'position': 'absolute'
});
initialgroups = data.data.initialgroups;
successfunction();
// Change membership
$('body').on('click', '.js-editgroup-submit', function(e) {
e.preventDefault();
var userid = $(this).data('userid');
var addtype = $(this).data('addtype');
var groups = $('[name="' + addtype +'group_'+ userid + '"]');
var resultgroups = getAllCheckedElemValues(groups);
// apply changes only if something has been changed
if (!initialgroups[addtype].compare(resultgroups)){
sendjsonrequest('../group/changegroupsmembership.json.php',
{
'addtype': addtype,
'userid': userid,
'resultgroups': resultgroups.join(','),
'initialgroups': initialgroups[addtype].join(',')
}, 'POST',
function() {
$('.modal.in').modal('hide');
});
}
});
}
});
......@@ -280,3 +280,19 @@
margin-top: 0;
}
}
// Editgroup membership modal
// see editgroupmemship.tpl
.editgroup-container {
border-bottom: 1px solid #f9f9f9;
padding-bottom: 20px;
margin-bottom: 20px;
&:last-child {
border-bottom-width: 0;
margin-bottom: 0;
padding-bottom: 0;
}
.heading {
margin: 0;
}
}
......@@ -57,10 +57,10 @@ $width-sm: 90%;
}
}
.page-modal {
.modal-content {
.modal-content {
overflow: hidden;
max-height: 90%;
}
}
}
.modal-content {
......
<div class="modal fade in edit-membership" id="groupboxwrap" style="display:block;">
<div class="modal-dialog" >
<div class="modal fade js-editgroup-{$userid}" id="groupboxwrap-{$userid}">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<a href="" onclick="addElementClass('groupbox', 'hidden');return false;" class="close"><span aria-hidden="true">×</span></a>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<h4 class="modal-title">{str tag=editmembershipforuser section=group arg1=display_name($userid)}</h4>
</div>
<div class="modal-body">
{if !$data}
<p>{str tag=nogroups section=group}</p>
<p class="no-results">{str tag=nogroups section=group}</p>
{else}
{foreach from=$data key=addtype item=groups}
<div class="editgroup-container">
{if $groups}
<h5 class="lead">{if $addtype == 'add'}{str tag=addmembers section=group}{else}{str tag=invite section=group}{/if}</h5>
<div class="form-group checkbox">
<h4 class="heading">{if $addtype == 'add'}{str tag=addmembers section=group}{else}{str tag=invite section=group}{/if}</h4>
<div class="checkboxes form-group last {if count($groups) > 6}column-list{/if}">
{foreach from=$groups item=group}
<div>
<input id="{$addtype}{$group->id}" type="checkbox" class="checkbox" name="{$addtype}group_{$userid}" value="{$group->id}"{if $group->checked} checked{/if}{if $group->disabled} disabled{/if}>
<div class="checkbox">
<input id="{$addtype}{$group->id}" type="checkbox" class="checkbox" name="{$addtype}group_{$userid}" value="{$group->id}" {if $group->checked}checked{/if} {if $group->disabled} disabled{/if}>
<label for="{$addtype}{$group->id}">{$group->name}</label>
</div>
{/foreach}
<a class="btn btn-primary submit" href="" onclick="changemembership(event, {$userid}, '{$addtype}');">{str tag=applychanges}</a>
</div>
<a href="" class="btn btn-primary js-editgroup-submit" data-userid="{$userid}" data-addtype="{$addtype}">
{str tag=applychanges}
</a>
{/if}
</div>
{/foreach}
{/if}
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
\ No newline at end of file
</div>
</div>
</div>
......@@ -63,7 +63,9 @@
{if $admingroups}
<div class="editgroup text-small">
<span class="icon icon-pencil left"></span>
<a href="" onclick="showGroupBox(event, {$user->id})" class="btn-edit">{str tag='editgroupmembership' section='group'}</a>
<a href="" id="editgroup-link-{$user->id}" class="js-edit-group" data-userid="{$user->id}">
{str tag='editgroupmembership' section='group'}
</a>
</div>
{/if}
</div>
......
......@@ -92,7 +92,9 @@
{if $admingroups}
<li class="editgroup">
<span class="icon icon-lg text-default icon-cogs left"></span>
<a href="" onclick="showGroupBox(event, {$user->id})" class="btn-edit">{str tag='editgroupmembership' section='group'}</a>
<a id="editgroup-link" class="js-edit-group" href="" data-userid="{$user->id}">
{str tag='editgroupmembership' section='group'}
</a>
</li>
{/if}
</ul>
......
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