Add method to laod a list

This commit is contained in:
Romain Neutron
2012-02-14 16:09:04 +01:00
parent 736f05ff94
commit 06449896d3
3 changed files with 61 additions and 74 deletions

View File

@@ -455,65 +455,8 @@ class Push implements ControllerProviderInterface
}
);
$controllers->get('/search-user/', function(Application $app)
$controllers->get('/user/{usr_id}/', function(Application $app, $usr_id) use ($userFormatter)
{
$request = $app['request'];
$em = $app['Core']->getEntityManager();
$user = $app['Core']->getAuthenticatedUser();
$query = new \User_Query(\appbox::get_instance());
$query->on_bases_where_i_am($user->ACL(), array('canpush'));
$query->like(\User_Query::LIKE_FIRSTNAME, $request->get('query'))
->like(\User_Query::LIKE_LASTNAME, $request->get('query'))
->like(\User_Query::LIKE_LOGIN, $request->get('query'))
->like_match(\User_Query::LIKE_MATCH_OR);
$result = $query->include_phantoms()
->limit(0, 50)
->execute()->get_results();
$repository = $em->getRepository('\Entities\UsrList');
$lists = $repository->findUserListLike($user, $request->get('query'));
$datas = array();
if ($lists)
{
foreach ($lists as $list)
{
$datas[] = array(
'type' => 'LIST'
, 'name' => $list->getName()
, 'quantity' => $list->getUsers()->count()
);
}
}
if ($result)
{
foreach ($result as $user)
{
$datas[] = array(
'type' => 'USER'
, 'usr_id' => $user->get_id()
, 'firstname' => $user->get_firstname()
, 'lastname' => $user->get_lastname()
, 'email' => $user->get_email()
, 'display_name' => $user->get_display_name()
);
}
}
$Json = $app['Core']['Serializer']->serialize($datas, 'json');
return new Response($Json, 200, array('Content-Type' => 'application/json'));
}
);
$controllers->get('/load-user/', function(Application $app){
$datas = null;
@@ -525,7 +468,7 @@ class Push implements ControllerProviderInterface
$query->on_bases_where_i_am($user->ACL(), array('canpush'));
$query->in(array($request->get('usr_id')));
$query->in(array($usr_id));
$result = $query->include_phantoms()
->limit(0, 1)
@@ -535,21 +478,35 @@ class Push implements ControllerProviderInterface
{
foreach ($result as $user)
{
$datas = array(
'type' => 'USER'
, 'usr_id' => $user->get_id()
, 'firstname' => $user->get_firstname()
, 'lastname' => $user->get_lastname()
, 'email' => $user->get_email()
, 'display_name' => $user->get_display_name()
);
$datas = $userFormatter($user);
}
}
$Json = $app['Core']['Serializer']->serialize($datas, 'json');
return new Response($Json, 200, array('Content-Type' => 'application/json'));
});
})->assert('usr_id', '\d+');
$controllers->get('/list/{list_id}/', function(Application $app, $list_id) use ($listFormatter)
{
$datas = null;
$em = $app['Core']->getEntityManager();
$user = $app['Core']->getAuthenticatedUser();
$repository = $em->getRepository('\Entities\UsrList');
$list = $repository->findUserListByUserAndId($user, $list_id);
if ($list)
{
$datas = $listFormatter($list);
}
$Json = $app['Core']['Serializer']->serialize($datas, 'json');
return new Response($Json, 200, array('Content-Type' => 'application/json'));
})->assert('list_id', '\d+');
$controllers->post('/add-user/', function(Application $app, Request $request) use ($userFormatter)
{

View File

@@ -44,7 +44,7 @@
<ul>
{% for list in lists %}
<li>
<a href="#" class="list_loader" href="/prod/push/lists/list/{{ list.getId() }}/">
<a class="list_loader" href="/prod/push/list/{{ list.getId() }}/">
{% if list.getOwner(user).getRole() >= constant('\\Entities\\UsrListOwner::ROLE_EDITOR') %}
<img src="/skins/prod/Push/list-icon.png" />
{% else %}

View File

@@ -242,6 +242,21 @@
return false;
});
$('a.list_loader', this.container).bind('click', function(){
var url = $(this).attr('href');
var callbackList = function(list){
for(i in list.entries)
{
this.selectUser(list.entries[i].User);
}
}
$this.loadList(url, callbackList)
return false;
});
$('.options button', this.container).button();
$('form.list_saver', this.container).bind('submit', function(){
@@ -345,7 +360,7 @@
$.ajax({
type: 'GET',
url: '/prod/push/load-user/',
url: '/prod/push/user/' + usr_id + '/',
dataType: 'json',
data: {usr_id : usr_id},
success: function(data){
@@ -356,6 +371,21 @@
}
});
},
loadList : function(url, callback) {
var $this = this;
$.ajax({
type: 'GET',
url: url,
dataType: 'json',
success: function(data){
if(typeof callback === 'function')
{
callback.call($this, data);
}
}
});
},
appendBadge : function(badge){
$('.user_content .badges', this.container).append(badge);
},