Merge remote-tracking branch 'framagit/master'

This commit is contained in:
Julien Fastré 2016-03-24 14:21:28 +01:00
commit dc5fd27a40
3 changed files with 252 additions and 167 deletions

View File

@ -1,6 +1,6 @@
/* jslint vars: true */ /* jslint vars: true */
/*jslint indent: 3 */ /*jslint indent: 4 */
/* global moment, $ */ /* global moment, $, window */
'use strict'; 'use strict';
var chill = function() { var chill = function() {
@ -107,7 +107,8 @@ var chill = function() {
}) })
.on('reset', function() { .on('reset', function() {
unsaved_data = false; unsaved_data = false;
}); })
;
$.each($(form_id).find(':input'), function(i,e) { $.each($(form_id).find(':input'), function(i,e) {
$(e).change(function() { $(e).change(function() {
@ -122,9 +123,11 @@ var chill = function() {
}); });
} }
/**
* TODO : DOC
*/
function checkNullValuesInChoices(choice_name) { function checkNullValuesInChoices(choice_name) {
var choices; var choices;
console.log(choice_name);
choices = $("input[name='"+choice_name+"']:checked"); choices = $("input[name='"+choice_name+"']:checked");
if (choices.size() === 0) { if (choices.size() === 0) {
$.each($("input[name='"+choice_name+"']"), function (i, e) { $.each($("input[name='"+choice_name+"']"), function (i, e) {
@ -133,8 +136,6 @@ var chill = function() {
} }
}); });
} }
//}
//});
} }
/** /**
@ -173,6 +174,71 @@ var chill = function() {
}); });
} }
/**
* Create an interraction between two select element (the parent and the
* child) of a given form : each parent option has a category, the
* child select only display options that have the same category of the
* parent optionn
*/
/**
* TODO ECRIRE LA DOC METTRE LES TESTS DANS git :
* tester que init est ok :
- quand vide
- quand choix
* tester que quand sélection
- quand vide
- quand choix
*/
function categoryLinkParentChildSelect() {
var forms_to_link = $('form:has(select.chill-category-link-parent)');
forms_to_link.each(function(i,form_selector) {
var form = $(form_selector);
form.old_category = null;
form.link_parent = $(form).find('.chill-category-link-parent');
form.link_child = $(form).find('.chill-category-link-child');
$(form.link_parent).addClass('select2');
$(form.link_parant).select2({allowClear: true});
form.old_category = null;
if($(form.link_parent).select2('data') !== null) {
form.old_category = ($(form.link_parent).select2('data').element[0].dataset.linkCategory);
}
$(form.link_child).find('option')
.each(function(i,e) {
if(
((!$(e).data('link-category')) || $(e).data('link-category') == form.old_category) &&
((!$(e).data('link-categories')) || form.old_category in $(e).data('link-categories').split(','))
) {
$(e).show();
} else {
$(e).hide();
}
});
form.link_parent.change(function() {
var new_category = ($(form.link_parent).select2('data').element[0].dataset.linkCategory);
if(new_category != form.old_category) {
$(form.link_child).find('option')
.each(function(i,e) {
if(
((!$(e).data('link-category')) || $(e).data('link-category') == new_category) &&
((!$(e).data('link-categories')) || new_category in $(e).data('link-categories').split(','))
) {
$(e).show();
} else {
$(e).hide();
}
});
$(form.link_child).find('option')[0].selected = true;
form.old_category = new_category;
}
});
});
}
return { return {
initPikaday: initPikaday, initPikaday: initPikaday,
emulateSticky: emulateSticky, emulateSticky: emulateSticky,
@ -180,5 +246,6 @@ var chill = function() {
displayAlertWhenLeavingModifiedForm: displayAlertWhenLeavingModifiedForm, displayAlertWhenLeavingModifiedForm: displayAlertWhenLeavingModifiedForm,
displayAlertWhenLeavingUnsubmittedForm: displayAlertWhenLeavingUnsubmittedForm, displayAlertWhenLeavingUnsubmittedForm: displayAlertWhenLeavingUnsubmittedForm,
checkNullValuesInChoices: checkNullValuesInChoices, checkNullValuesInChoices: checkNullValuesInChoices,
categoryLinkParentChildSelect: categoryLinkParentChildSelect,
}; };
} (); } ();

View File

@ -167,6 +167,7 @@
chill.emulateSticky(); chill.emulateSticky();
chill.checkOtherValueOnChange(); chill.checkOtherValueOnChange();
$('.select2').select2({allowClear: true}); $('.select2').select2({allowClear: true});
chill.categoryLinkParentChildSelect();
</script> </script>
{% block js%}<!-- nothing added to js -->{% endblock %} {% block js%}<!-- nothing added to js -->{% endblock %}

View File

@ -164,12 +164,27 @@ class AuthorizationHelper
/** /**
* Return all reachable scope for a given user, center and role * Return all reachable scope for a given user, center and role
* *
* @deprecated Use getReachableCircles
*
* @param User $user * @param User $user
* @param Role $role * @param Role $role
* @param Center $center * @param Center $center
* @return Scope[] * @return Scope[]
*/ */
public function getReachableScopes(User $user, Role $role, Center $center) public function getReachableScopes(User $user, Role $role, Center $center)
{
return $this->getReachableCircles($user, $role, $center);
}
/**
* Return all reachable circle for a given user, center and role
*
* @param User $user
* @param Role $role
* @param Center $center
* @return Scope[]
*/
public function getReachableCircles(User $user, Role $role, Center $center)
{ {
$scopes = array(); $scopes = array();
@ -192,6 +207,8 @@ class AuthorizationHelper
return $scopes; return $scopes;
} }
/** /**
* Test if a parent role may give access to a given child role * Test if a parent role may give access to a given child role
* *