Add dedicated route for user preferences

This commit is contained in:
Romain Neutron
2012-02-09 16:57:16 +01:00
parent 6dea14b12e
commit ba91eddb39
7 changed files with 129 additions and 76 deletions

View File

@@ -29,6 +29,7 @@ rewrite ^/prod/baskets/.*$ /prod/router.php last;
rewrite ^/prod/story/.*$ /prod/router.php last; rewrite ^/prod/story/.*$ /prod/router.php last;
rewrite ^/prod/WorkZone/.*$ /prod/router.php last; rewrite ^/prod/WorkZone/.*$ /prod/router.php last;
rewrite ^/prod/language/.*$ /prod/router.php last; rewrite ^/prod/language/.*$ /prod/router.php last;
rewrite ^/prod/UserPreferences/.*$ /prod/router.php last;
rewrite ^/prod/$ /prod/router.php last; rewrite ^/prod/$ /prod/router.php last;
rewrite ^/robots.txt$ /index.php last; rewrite ^/robots.txt$ /index.php last;

View File

@@ -39,6 +39,7 @@ return call_user_func(function()
); );
}); });
$app->mount('/UserPreferences/', new Controller\UserPreferences());
$app->mount('/baskets', new Controller\Basket()); $app->mount('/baskets', new Controller\Basket());
$app->mount('/story', new Controller\Story()); $app->mount('/story', new Controller\Story());
$app->mount('/WorkZone', new Controller\WorkZone()); $app->mount('/WorkZone', new Controller\WorkZone());

View File

@@ -0,0 +1,69 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Controller\Prod;
use Silex\Application,
Silex\ControllerProviderInterface,
Silex\ControllerCollection;
use Symfony\Component\HttpFoundation\Request,
Symfony\Component\HttpFoundation\Response,
Symfony\Component\HttpFoundation\RedirectResponse,
Symfony\Component\HttpKernel\Exception\HttpException,
Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Alchemy\Phrasea\RouteProcessor\Basket as BasketRoute,
Alchemy\Phrasea\Helper;
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class UserPreferences implements ControllerProviderInterface
{
public function connect(Application $app)
{
$controllers = new ControllerCollection();
$controllers->post('/save/', function(Application $app, Request $request)
{
$ret = array('success' => false, 'message' => _('Error while saving preference'));
try
{
$user = $app['Core']->getAuthenticatedUser();
$ret = $user->setPrefs($request->get('prop'), $request->get('value'));
if ($ret == $request->get('value'))
$output = "1";
else
$output = "0";
$ret = array('success' => true, 'message' => _('Preference saved !'));
}
catch (\Exception $e)
{
}
$Serializer = $app['Core']['Serializer'];
$datas = $Serializer->serialize($ret, 'json');
return new Response($datas, 200, array('Content-Type' => 'application/json'));
});
return $controllers;
}
}

View File

@@ -1487,9 +1487,10 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
{ {
$this->load_preferences(); $this->load_preferences();
if (isset($this->_prefs[$prop]) && $this->_prefs[$prop] === $value) if (isset($this->_prefs[$prop]) && $this->_prefs[$prop] === $value)
{
return $value; return $this->_prefs[$prop];
}
$ok = true; $ok = true;
if (isset(self::$available_values[$prop])) if (isset(self::$available_values[$prop]))

View File

@@ -20,6 +20,7 @@
RewriteRule ^prod/records/edit/.*$ /prod/router.php [L] RewriteRule ^prod/records/edit/.*$ /prod/router.php [L]
RewriteRule ^prod/records/movecollection/.*$ /prod/router.php [L] RewriteRule ^prod/records/movecollection/.*$ /prod/router.php [L]
RewriteRule ^prod/UserPreferences/.*$ /prod/router.php [L]
RewriteRule ^prod/bridge/.*$ /prod/router.php [L] RewriteRule ^prod/bridge/.*$ /prod/router.php [L]
RewriteRule ^prod/MustacheLoader/.*$ /prod/router.php [L] RewriteRule ^prod/MustacheLoader/.*$ /prod/router.php [L]
RewriteRule ^prod/feeds/.*$ /prod/router.php [L] RewriteRule ^prod/feeds/.*$ /prod/router.php [L]
@@ -64,7 +65,7 @@
<IfModule mod_h264_streaming.c> <IfModule mod_h264_streaming.c>
RewriteRule ^admin/test-h264$ admin/adminFeedback.php?action=APACHE&test=success [L] RewriteRule ^admin/test-h264$ admin/adminFeedback.php?action=APACHE&test=success [L]
</IfModule> </IfModule>
RewriteRule ^admin/test-rewrite$ admin/adminFeedback.php?action=APACHE&test=fail [L] RewriteRule ^admin/test-rewrite$ admin/adminFeedback.php?action=APACHE&test=fail [L]
RewriteRule ^admin/test-xsendfile$ admin/adminFeedback.php?action=APACHE&test=fail [L] RewriteRule ^admin/test-xsendfile$ admin/adminFeedback.php?action=APACHE&test=fail [L]
RewriteRule ^admin/test-authtoken$ admin/adminFeedback.php?action=APACHE&test=fail [L] RewriteRule ^admin/test-authtoken$ admin/adminFeedback.php?action=APACHE&test=fail [L]

View File

@@ -6,14 +6,14 @@ $(document).ready(function(){
function(){$(this).removeClass('hover');} function(){$(this).removeClass('hover');}
); );
var locale = $.cookie('locale'); var locale = $.cookie('locale');
var jq_date = p4.lng = locale !== null ? locale.split('_').reverse().pop() : 'en'; var jq_date = p4.lng = locale !== null ? locale.split('_').reverse().pop() : 'en';
if(jq_date == 'en') if(jq_date == 'en')
{ {
jq_date = 'en-GB'; jq_date = 'en-GB';
} }
$.datepicker.setDefaults({showMonthAfterYear: false}); $.datepicker.setDefaults({showMonthAfterYear: false});
$.datepicker.setDefaults($.datepicker.regional[jq_date]); $.datepicker.setDefaults($.datepicker.regional[jq_date]);
@@ -23,7 +23,7 @@ $(document).ready(function(){
var cache = $('#mainMenu .helpcontextmenu'); var cache = $('#mainMenu .helpcontextmenu');
$('.context-menu-item',cache).hover(function(){$(this).addClass('context-menu-item-hover');},function(){$(this).removeClass('context-menu-item-hover');}); $('.context-menu-item',cache).hover(function(){$(this).addClass('context-menu-item-hover');},function(){$(this).removeClass('context-menu-item-hover');});
$('#help-trigger').contextMenu('#mainMenu .helpcontextmenu',{openEvt:'click',dropDown:true,theme:'vista', dropDown:true, $('#help-trigger').contextMenu('#mainMenu .helpcontextmenu',{openEvt:'click',dropDown:true,theme:'vista', dropDown:true,
showTransition:'slideDown', showTransition:'slideDown',
hideTransition:'hide', hideTransition:'hide',
@@ -42,14 +42,14 @@ $(document).ready(function(){
else else
{ {
box.show(); box.show();
fix_notification_height(); fix_notification_height();
$(this).addClass('open'); $(this).addClass('open');
read_notifications(); read_notifications();
} }
}); });
$(this).bind('mousedown',function(){ $(this).bind('mousedown',function(){
var not_trigger = $('#notification_trigger'); var not_trigger = $('#notification_trigger');
if(not_trigger.hasClass('open')) if(not_trigger.hasClass('open'))
@@ -58,12 +58,12 @@ $(document).ready(function(){
$('#notification_box').bind('mousedown',function(event){ $('#notification_box').bind('mousedown',function(event){
event.stopPropagation(); event.stopPropagation();
}); });
$('#notification_box div.notification').live('mouseover',function(){$(this).addClass('hover');}); $('#notification_box div.notification').live('mouseover',function(){$(this).addClass('hover');});
$('#notification_box div.notification').live('mouseout',function(){$(this).removeClass('hover');}); $('#notification_box div.notification').live('mouseout',function(){$(this).removeClass('hover');});
$(this).bind('mousedown',function(){ $(this).bind('mousedown',function(){
var box = $('#notification_box'); var box = $('#notification_box');
if($('#notification_trigger').hasClass('open')) if($('#notification_trigger').hasClass('open'))
@@ -73,10 +73,10 @@ $(document).ready(function(){
clear_notifications(); clear_notifications();
} }
}); });
set_notif_position(); set_notif_position();
}); });
@@ -116,11 +116,11 @@ function fix_notification_height()
var n = not.length; var n = not.length;
var not_t = $('.notification_title',box); var not_t = $('.notification_title',box);
var n_t = not_t.length; var n_t = not_t.length;
h = not.outerHeight() * n + not_t.outerHeight() * n_t; h = not.outerHeight() * n + not_t.outerHeight() * n_t;
h = h > 350 ? 350 : h; h = h > 350 ? 350 : h;
box.stop().animate({height:h}); box.stop().animate({height:h});
} }
function set_notif_position() function set_notif_position()
@@ -149,7 +149,7 @@ function print_notifications(page)
if($('#notifications-dialog').length === 0) if($('#notifications-dialog').length === 0)
$('body').append('<div id="notifications-dialog" class="loading"></div>'); $('body').append('<div id="notifications-dialog" class="loading"></div>');
$('#notifications-dialog') $('#notifications-dialog')
.dialog({ .dialog({
title:language.notifications, title:language.notifications,
@@ -170,7 +170,7 @@ function print_notifications(page)
} }
}).dialog('option','buttons',buttons) }).dialog('option','buttons',buttons)
.dialog('open'); .dialog('open');
$.ajax({ $.ajax({
type: "POST", type: "POST",
@@ -194,7 +194,7 @@ function print_notifications(page)
cont.empty(); cont.empty();
else else
$('.notification_next',cont).remove(); $('.notification_next',cont).remove();
for (i in data.notifications) for (i in data.notifications)
{ {
var id = 'notif_date_'+i; var id = 'notif_date_'+i;
@@ -219,14 +219,14 @@ function print_notifications(page)
date_cont.append(html); date_cont.append(html);
} }
} }
var next_ln = $.trim(data.next); var next_ln = $.trim(data.next);
if(next_ln !== '') if(next_ln !== '')
{ {
cont.append('<div class="notification_next">'+next_ln+'</div>'); cont.append('<div class="notification_next">'+next_ln+'</div>');
} }
// '<div style="position:relative;" id="notification_'.$row['id'].'" class="notification '.($row['unread'] == '1' ? 'unread':'').'">'. // '<div style="position:relative;" id="notification_'.$row['id'].'" class="notification '.($row['unread'] == '1' ? 'unread':'').'">'.
// '<table style="width:100%;" cellspacing="0" cellpadding="0" border="0"><tr><td style="width:25px;">'. // '<table style="width:100%;" cellspacing="0" cellpadding="0" border="0"><tr><td style="width:25px;">'.
// '<img src="'.$this->pool_classes[$row['type']]->icon_url().'" style="vertical-align:middle;width:16px;margin:2px;" />'. // '<img src="'.$this->pool_classes[$row['type']]->icon_url().'" style="vertical-align:middle;width:16px;margin:2px;" />'.
@@ -235,21 +235,21 @@ function print_notifications(page)
// $data['text'].' <span class="time"></span></div>'. // $data['text'].' <span class="time"></span></div>'.
// '</td></tr></table>'. // '</td></tr></table>'.
// '</div>' // '</div>'
} }
}); });
} }
function read_notifications() function read_notifications()
{ {
var notifications = []; var notifications = [];
$('#notification_box .unread').each(function(){ $('#notification_box .unread').each(function(){
notifications.push($(this).attr('id').split('_').pop()); notifications.push($(this).attr('id').split('_').pop());
}); });
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: "/prod/prodFeedBack.php", url: "/prod/prodFeedBack.php",
@@ -266,10 +266,10 @@ function read_notifications()
function clear_notifications() function clear_notifications()
{ {
var unread = $('#notification_box .unread'); var unread = $('#notification_box .unread');
if(unread.length === 0) if(unread.length === 0)
return; return;
unread.removeClass('unread'); unread.removeClass('unread');
$('#notification_trigger .counter').css('visibility','hidden').empty(); $('#notification_trigger .counter').css('visibility','hidden').empty();
} }
@@ -282,7 +282,7 @@ function clear_notifications()
function getMyRss(renew) function getMyRss(renew)
{ {
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: "/prod/prodFeedBack.php", url: "/prod/prodFeedBack.php",
@@ -291,7 +291,7 @@ function getMyRss(renew)
success: function(data){ success: function(data){
} }
}); });
} }
function setPref(name,value) function setPref(name,value)
@@ -304,12 +304,13 @@ function setPref(name,value)
jQuery.data['pref_'+name] = $.ajax({ jQuery.data['pref_'+name] = $.ajax({
type: "POST", type: "POST",
url: "/prod/prodFeedBack.php", url: "/prod/UserPreferences/save/",
data: { data: {
action: "SAVEPREF", action: "SAVEPREF",
prop:name, prop:name,
value:value value:value
}, },
dataType:'json',
timeout: function(){ timeout: function(){
jQuery.data['pref_'+name] = false; jQuery.data['pref_'+name] = false;
}, },
@@ -317,6 +318,14 @@ function setPref(name,value)
jQuery.data['pref_'+name] = false; jQuery.data['pref_'+name] = false;
}, },
success: function(data){ success: function(data){
if(data.success)
{
humane.info(data.message);
}
else
{
humane.error(data.message);
}
jQuery.data['pref_'+name] = false; jQuery.data['pref_'+name] = false;
return; return;
} }
@@ -349,7 +358,7 @@ function manageSession(data, showMessages)
{ {
if(typeof(showMessages) == "undefined") if(typeof(showMessages) == "undefined")
showMessages = false; showMessages = false;
if(data.status == 'disconnected' || data.status == 'session') if(data.status == 'disconnected' || data.status == 'session')
{ {
disconnected(); disconnected();
@@ -359,10 +368,10 @@ function manageSession(data, showMessages)
{ {
var box = $('#notification_box'); var box = $('#notification_box');
box.empty().append(data.notifications); box.empty().append(data.notifications);
if(box.is(':visible')) if(box.is(':visible'))
fix_notification_height(); fix_notification_height();
if($('.notification.unread',box).length > 0) if($('.notification.unread',box).length > 0)
{ {
var trigger = $('#notification_trigger') ; var trigger = $('#notification_trigger') ;
@@ -370,7 +379,7 @@ function manageSession(data, showMessages)
.empty() .empty()
.append($('.notification.unread',box).length); .append($('.notification.unread',box).length);
$('.counter',trigger).css('visibility','visible'); $('.counter',trigger).css('visibility','visible');
} }
else else
$('#notification_trigger .counter').css('visibility','hidden').empty(); $('#notification_trigger .counter').css('visibility','hidden').empty();
@@ -437,7 +446,7 @@ function disconnected()
} }
function showModal(cas, options){ function showModal(cas, options){
var content = ''; var content = '';
var callback = null; var callback = null;
var button = { var button = {
@@ -449,7 +458,7 @@ function showModal(cas, options){
}}; }};
var escape = true; var escape = true;
var onClose = function(){}; var onClose = function(){};
switch (cas) { switch (cas) {
case 'timeout': case 'timeout':
content = language.serverTimeout; content = language.serverTimeout;
@@ -465,9 +474,9 @@ function showModal(cas, options){
default: default:
break; break;
} }
p4.Alerts(options.title, content, callback); p4.Alerts(options.title, content, callback);
return; return;
} }
@@ -482,7 +491,7 @@ function showOverlay(n,appendto,callback, zIndex){
appendto = 'body'; appendto = 'body';
$(appendto).append('<div id="'+div+'" style="display:none;">&nbsp;</div>'); $(appendto).append('<div id="'+div+'" style="display:none;">&nbsp;</div>');
} }
var css = { var css = {
display: 'block', display: 'block',
opacity: 0, opacity: 0,
@@ -493,10 +502,10 @@ function showOverlay(n,appendto,callback, zIndex){
zIndex:zIndex, zIndex:zIndex,
left:0 left:0
}; };
if(parseInt(zIndex) > 0) if(parseInt(zIndex) > 0)
css['zIndex'] = parseInt(zIndex); css['zIndex'] = parseInt(zIndex);
if(typeof(callback) != 'function') if(typeof(callback) != 'function')
callback = function(){}; callback = function(){};
$('#'+div).css(css).addClass('overlay').fadeTo(500, 0.7).bind('click',function(){(callback)();}); $('#'+div).css(css).addClass('overlay').fadeTo(500, 0.7).bind('click',function(){(callback)();});

View File

@@ -71,30 +71,6 @@ switch ($action)
$parm = $request->get_parms('color'); $parm = $request->get_parms('color');
$output = $user->setPrefs('css', $color); $output = $user->setPrefs('css', $color);
break; break;
case 'MYRSS':
require ($registry->get('GV_RootPath') . 'lib/classes/deprecated/prodUtils.php');
$parm = $request->get_parms('renew');
$url = $user->get_protected_rss_url(($parm['renew'] === 'true'))->get_url();
$output = p4string::jsonencode(
array(
'texte' => '<p>' . _('publication::Voici votre fil RSS personnel. Il vous permettra d\'etre tenu au courrant des publications.')
. '</p><p>' . _('publications::Ne le partagez pas, il est strictement confidentiel') . '</p>
<div><input type="text" style="width:100%" value="' . $url . '"/></div>',
'titre' => _('publications::votre rss personnel')
)
);
break;
case 'SAVEPREF':
$parm = $request->get_parms('prop', 'value');
$ret = $user->setPrefs($parm['prop'], $parm['value']);
if (isset($ret[$parm['prop']]) && $ret[$parm['prop']] = $parm['value'])
$output = "1";
else
$output = "0";
break;
case 'SAVETEMPPREF': case 'SAVETEMPPREF':
$parm = $request->get_parms('prop', 'value'); $parm = $request->get_parms('prop', 'value');
@@ -113,11 +89,6 @@ switch ($action)
$output = deleteRecord($parm['lst'], $parm['del_children']); $output = deleteRecord($parm['lst'], $parm['del_children']);
break; break;
case 'MAIL_REQ':
$parm = $request->get_parms('user', 'contrib', 'message', 'query');
$output = query_phrasea::mail_request($parm['user'], $parm['contrib'], $parm['message'], $parm['query']);
break;
case 'DENY_CGU': case 'DENY_CGU':
$parm = $request->get_parms('sbas_id'); $parm = $request->get_parms('sbas_id');
$output = databox_cgu::denyCgus($parm['sbas_id']); $output = databox_cgu::denyCgus($parm['sbas_id']);