From 06ba35002a49b038d3dc535f1683d33dabcc0e56 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Wed, 8 Feb 2012 18:30:23 +0100 Subject: [PATCH] Add feedback user infos --- .../Phrasea/Controller/Prod/Language.php | 1 + www/prod/jquery.Dialog.js | 56 ++-- www/prod/jquery.Feedback.js | 290 +++++++++--------- 3 files changed, 173 insertions(+), 174 deletions(-) diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Language.php b/lib/Alchemy/Phrasea/Controller/Prod/Language.php index 1e85dc8062..2e16de288f 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Language.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Language.php @@ -92,6 +92,7 @@ class Language implements ControllerProviderInterface $out['listNameCannotBeEmpty'] = _('List name can not be empty'); $out['FeedBackName'] = _('Name'); $out['FeedBackMessage'] = _('Message'); + $out['send'] = _('Send'); $out['FeedBackNoUsersSelected'] = _('No users selected'); $Serializer = $app['Core']['Serializer']; diff --git a/www/prod/jquery.Dialog.js b/www/prod/jquery.Dialog.js index 343cad68aa..c43d251a15 100644 --- a/www/prod/jquery.Dialog.js +++ b/www/prod/jquery.Dialog.js @@ -3,7 +3,7 @@ var p4 = p4 || {}; ; (function(p4, $){ - + function getLevel (level) { level = parseInt(level); @@ -13,14 +13,14 @@ var p4 = p4 || {}; return 1; } - return level; + return level; }; - + function getId (level) { - return 'DIALOG' + getLevel(level); + return 'DIALOG' + getLevel(level); }; - + var phraseaDialog = function (options, level) { var createDialog = function(level) { @@ -38,7 +38,7 @@ var p4 = p4 || {}; return $dialog; } - var defaults = { + var defaults = { size : 'Medium', buttons : {}, loading : true, @@ -58,16 +58,16 @@ var p4 = p4 || {}; this.closing = false; this.options = $.extend(defaults, options); - + this.level = getLevel(level); if(this.options.closeButton === true) { - this.options.buttons[language.fermer] = this.Close; + this.options.buttons[language.fermer] = function() { $this.Close(); }; } if(this.options.cancelButton === true) { - this.options.buttons[language.annuler] = this.Close; + this.options.buttons[language.annuler] = function() { $this.Close(); }; } switch(this.options.size) @@ -89,11 +89,11 @@ var p4 = p4 || {}; /* * 3 avaailable dimensions : - * + * * - Full | Full size () * - Medium | 420 x 450 * - Small | 730 x 480 - * + * **/ this.$dialog = createDialog(this.level), zIndex = Math.min(this.level * 5000 + 5000, 32767); @@ -103,7 +103,7 @@ var p4 = p4 || {}; { $this.options.closeCallback($this.$dialog); } - + if($this.closing === false) { $this.closing = true; @@ -137,7 +137,7 @@ var p4 = p4 || {}; $(window).unbind('resize.DIALOG' + getLevel(level)) .bind('resize.DIALOG' + getLevel(level), function(){ $this.$dialog.dialog('option', { - width : bodySize.x - 30, + width : bodySize.x - 30, height : bodySize.y - 30 }); }); @@ -145,7 +145,7 @@ var p4 = p4 || {}; return this; }; - + phraseaDialog.prototype = { Close : function() { p4.Dialog.Close(this.level); @@ -166,12 +166,12 @@ var p4 = p4 || {}; this.$dialog.dialog('option', optionName, optionValue); } }; - + var Dialog = function () { this.currentStack = {}; }; - + Dialog.prototype = { Create : function(options, level) { @@ -179,40 +179,40 @@ var p4 = p4 || {}; { this.get(level).Close(); } - + $dialog = new phraseaDialog(options, level); - + this.currentStack[$dialog.getId()] = $dialog; - + return $dialog; }, get : function (level) { - + var id = getId(level); - + if(id in this.currentStack) { return this.currentStack[id]; } - + return null; }, Close : function (level) { - + $(window).unbind('resize.DIALOG' + getLevel(level)); - + this.get(level).closing = true; this.get(level).getDomElement().dialog('close').dialog('destroy').remove(); - + var id = this.get(level).getId(); - + if(id in this.currentStack) { delete this.currentStack.id; } } }; - + p4.Dialog = new Dialog(); - + }(p4, jQuery)); \ No newline at end of file diff --git a/www/prod/jquery.Feedback.js b/www/prod/jquery.Feedback.js index 16e07e9cd1..6479694745 100644 --- a/www/prod/jquery.Feedback.js +++ b/www/prod/jquery.Feedback.js @@ -1,26 +1,26 @@ ;(function(window){ - + var Feedback = function($container){ this.container = $($container); - + this.selection = new Selectable( - $('.user_content .badges', this.container), + $('.user_content .badges', this.container), { selector:'.badge' } ); - + var $this = this; - + $('.content .options .select-all', this.container).bind('click', function(){ $this.selection.selectAll(); }); $('.content .options .unselect-all', this.container).bind('click', function(){ $this.selection.empty(); }); - + $('a.user_adder', this.container).bind('click', function(){ @@ -63,104 +63,102 @@ return false; }); - + $('#PushBox form[name="FeedBackForm"]').bind('submit', function(){ - + var $this = $(this); - + $.ajax({ type: $this.attr('method'), url: $this.attr('action'), dataType: 'json', data: $this.serializeArray(), beforeSend:function(){ - + }, success: function(data){ - + if(data.success) + { + humane.info(data.message); + p4.Dialog.Close(1); + p4.WorkZone.refresh(); + } + else + { + humane.error(data.message); + } return; }, error: function(){ - + return; }, timeout: function(){ - + return; } }); return false; }); - + $('.FeedbackSend', this.container).bind('click', function(){ if($('.badges .badge', $container).length === 0) { alert(language.FeedBackNoUsersSelected); return; } - - if($('#FeedBackSendDialog').length == 0) - { - $('body').append(''); - } - - var $dialog = $('#FeedBackSendDialog'); - - $dialog.addClass('loading').dialog({ - buttons:{}, - draggable:false, - resizable:false, - modal:true, - closeOnEscape:true, - width:300, - height:400 - }).dialog( "moveToTop" ); - - var $FeedBackForm = $('form[name="FeedBackForm"]', $container); - + var buttons = {}; - - buttons[language.cancel] = function(){ - $dialog.dialog('destroy'); - $dialog.remove(); - }; + buttons[language.send] = function(){ - $dialog.dialog('destroy'); - $dialog.remove(); - + $dialog.Close(); + $('#PushBox form[name="FeedBackForm"]').trigger('submit'); - + $('input[name="name"]', $FeedBackForm).val($('input[name="name"]', $dialog).val()); $('textarea[name="message"]', $FeedBackForm).val($('textarea[name="message"]', $dialog).val()); }; - + + var options = { + size : 'Small', + buttons : buttons, + loading : true, + title : language.send, + closeOnEscape : true, + cancelButton : true + }; + + var $dialog = p4.Dialog.Create(options, 2); + + var $FeedBackForm = $('form[name="FeedBackForm"]', $container); + var callback = function(rendered){ - + $('input[name="name"]', rendered).val($('input[name="name"]', $FeedBackForm).val()); $('textarea[name="message"]', rendered).val($('textarea[name="message"]', $FeedBackForm).val()); - - $dialog.dialog('option', 'buttons', buttons).removeClass('loading').empty().append(rendered); + + $dialog.setContent(rendered); }; p4.Mustache.Render('Feedback-SendForm', { language:language }, callback); }).button(); - + $('.user_content .badges', this.container).disableSelection(); - + $('.user_content .badges .badge .toggle', this.container).live('click', function(event){ var $this = $(this); $this.toggleClass('status_off status_on'); $this.find('input').val($this.hasClass('status_on') ? '1' : '0'); - + return false; }); - + $('.general_togglers .general_toggler', this.container).bind('click', function(){ var feature = $(this).attr('feature'); - + var $badges = $('.user_content .badge.selected', this.container); - + var toggles = $('.status_off.toggle_' + feature, $badges); if(toggles.length == 0) @@ -174,7 +172,7 @@ toggles.trigger('click'); return false; }); - + $('.user_content .badges .badge .deleter', this.container).live('click', function(event){ var $elem = $(this).closest('.badge'); $elem.fadeOut(function(){$elem.remove();}); @@ -188,21 +186,21 @@ }); $('.options button', this.container).button(); - + $('form.list_saver', this.container).bind('submit', function(){ var $form = $(this); var $input = $('input[name="name"]', $form); - + var users = p4.Feedback.getUsers(); - + if(users.length == 0) { humane.error('No users'); return false; } - + p4.Lists.create($input.val(), function(list){$input.val('');list.addUsers(users);}); - + return false; }); @@ -236,9 +234,9 @@ } }) .data( "autocomplete" )._renderItem = function( ul, item ) { - + var autocompleter = $('input[name="users-search"]', $this.container); - + autocompleter.addClass('loading'); var callback = function(datas){ @@ -247,7 +245,7 @@ autocompleter.data('autocomplete')._resizeMenu(); autocompleter.removeClass('loading'); }; - + if(item.type == 'USER') { var datas = p4.Mustache.Render('List-User-Item', item, callback); @@ -256,13 +254,13 @@ { var datas = p4.Mustache.Render('List-List-Item', item, callback); } - + return; }; - + return this; }; - + Feedback.prototype = { selectUser : function(user){ if(typeof user !== 'object') @@ -277,14 +275,14 @@ humane.info('User already selected'); return; } - + p4.Mustache.Render('Feedback-Badge', user, p4.Feedback.appendBadge); }, appendBadge : function(badge){ $('.user_content .badges', this.container).append(badge); }, addUser : function($form, callback){ - + var $this = this; $.ajax({ type: 'POST', @@ -314,22 +312,22 @@ }); } }; - - - + + + var ListManager = function($container) { - + this.list = null; this.container = $container; - + $('.back_link', this.container).bind('click', function(){ $('#PushBox').show(); $('#ListManager').hide(); return false; }); - - - + + + $('a.user_adder', this.container).bind('click', function(){ var $this = $(this); @@ -371,62 +369,62 @@ return false; }); - - - + + + var initLeft = function() { $('a.list_refresh', $container).bind('click', function(event){ - var callback = function(datas){ + var callback = function(datas){ $('.all-lists', $container).removeClass('loading').append(datas); - initLeft(); + initLeft(); }; - - $('.all-lists', $container).empty().addClass('loading'); - + + $('.all-lists', $container).empty().addClass('loading'); + p4.Lists.get(callback, 'html'); return false; }); - + var ListDeleterDialogBox = function(callbackDeleter) { if($('#ListDeleterDialogBox').length > 0) { $('#ListDeleterDialogBox').remove(); } - + $('body').append('
'); - - var callbackMustache = function(datas){ + + var callbackMustache = function(datas){ $('#ListDeleterDialogBox').append(datas); callbackDeleter($('#ListDeleterDialogBox')); }; - + p4.Mustache.Render('ListEditor-DialogDelete', language, callbackMustache); - + return false; }; - - + + $('a.deleter', $container).bind('click', function(event){ - + var list_id = $(this).find('input[name=list_id]').val(); - + var makeDialog = function (box) { - + var buttons = {}; - + buttons[language.create] = function() { - - var callbackOK = function () { - $('a.list_refresh', $container).trigger('click'); - box.dialog('close'); + + var callbackOK = function () { + $('a.list_refresh', $container).trigger('click'); + box.dialog('close'); }; - + var List = new document.List(list_id); List.remove(callbackOK); }; - + box.dialog({ buttons:buttons, modal:true, @@ -436,54 +434,54 @@ height:150 }); }; - + ListDeleterDialogBox(makeDialog); return false; }); - + var ListAdderDialogBox = function(callbackAdder) { if($('#ListAdderDialogBox').length > 0) { $('#ListAdderDialogBox').remove(); } - + $('body').append('
'); - - var callbackMustache = function(datas){ + + var callbackMustache = function(datas){ $('#ListAdderDialogBox').append(datas); callbackAdder($('#ListAdderDialogBox')); }; - + p4.Mustache.Render('ListEditor-DialogAdd', language, callbackMustache); - + return false; }; - + $('a.list_adder', $container).bind('click', function(event){ - + var makeDialog = function (box) { - + var buttons = {}; - + buttons[language.valider] = function() { - - var callbackOK = function () { - $('a.list_refresh', $container).trigger('click'); - box.dialog('close'); + + var callbackOK = function () { + $('a.list_refresh', $container).trigger('click'); + box.dialog('close'); }; - + var name = $('#ListAdderDialogBox input[name="name"]').val(); - + if($.trim(name) === '') { alert(language.listNameCannotBeEmpty); return; } - + p4.Lists.create(name, callbackOK); }; - + box.dialog({ buttons:buttons, modal:true, @@ -493,12 +491,12 @@ height:150 }); }; - + ListAdderDialogBox(makeDialog); return false; }); - + $('li.list a.link', $container).bind('click', function(event){ var $this = $(this); @@ -521,11 +519,11 @@ return false; }); - + }; - + var initRight = function(){ - + var $container = this.container; $('form[name="list-editor-search"]', this.container).bind('submit', function(){ @@ -548,14 +546,14 @@ }); return false; }); - + $('form[name="list-editor-search"] select', this.container).bind('change', function(){ $(this).closest('form').trigger('submit'); }); - - - -// + + + +// // $('.editor input[name="list-add-user"]', this.container).autocomplete({ // minLength: 2, // source: function( request, response ) { @@ -610,31 +608,31 @@ // }; }; - + initLeft(); - + $('.badges a.deleter', this.container).live('click', function(){ var badge = $(this).closest('.badge'); - + var usr_id = badge.find('input[name="id"]').val(); - - - var callback = function(list, datas){ + + + var callback = function(list, datas){ $('.counter.current, .list.selected .counter', $('#ListManager')).each(function(){ $(this).text(parseInt($(this).text()) - 1); }); - - badge.remove(); + + badge.remove(); }; - + p4.ListManager.getList().removeUser(usr_id, callback); - + return false; }); - + }; - + ListManager.prototype = { workOn : function(list_id) { this.list = new document.List(list_id); @@ -646,10 +644,10 @@ $('#ListManager .badges').append(datas); } }; - - - + + + window.Feedback = Feedback; window.ListManager = ListManager; - + }(window)); \ No newline at end of file