Fix #1573 : Propose rights reset prior apply template

Conflicts:
	templates/web/admin/index.html.twig
This commit is contained in:
Romain Neutron
2013-11-08 15:38:15 +01:00
parent e48c2cc158
commit 9f2f1a4217
8 changed files with 120 additions and 48 deletions

View File

@@ -72,9 +72,15 @@ class Users implements ControllerProviderInterface
try {
$rights = new UserHelper\Edit($app, $app['request']);
$rights->apply_rights();
if (!$app['request']->request->get('reset_before_apply')) {
$rights->apply_rights();
}
if ($app['request']->request->get('template')) {
if ($app['request']->request->get('reset_before_apply')) {
$rights->resetRights();
}
$rights->apply_template();
}
@@ -198,6 +204,9 @@ class Users implements ControllerProviderInterface
$controllers->post('/apply_template/', function () use ($app) {
$users = new UserHelper\Edit($app, $app['request']);
if ($app['request']->request->get('reset_before_apply')) {
$users->resetRights();
}
$users->apply_template();
return $app->redirectPath('admin_users_search');

View File

@@ -42,9 +42,11 @@ $groups = array(
, '//include/jslibs/jquery-ui-1.10.3/jquery-ui-i18n.js'
, '//include/jquery.kb-event.js'
, '//skins/admin/users.js'
, '//skins/admin/template-dialogs.js'
, '//skins/admin/editusers.js'
, '//include/jquery.common.js'
, '//include/jquery.tooltip.js'
, '//skins/prod/jquery.Dialog.js'
, '//include/jslibs/jquery.contextmenu_scroll.js'
, '//assets/blueimp-load-image/js/load-image.js'
, '//assets/jquery-file-upload/js/jquery.iframe-transport.js'

View File

@@ -18,7 +18,8 @@
<script type="text/javascript" src="/include/tinymce/js/tinymce/tinymce.min.js"></script>
<script type="text/javascript" src="{{ path('minifier', { 'g' : 'admin' }) }}"></script>
<script type="text/javascript">
var p4 = {users:{sel:[]}};
var p4 = p4 || {};
p4.users = {sel:[]};
var bodySize = {x:0,y:0};
var language = {
@@ -33,7 +34,14 @@
annuler : '{% trans 'boutton::annuler' %}',
errorFileApiTooBig : '{% trans 'This file is too big' %}',
requiredValue: '{% trans 'This field is required' %}',
attention: '{% trans 'Attention' %}'
attention: '{% trans 'Attention' %}',
reset_template_do_reset_apply_button: '{% trans 'Reset and apply' %}',
reset_template_confirm_dialog_title: '{% trans 'Confirm reset users rights before applying template' %}',
reset_template_do_confirm_choice: '{% trans 'Rights will be erased before applying template, do you confirm?' %}',
reset_template_do_reset_button: '{% trans 'Reset and apply template' %}',
reset_template_do_not_reset_button: '{% trans 'Apply template' %}',
reset_template_dialog_title: '{% trans 'Reset rights before applying template?' %}',
reset_template_ask_choice: '{% trans 'Would you like to reset rights before applying the template?' %}'
};
function sessionactive(){

View File

@@ -11,7 +11,7 @@
{% trans %}
The user has been created.
{% endtrans %}
{% else %}
{% else %}
{% trans %}
{{ user_count }} users have been created.
{% endtrans %}
@@ -58,7 +58,7 @@
</fieldset>
</form>
<form id="users_apply_template" method="post" action="{{ path('admin_users_apply_template') }}" target="_self" class="form-inline pull-left" style="margin:0">
<form id="users_apply_template" method="post" action="{{ path('admin_users_apply_template') }}" target="_self" class="form-inline pull-left no-ajax" style="margin:0">
<fieldset class="admin_head_opts">
<span>{% trans 'Apply a template' %}</span>
<select name="template_chooser" class="input-medium">
@@ -140,7 +140,7 @@
{{usr.get_login()}}
</td>
<td>
{{usr.get_firstname()}} {{usr.get_lastname()}}
{{usr.get_firstname()}} {{usr.get_lastname()}}
</td>
<td>
{{usr.get_company()}}

View File

@@ -74,18 +74,29 @@ function ini_edit_usrs() {
template: $('#users_rights_form select[name="template"]').val(),
user_infos: $('#user_infos_form').serialize()
};
$.ajax({
type: 'POST',
url: '../admin/users/rights/apply/',
dataType: 'json',
data: datas,
success: function (data) {
if (!data.error)
$('a.zone_editusers').trigger('click');
else
alert(data.message);
}
});
var callback = function (reset_before_apply) {
datas.reset_before_apply = reset_before_apply;
$.ajax({
type: 'POST',
url: '../admin/users/rights/apply/',
dataType: 'json',
data: datas,
success: function (data) {
if (!data.error)
$('a.zone_editusers').trigger('click');
else
alert(data.message);
}
});
};
if (datas.template !== '') {
dialogUserTemplate(callback);
} else {
callback('0');
}
return false;
});

View File

@@ -0,0 +1,33 @@
var dialogUserResetTemplateConfirm = function (callback) {
var buttons = {};
buttons[language.reset_template_do_reset_apply_button] = function () { p4.Dialog.Close(2); callback('1'); };
var $dialog = p4.Dialog.Create({
size : '500x150',
closeOnEscape : true,
closeButton:false,
cancelButton:true,
title : language.reset_template_confirm_dialog_title,
buttons : buttons
}, 2);
$dialog.setContent(language.reset_template_do_confirm_choice);
}
var dialogUserTemplate = function (callback) {
var buttons = {};
buttons[language.reset_template_do_not_reset_button] = function () { p4.Dialog.Close(1); callback('0'); };
buttons[language.reset_template_do_reset_button] = function () { p4.Dialog.Close(1); dialogUserResetTemplateConfirm(callback); };
var $dialog = p4.Dialog.Create({
size : '500x150',
closeOnEscape : true,
closeButton:false,
cancelButton:true,
title : language.reset_template_dialog_title,
buttons : buttons
});
$dialog.setContent(language.reset_template_ask_choice);
}

View File

@@ -283,19 +283,22 @@ $(document).ready(function () {
return false;
}
$('#right-ajax').empty().addClass('loading');
p4.users.sel = [];
dialogUserTemplate(function (reset_before_apply) {
$('#right-ajax').empty().addClass('loading');
p4.users.sel = [];
$.ajax({
type: $this.attr('method'),
url: $this.attr('action'),
data: {
users: users,
template: template
},
success: function (data) {
$('#right-ajax').removeClass('loading').html(data);
}
$.ajax({
type: $this.attr('method'),
url: $this.attr('action'),
data: {
users: users,
template: template,
reset_before_apply: reset_before_apply
},
success: function (data) {
$('#right-ajax').removeClass('loading').html(data);
}
});
});
return false;
});

View File

@@ -75,24 +75,30 @@ var p4 = p4 || {};
this.options.buttons = addButtons(this.options.buttons, this);
switch (this.options.size) {
case 'Full':
height = bodySize.y - 30;
width = bodySize.x - 30;
break;
case 'Medium':
width = Math.min(bodySize.x - 30, 730);
height = Math.min(bodySize.y - 30, 520);
break;
default:
case 'Small':
width = Math.min(bodySize.x - 30, 420);
height = Math.min(bodySize.y - 30, 300);
break;
case 'Alert':
width = Math.min(bodySize.x - 30, 300);
height = Math.min(bodySize.y - 30, 150);
break;
if (/\d+x\d+/.test(this.options.size)) {
var dimension = this.options.size.split('x');
height = dimension[1];
width = dimension[0];
} else {
switch (this.options.size) {
case 'Full':
height = bodySize.y - 30;
width = bodySize.x - 30;
break;
case 'Medium':
width = Math.min(bodySize.x - 30, 730);
height = Math.min(bodySize.y - 30, 520);
break;
default:
case 'Small':
width = Math.min(bodySize.x - 30, 420);
height = Math.min(bodySize.y - 30, 300);
break;
case 'Alert':
width = Math.min(bodySize.x - 30, 300);
height = Math.min(bodySize.y - 30, 150);
break;
}
}
/*