From 2b38a7ddd6d4717a476c9c93905f067d84030bad Mon Sep 17 00:00:00 2001 From: Antonin Date: Tue, 13 Oct 2015 01:03:41 +0200 Subject: [PATCH 1/5] Refactoring NotificationService --- adminstuds.php | 45 +--------- .../Services/NotificationService.php | 86 +++++++++++++++++++ studs.php | 54 ++---------- 3 files changed, 95 insertions(+), 90 deletions(-) create mode 100644 app/classes/Framadate/Services/NotificationService.php diff --git a/adminstuds.php b/adminstuds.php index 3f30a41..5315422 100644 --- a/adminstuds.php +++ b/adminstuds.php @@ -23,15 +23,11 @@ use Framadate\Services\InputService; use Framadate\Services\LogService; use Framadate\Services\MailService; use Framadate\Services\PollService; +use Framadate\Services\NotificationService; use Framadate\Utils; include_once __DIR__ . '/app/inc/init.php'; -/* Constants */ -/* --------- */ -const UPDATE_POLL = 1; -const DELETED_POLL = 2; - /* Variables */ /* --------- */ @@ -49,40 +45,7 @@ $pollService = new PollService($connect, $logService); $adminPollService = new AdminPollService($connect, $pollService, $logService); $inputService = new InputService(); $mailService = new MailService($config['use_smtp']); - -/* Functions */ -/*-----------*/ - -/** - * Send a notification to the poll admin to notify him about an update. - * - * @param stdClass $poll The poll - * @param MailService $mailService The mail service - * @param int $type cf: Constants on the top of this page - */ -function sendUpdateNotification($poll, $mailService, $type) { - if (!isset($_SESSION['mail_sent'])) { - $_SESSION['mail_sent'] = []; - } - - if ($poll->receiveNewVotes) { - - $subject = '[' . NOMAPPLICATION . '] ' . __f('Mail', 'Notification of poll: %s', $poll->title); - - $message = ''; - switch ($type) { - case UPDATE_POLL: - $message = __f('Mail', 'Someone just change your poll available at the following link %s.', Utils::getUrlSondage($poll->admin_id, true)) . "\n\n"; - break; - case DELETED_POLL: - $message = __f('Mail', 'Someone just delete your poll %s.', Utils::htmlEscape($poll->title)) . "\n\n"; - break; - } - - $messageTypeKey = $type . '-' . $poll->id; - $mailService->send($poll->admin_mail, $subject, $message, $messageTypeKey); - } -} +$notificationService = new NotificationService($mailService); /* PAGE */ /* ---- */ @@ -176,7 +139,7 @@ if (isset($_POST['update_poll_info'])) { // Update poll in database if ($updated && $adminPollService->updatePoll($poll)) { $message = new Message('success', __('adminstuds', 'Poll saved')); - sendUpdateNotification($poll, $mailService, UPDATE_POLL); + $notificationService->sendUpdateNotification($poll, $notificationService::UPDATE_POLL); } else { $message = new Message('danger', __('Error', 'Failed to save poll')); $poll = $pollService->findById($poll_id); @@ -341,7 +304,7 @@ if (isset($_POST['delete_poll'])) { if (isset($_POST['confirm_delete_poll'])) { if ($adminPollService->deleteEntirePoll($poll_id)) { $message = new Message('success', __('adminstuds', 'Poll fully deleted')); - sendUpdateNotification($poll, $mailService, DELETED_POLL); + $notificationService->sendUpdateNotification($poll, $notificationService::DELETED_POLL); } else { $message = new Message('danger', __('Error', 'Failed to delete the poll')); } diff --git a/app/classes/Framadate/Services/NotificationService.php b/app/classes/Framadate/Services/NotificationService.php new file mode 100644 index 0000000..7944c7f --- /dev/null +++ b/app/classes/Framadate/Services/NotificationService.php @@ -0,0 +1,86 @@ +mailService = $mailService; + } + + /** + * Send a notification to the poll admin to notify him about an update. + * + * @param $poll stdClass The poll + * @param $name string The name user who triggered the notification + * @param $type int cf: Constants on the top of this page + */ + function sendUpdateNotification(stdClass $poll, $type, $name='') { + if (!isset($_SESSION['mail_sent'])) { + $_SESSION['mail_sent'] = []; + } + + if ($poll->receiveNewVotes) { + + if (self::isParticipation($type)) + $translationString = 'Poll\'s participation: %s'; + else + $translationString = 'Notification of poll: %s'; + + $subject = '[' . NOMAPPLICATION . '] ' . __f('Mail', $translationString, $poll->title); + + + $message = ''; + if (self::isParticipation($type)) + $message .= $name . ' '; + + $urlSondage = Utils::getUrlSondage($poll->admin_id, true); + $link = '' . $urlSondage . '' . "\n\n"; + + switch ($type) { + case self::UPDATE_VOTE: + $message .= __('Mail', "updated a vote.\nYou can find your poll at the link") . " :\n\n"; + $message .= $link; + break; + case self::ADD_VOTE: + $message .= __('Mail', "filled a vote.\nYou can find your poll at the link") . " :\n\n"; + $message .= $link; + break; + case self::ADD_COMMENT: + $message .= __('Mail', "wrote a comment.\nYou can find your poll at the link") . " :\n\n"; + $message .= $link; + break; + case self::UPDATE_POLL: + $message = __f('Mail', 'Someone just change your poll available at the following link %s.', Utils::getUrlSondage($poll->admin_id, true)) . "\n\n"; + break; + case self::DELETED_POLL: + $message = __f('Mail', 'Someone just delete your poll %s.', Utils::htmlEscape($poll->title)) . "\n\n"; + break; + + } + + $messageTypeKey = $type . '-' . $poll->id; + $this->mailService->send($poll->admin_mail, $subject, $message, $messageTypeKey); + } + } + + function isParticipation($type) + { + return $type >= self::UPDATE_POLL; + } + +} \ No newline at end of file diff --git a/studs.php b/studs.php index 52b9096..661b1e0 100644 --- a/studs.php +++ b/studs.php @@ -20,18 +20,13 @@ use Framadate\Services\LogService; use Framadate\Services\PollService; use Framadate\Services\InputService; use Framadate\Services\MailService; +use Framadate\Services\NotificationService; use Framadate\Message; use Framadate\Utils; use Framadate\Editable; include_once __DIR__ . '/app/inc/init.php'; -/* Constants */ -/* --------- */ -const UPDATE_VOTE = 1; -const ADD_VOTE = 2; -const ADD_COMMENT = 3; - /* Variables */ /* --------- */ @@ -47,46 +42,8 @@ $logService = new LogService(); $pollService = new PollService($connect, $logService); $inputService = new InputService(); $mailService = new MailService($config['use_smtp']); +$notificationService = new NotificationService($mailService); -/* Functions */ -/*-----------*/ - -/** - * Send a notification to the poll admin to notify him about an update. - * - * @param $poll stdClass The poll - * @param $mailService MailService The mail service - * @param $name string The name user who triggered the notification - * @param $type int cf: Constants on the top of this page - */ -function sendUpdateNotification($poll, $mailService, $name, $type) { - if (!isset($_SESSION['mail_sent'])) { - $_SESSION['mail_sent'] = []; - } - - if ($poll->receiveNewVotes) { - - $subject = '[' . NOMAPPLICATION . '] ' . __f('Mail', 'Poll\'s participation: %s', $poll->title); - - $message = $name . ' '; - switch ($type) { - case UPDATE_VOTE: - $message .= __('Mail', "updated a vote.\nYou can find your poll at the link") . " :\n\n"; - break; - case ADD_VOTE: - $message .= __('Mail', "filled a vote.\nYou can find your poll at the link") . " :\n\n"; - break; - case ADD_COMMENT: - $message .= __('Mail', "wrote a comment.\nYou can find your poll at the link") . " :\n\n"; - break; - } - $urlSondage = Utils::getUrlSondage($poll->admin_id, true); - $message .= '' . $urlSondage . '' . "\n\n"; - - $messageTypeKey = $type . '-' . $poll->id; - $mailService->send($poll->admin_mail, $subject, $message, $messageTypeKey); - } -} /* PAGE */ /* ---- */ @@ -139,7 +96,7 @@ if (!empty($_POST['save'])) { // Save edition of an old vote } else { $message = new Message('success', __('studs', 'Update vote succeeded')); } - sendUpdateNotification($poll, $mailService, $name, UPDATE_VOTE); + $notificationService->sendUpdateNotification($poll, $notificationService::UPDATE_VOTE, $name); } else { $message = new Message('danger', __('Error', 'Update vote failed')); } @@ -165,7 +122,7 @@ if (!empty($_POST['save'])) { // Save edition of an old vote } else { $message = new Message('success', __('studs', 'Adding the vote succeeded')); } - sendUpdateNotification($poll, $mailService, $name, ADD_VOTE); + $notificationService->sendUpdateNotification($poll, $notificationService::ADD_VOTE, $name); } else { $message = new Message('danger', __('Error', 'Adding vote failed')); } @@ -189,12 +146,11 @@ if (isset($_POST['add_comment'])) { $result = $pollService->addComment($poll_id, $name, $comment); if ($result) { $message = new Message('success', __('Comments', 'Comment added')); - sendUpdateNotification($poll, $mailService, $name, ADD_COMMENT); + $notificationService->sendUpdateNotification($poll, $notificationService::ADD_COMMENT, $name); } else { $message = new Message('danger', __('Error', 'Comment failed')); } } - } // Retrieve data From 166927f8afb7374ceea8c55050258b84afe3aecb Mon Sep 17 00:00:00 2001 From: Antonin Date: Thu, 22 Oct 2015 22:48:30 +0200 Subject: [PATCH 2/5] Ajaxifisation des commentaires. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Permet de ne pas perdre ses votes à l'ajout d'un commentaire. - On rafraichit aussi à l'envois du commentaire la liste des commentaires. Fix #3 --- action/add_comment.php | 88 ++++++++++++++++++++++++++++++++++++++ css/jquery-ui.min.css | 7 +++ js/app/studs.js | 32 ++++++++++++++ js/jquery-ui.min.js | 6 +++ tpl/part/comments.tpl | 20 +++------ tpl/part/comments_list.tpl | 16 +++++++ tpl/studs.tpl | 4 ++ 7 files changed, 158 insertions(+), 15 deletions(-) create mode 100644 action/add_comment.php create mode 100644 css/jquery-ui.min.css create mode 100644 js/jquery-ui.min.js create mode 100644 tpl/part/comments_list.tpl diff --git a/action/add_comment.php b/action/add_comment.php new file mode 100644 index 0000000..4bdd07c --- /dev/null +++ b/action/add_comment.php @@ -0,0 +1,88 @@ + ['regexp' => POLL_REGEX]]); + if (strlen($poll_id) === 16) { + $poll = $pollService->findById($poll_id); + } +} + +if (!$poll) { + $message = new Message('error', __('Error', 'This poll doesn\'t exist !')); +} else { + $name = $inputService->filterName($_POST['name']); + $comment = $inputService->filterComment($_POST['comment']); + + if ($name == null) { + $message = new Message('danger', __('Error', 'The name is invalid.')); + } + + if ($message == null) { + // Add comment + $result = $pollService->addComment($poll_id, $name, $comment); + if ($result) { + $message = new Message('success', __('Comments', 'Comment added')); + $notificationService->sendUpdateNotification($poll, $mailService, $name, NotificationService::ADD_COMMENT); + } else { + $message = new Message('danger', __('Error', 'Comment failed')); + } + } +} + +$comments = $pollService->allCommentsByPollId($poll_id); + +$smarty->error_reporting = E_ALL & ~E_NOTICE; +$smarty->assign('comments', $comments); +$comments_html = $smarty->fetch('part/comments_list.tpl'); + +$response = array('result' => $result, 'message' => $message, 'comments' => $comments_html); + +echo json_encode($response); diff --git a/css/jquery-ui.min.css b/css/jquery-ui.min.css new file mode 100644 index 0000000..12dab83 --- /dev/null +++ b/css/jquery-ui.min.css @@ -0,0 +1,7 @@ +/*! jQuery UI - v1.11.4 - 2015-10-22 +* http://jqueryui.com +* Includes: core.css, theme.css +* To view and modify this theme, visit http://jqueryui.com/themeroller/?ffDefault=Trebuchet%20MS%2CTahoma%2CVerdana%2CArial%2Csans-serif&fwDefault=bold&fsDefault=1.1em&cornerRadius=4px&bgColorHeader=f6a828&bgTextureHeader=gloss_wave&bgImgOpacityHeader=35&borderColorHeader=e78f08&fcHeader=ffffff&iconColorHeader=ffffff&bgColorContent=eeeeee&bgTextureContent=highlight_soft&bgImgOpacityContent=100&borderColorContent=dddddd&fcContent=333333&iconColorContent=222222&bgColorDefault=f6f6f6&bgTextureDefault=glass&bgImgOpacityDefault=100&borderColorDefault=cccccc&fcDefault=1c94c4&iconColorDefault=ef8c08&bgColorHover=fdf5ce&bgTextureHover=glass&bgImgOpacityHover=100&borderColorHover=fbcb09&fcHover=c77405&iconColorHover=ef8c08&bgColorActive=ffffff&bgTextureActive=glass&bgImgOpacityActive=65&borderColorActive=fbd850&fcActive=eb8f00&iconColorActive=ef8c08&bgColorHighlight=ffe45c&bgTextureHighlight=highlight_soft&bgImgOpacityHighlight=75&borderColorHighlight=fed22f&fcHighlight=363636&iconColorHighlight=228ef1&bgColorError=b81900&bgTextureError=diagonals_thick&bgImgOpacityError=18&borderColorError=cd0a0a&fcError=ffffff&iconColorError=ffd27a&bgColorOverlay=666666&bgTextureOverlay=diagonals_thick&bgImgOpacityOverlay=20&opacityOverlay=50&bgColorShadow=000000&bgTextureShadow=flat&bgImgOpacityShadow=10&opacityShadow=20&thicknessShadow=5px&offsetTopShadow=-5px&offsetLeftShadow=-5px&cornerRadiusShadow=5px +* Copyright 2015 jQuery Foundation and other contributors; Licensed MIT */ + +.ui-helper-hidden{display:none}.ui-helper-hidden-accessible{border:0;clip:rect(0 0 0 0);height:1px;margin:-1px;overflow:hidden;padding:0;position:absolute;width:1px}.ui-helper-reset{margin:0;padding:0;border:0;outline:0;line-height:1.3;text-decoration:none;font-size:100%;list-style:none}.ui-helper-clearfix:before,.ui-helper-clearfix:after{content:"";display:table;border-collapse:collapse}.ui-helper-clearfix:after{clear:both}.ui-helper-clearfix{min-height:0}.ui-helper-zfix{width:100%;height:100%;top:0;left:0;position:absolute;opacity:0;filter:Alpha(Opacity=0)}.ui-front{z-index:100}.ui-state-disabled{cursor:default!important}.ui-icon{display:block;text-indent:-99999px;overflow:hidden;background-repeat:no-repeat}.ui-widget-overlay{position:fixed;top:0;left:0;width:100%;height:100%}.ui-widget{font-family:Trebuchet MS,Tahoma,Verdana,Arial,sans-serif;font-size:1.1em}.ui-widget .ui-widget{font-size:1em}.ui-widget input,.ui-widget select,.ui-widget textarea,.ui-widget button{font-family:Trebuchet MS,Tahoma,Verdana,Arial,sans-serif;font-size:1em}.ui-widget-content{border:1px solid #ddd;background:#eee url("images/ui-bg_highlight-soft_100_eeeeee_1x100.png") 50% top repeat-x;color:#333}.ui-widget-content a{color:#333}.ui-widget-header{border:1px solid #e78f08;background:#f6a828 url("images/ui-bg_gloss-wave_35_f6a828_500x100.png") 50% 50% repeat-x;color:#fff;font-weight:bold}.ui-widget-header a{color:#fff}.ui-state-default,.ui-widget-content .ui-state-default,.ui-widget-header .ui-state-default{border:1px solid #ccc;background:#f6f6f6 url("images/ui-bg_glass_100_f6f6f6_1x400.png") 50% 50% repeat-x;font-weight:bold;color:#1c94c4}.ui-state-default a,.ui-state-default a:link,.ui-state-default a:visited{color:#1c94c4;text-decoration:none}.ui-state-hover,.ui-widget-content .ui-state-hover,.ui-widget-header .ui-state-hover,.ui-state-focus,.ui-widget-content .ui-state-focus,.ui-widget-header .ui-state-focus{border:1px solid #fbcb09;background:#fdf5ce url("images/ui-bg_glass_100_fdf5ce_1x400.png") 50% 50% repeat-x;font-weight:bold;color:#c77405}.ui-state-hover a,.ui-state-hover a:hover,.ui-state-hover a:link,.ui-state-hover a:visited,.ui-state-focus a,.ui-state-focus a:hover,.ui-state-focus a:link,.ui-state-focus a:visited{color:#c77405;text-decoration:none}.ui-state-active,.ui-widget-content .ui-state-active,.ui-widget-header .ui-state-active{border:1px solid #fbd850;background:#fff url("images/ui-bg_glass_65_ffffff_1x400.png") 50% 50% repeat-x;font-weight:bold;color:#eb8f00}.ui-state-active a,.ui-state-active a:link,.ui-state-active a:visited{color:#eb8f00;text-decoration:none}.ui-state-highlight,.ui-widget-content .ui-state-highlight,.ui-widget-header .ui-state-highlight{border:1px solid #fed22f;background:#ffe45c url("images/ui-bg_highlight-soft_75_ffe45c_1x100.png") 50% top repeat-x;color:#363636}.ui-state-highlight a,.ui-widget-content .ui-state-highlight a,.ui-widget-header .ui-state-highlight a{color:#363636}.ui-state-error,.ui-widget-content .ui-state-error,.ui-widget-header .ui-state-error{border:1px solid #cd0a0a;background:#b81900 url("images/ui-bg_diagonals-thick_18_b81900_40x40.png") 50% 50% repeat;color:#fff}.ui-state-error a,.ui-widget-content .ui-state-error a,.ui-widget-header .ui-state-error a{color:#fff}.ui-state-error-text,.ui-widget-content .ui-state-error-text,.ui-widget-header .ui-state-error-text{color:#fff}.ui-priority-primary,.ui-widget-content .ui-priority-primary,.ui-widget-header .ui-priority-primary{font-weight:bold}.ui-priority-secondary,.ui-widget-content .ui-priority-secondary,.ui-widget-header .ui-priority-secondary{opacity:.7;filter:Alpha(Opacity=70);font-weight:normal}.ui-state-disabled,.ui-widget-content .ui-state-disabled,.ui-widget-header .ui-state-disabled{opacity:.35;filter:Alpha(Opacity=35);background-image:none}.ui-state-disabled .ui-icon{filter:Alpha(Opacity=35)}.ui-icon{width:16px;height:16px}.ui-icon,.ui-widget-content .ui-icon{background-image:url("images/ui-icons_222222_256x240.png")}.ui-widget-header .ui-icon{background-image:url("images/ui-icons_ffffff_256x240.png")}.ui-state-default .ui-icon{background-image:url("images/ui-icons_ef8c08_256x240.png")}.ui-state-hover .ui-icon,.ui-state-focus .ui-icon{background-image:url("images/ui-icons_ef8c08_256x240.png")}.ui-state-active .ui-icon{background-image:url("images/ui-icons_ef8c08_256x240.png")}.ui-state-highlight .ui-icon{background-image:url("images/ui-icons_228ef1_256x240.png")}.ui-state-error .ui-icon,.ui-state-error-text .ui-icon{background-image:url("images/ui-icons_ffd27a_256x240.png")}.ui-icon-blank{background-position:16px 16px}.ui-icon-carat-1-n{background-position:0 0}.ui-icon-carat-1-ne{background-position:-16px 0}.ui-icon-carat-1-e{background-position:-32px 0}.ui-icon-carat-1-se{background-position:-48px 0}.ui-icon-carat-1-s{background-position:-64px 0}.ui-icon-carat-1-sw{background-position:-80px 0}.ui-icon-carat-1-w{background-position:-96px 0}.ui-icon-carat-1-nw{background-position:-112px 0}.ui-icon-carat-2-n-s{background-position:-128px 0}.ui-icon-carat-2-e-w{background-position:-144px 0}.ui-icon-triangle-1-n{background-position:0 -16px}.ui-icon-triangle-1-ne{background-position:-16px -16px}.ui-icon-triangle-1-e{background-position:-32px -16px}.ui-icon-triangle-1-se{background-position:-48px -16px}.ui-icon-triangle-1-s{background-position:-64px -16px}.ui-icon-triangle-1-sw{background-position:-80px -16px}.ui-icon-triangle-1-w{background-position:-96px -16px}.ui-icon-triangle-1-nw{background-position:-112px -16px}.ui-icon-triangle-2-n-s{background-position:-128px -16px}.ui-icon-triangle-2-e-w{background-position:-144px -16px}.ui-icon-arrow-1-n{background-position:0 -32px}.ui-icon-arrow-1-ne{background-position:-16px -32px}.ui-icon-arrow-1-e{background-position:-32px -32px}.ui-icon-arrow-1-se{background-position:-48px -32px}.ui-icon-arrow-1-s{background-position:-64px -32px}.ui-icon-arrow-1-sw{background-position:-80px -32px}.ui-icon-arrow-1-w{background-position:-96px -32px}.ui-icon-arrow-1-nw{background-position:-112px -32px}.ui-icon-arrow-2-n-s{background-position:-128px -32px}.ui-icon-arrow-2-ne-sw{background-position:-144px -32px}.ui-icon-arrow-2-e-w{background-position:-160px -32px}.ui-icon-arrow-2-se-nw{background-position:-176px -32px}.ui-icon-arrowstop-1-n{background-position:-192px -32px}.ui-icon-arrowstop-1-e{background-position:-208px -32px}.ui-icon-arrowstop-1-s{background-position:-224px -32px}.ui-icon-arrowstop-1-w{background-position:-240px -32px}.ui-icon-arrowthick-1-n{background-position:0 -48px}.ui-icon-arrowthick-1-ne{background-position:-16px -48px}.ui-icon-arrowthick-1-e{background-position:-32px -48px}.ui-icon-arrowthick-1-se{background-position:-48px -48px}.ui-icon-arrowthick-1-s{background-position:-64px -48px}.ui-icon-arrowthick-1-sw{background-position:-80px -48px}.ui-icon-arrowthick-1-w{background-position:-96px -48px}.ui-icon-arrowthick-1-nw{background-position:-112px -48px}.ui-icon-arrowthick-2-n-s{background-position:-128px -48px}.ui-icon-arrowthick-2-ne-sw{background-position:-144px -48px}.ui-icon-arrowthick-2-e-w{background-position:-160px -48px}.ui-icon-arrowthick-2-se-nw{background-position:-176px -48px}.ui-icon-arrowthickstop-1-n{background-position:-192px -48px}.ui-icon-arrowthickstop-1-e{background-position:-208px -48px}.ui-icon-arrowthickstop-1-s{background-position:-224px -48px}.ui-icon-arrowthickstop-1-w{background-position:-240px -48px}.ui-icon-arrowreturnthick-1-w{background-position:0 -64px}.ui-icon-arrowreturnthick-1-n{background-position:-16px -64px}.ui-icon-arrowreturnthick-1-e{background-position:-32px -64px}.ui-icon-arrowreturnthick-1-s{background-position:-48px -64px}.ui-icon-arrowreturn-1-w{background-position:-64px -64px}.ui-icon-arrowreturn-1-n{background-position:-80px -64px}.ui-icon-arrowreturn-1-e{background-position:-96px -64px}.ui-icon-arrowreturn-1-s{background-position:-112px -64px}.ui-icon-arrowrefresh-1-w{background-position:-128px -64px}.ui-icon-arrowrefresh-1-n{background-position:-144px -64px}.ui-icon-arrowrefresh-1-e{background-position:-160px -64px}.ui-icon-arrowrefresh-1-s{background-position:-176px -64px}.ui-icon-arrow-4{background-position:0 -80px}.ui-icon-arrow-4-diag{background-position:-16px -80px}.ui-icon-extlink{background-position:-32px -80px}.ui-icon-newwin{background-position:-48px -80px}.ui-icon-refresh{background-position:-64px -80px}.ui-icon-shuffle{background-position:-80px -80px}.ui-icon-transfer-e-w{background-position:-96px -80px}.ui-icon-transferthick-e-w{background-position:-112px -80px}.ui-icon-folder-collapsed{background-position:0 -96px}.ui-icon-folder-open{background-position:-16px -96px}.ui-icon-document{background-position:-32px -96px}.ui-icon-document-b{background-position:-48px -96px}.ui-icon-note{background-position:-64px -96px}.ui-icon-mail-closed{background-position:-80px -96px}.ui-icon-mail-open{background-position:-96px -96px}.ui-icon-suitcase{background-position:-112px -96px}.ui-icon-comment{background-position:-128px -96px}.ui-icon-person{background-position:-144px -96px}.ui-icon-print{background-position:-160px -96px}.ui-icon-trash{background-position:-176px -96px}.ui-icon-locked{background-position:-192px -96px}.ui-icon-unlocked{background-position:-208px -96px}.ui-icon-bookmark{background-position:-224px -96px}.ui-icon-tag{background-position:-240px -96px}.ui-icon-home{background-position:0 -112px}.ui-icon-flag{background-position:-16px -112px}.ui-icon-calendar{background-position:-32px -112px}.ui-icon-cart{background-position:-48px -112px}.ui-icon-pencil{background-position:-64px -112px}.ui-icon-clock{background-position:-80px -112px}.ui-icon-disk{background-position:-96px -112px}.ui-icon-calculator{background-position:-112px -112px}.ui-icon-zoomin{background-position:-128px -112px}.ui-icon-zoomout{background-position:-144px -112px}.ui-icon-search{background-position:-160px -112px}.ui-icon-wrench{background-position:-176px -112px}.ui-icon-gear{background-position:-192px -112px}.ui-icon-heart{background-position:-208px -112px}.ui-icon-star{background-position:-224px -112px}.ui-icon-link{background-position:-240px -112px}.ui-icon-cancel{background-position:0 -128px}.ui-icon-plus{background-position:-16px -128px}.ui-icon-plusthick{background-position:-32px -128px}.ui-icon-minus{background-position:-48px -128px}.ui-icon-minusthick{background-position:-64px -128px}.ui-icon-close{background-position:-80px -128px}.ui-icon-closethick{background-position:-96px -128px}.ui-icon-key{background-position:-112px -128px}.ui-icon-lightbulb{background-position:-128px -128px}.ui-icon-scissors{background-position:-144px -128px}.ui-icon-clipboard{background-position:-160px -128px}.ui-icon-copy{background-position:-176px -128px}.ui-icon-contact{background-position:-192px -128px}.ui-icon-image{background-position:-208px -128px}.ui-icon-video{background-position:-224px -128px}.ui-icon-script{background-position:-240px -128px}.ui-icon-alert{background-position:0 -144px}.ui-icon-info{background-position:-16px -144px}.ui-icon-notice{background-position:-32px -144px}.ui-icon-help{background-position:-48px -144px}.ui-icon-check{background-position:-64px -144px}.ui-icon-bullet{background-position:-80px -144px}.ui-icon-radio-on{background-position:-96px -144px}.ui-icon-radio-off{background-position:-112px -144px}.ui-icon-pin-w{background-position:-128px -144px}.ui-icon-pin-s{background-position:-144px -144px}.ui-icon-play{background-position:0 -160px}.ui-icon-pause{background-position:-16px -160px}.ui-icon-seek-next{background-position:-32px -160px}.ui-icon-seek-prev{background-position:-48px -160px}.ui-icon-seek-end{background-position:-64px -160px}.ui-icon-seek-start{background-position:-80px -160px}.ui-icon-seek-first{background-position:-80px -160px}.ui-icon-stop{background-position:-96px -160px}.ui-icon-eject{background-position:-112px -160px}.ui-icon-volume-off{background-position:-128px -160px}.ui-icon-volume-on{background-position:-144px -160px}.ui-icon-power{background-position:0 -176px}.ui-icon-signal-diag{background-position:-16px -176px}.ui-icon-signal{background-position:-32px -176px}.ui-icon-battery-0{background-position:-48px -176px}.ui-icon-battery-1{background-position:-64px -176px}.ui-icon-battery-2{background-position:-80px -176px}.ui-icon-battery-3{background-position:-96px -176px}.ui-icon-circle-plus{background-position:0 -192px}.ui-icon-circle-minus{background-position:-16px -192px}.ui-icon-circle-close{background-position:-32px -192px}.ui-icon-circle-triangle-e{background-position:-48px -192px}.ui-icon-circle-triangle-s{background-position:-64px -192px}.ui-icon-circle-triangle-w{background-position:-80px -192px}.ui-icon-circle-triangle-n{background-position:-96px -192px}.ui-icon-circle-arrow-e{background-position:-112px -192px}.ui-icon-circle-arrow-s{background-position:-128px -192px}.ui-icon-circle-arrow-w{background-position:-144px -192px}.ui-icon-circle-arrow-n{background-position:-160px -192px}.ui-icon-circle-zoomin{background-position:-176px -192px}.ui-icon-circle-zoomout{background-position:-192px -192px}.ui-icon-circle-check{background-position:-208px -192px}.ui-icon-circlesmall-plus{background-position:0 -208px}.ui-icon-circlesmall-minus{background-position:-16px -208px}.ui-icon-circlesmall-close{background-position:-32px -208px}.ui-icon-squaresmall-plus{background-position:-48px -208px}.ui-icon-squaresmall-minus{background-position:-64px -208px}.ui-icon-squaresmall-close{background-position:-80px -208px}.ui-icon-grip-dotted-vertical{background-position:0 -224px}.ui-icon-grip-dotted-horizontal{background-position:-16px -224px}.ui-icon-grip-solid-vertical{background-position:-32px -224px}.ui-icon-grip-solid-horizontal{background-position:-48px -224px}.ui-icon-gripsmall-diagonal-se{background-position:-64px -224px}.ui-icon-grip-diagonal-se{background-position:-80px -224px}.ui-corner-all,.ui-corner-top,.ui-corner-left,.ui-corner-tl{border-top-left-radius:4px}.ui-corner-all,.ui-corner-top,.ui-corner-right,.ui-corner-tr{border-top-right-radius:4px}.ui-corner-all,.ui-corner-bottom,.ui-corner-left,.ui-corner-bl{border-bottom-left-radius:4px}.ui-corner-all,.ui-corner-bottom,.ui-corner-right,.ui-corner-br{border-bottom-right-radius:4px}.ui-widget-overlay{background:#666 url("images/ui-bg_diagonals-thick_20_666666_40x40.png") 50% 50% repeat;opacity:.5;filter:Alpha(Opacity=50)}.ui-widget-shadow{margin:-5px 0 0 -5px;padding:5px;background:#000 url("images/ui-bg_flat_10_000000_40x100.png") 50% 50% repeat-x;opacity:.2;filter:Alpha(Opacity=20);border-radius:5px} \ No newline at end of file diff --git a/js/app/studs.js b/js/app/studs.js index 2ef5aee..6245c97 100644 --- a/js/app/studs.js +++ b/js/app/studs.js @@ -44,4 +44,36 @@ $(document).ready(function () { $(this).next().removeClass('startunchecked'); }); + var form = $('#comment_form'); + + form.submit(function(event) { + event.preventDefault(); + + $.ajax({ + type: "POST", + url: form.attr('action'), + data: form.serialize(), + dataType: 'json', + success: function(data) + { + $('#comment').val(""); + + if (data.result) { + $("#comments_list").replaceWith(data.comments); + var lastComment = $("#comments_list").find("div.comment").last(); + lastComment.effect('highlight', {color: 'green'}, 401); + $('html, body').animate({ + scrollTop: $("#comments_alerts").offset().top + }, 750); + } else { + var newMessage = $("#genericErrorTemplate").clone(); + newMessage.find(".contents").text(data.message.message); + $("#comments_alerts").empty().append(newMessage); + } + } + }); + + return false; + }); + }); diff --git a/js/jquery-ui.min.js b/js/jquery-ui.min.js new file mode 100644 index 0000000..03d45c0 --- /dev/null +++ b/js/jquery-ui.min.js @@ -0,0 +1,6 @@ +/*! jQuery UI - v1.11.4 - 2015-10-22 +* http://jqueryui.com +* Includes: core.js, effect.js, effect-highlight.js +* Copyright 2015 jQuery Foundation and other contributors; Licensed MIT */ + +(function(e){"function"==typeof define&&define.amd?define(["jquery"],e):e(jQuery)})(function(e){function t(t,s){var n,a,o,r=t.nodeName.toLowerCase();return"area"===r?(n=t.parentNode,a=n.name,t.href&&a&&"map"===n.nodeName.toLowerCase()?(o=e("img[usemap='#"+a+"']")[0],!!o&&i(o)):!1):(/^(input|select|textarea|button|object)$/.test(r)?!t.disabled:"a"===r?t.href||s:s)&&i(t)}function i(t){return e.expr.filters.visible(t)&&!e(t).parents().addBack().filter(function(){return"hidden"===e.css(this,"visibility")}).length}e.ui=e.ui||{},e.extend(e.ui,{version:"1.11.4",keyCode:{BACKSPACE:8,COMMA:188,DELETE:46,DOWN:40,END:35,ENTER:13,ESCAPE:27,HOME:36,LEFT:37,PAGE_DOWN:34,PAGE_UP:33,PERIOD:190,RIGHT:39,SPACE:32,TAB:9,UP:38}}),e.fn.extend({scrollParent:function(t){var i=this.css("position"),s="absolute"===i,n=t?/(auto|scroll|hidden)/:/(auto|scroll)/,a=this.parents().filter(function(){var t=e(this);return s&&"static"===t.css("position")?!1:n.test(t.css("overflow")+t.css("overflow-y")+t.css("overflow-x"))}).eq(0);return"fixed"!==i&&a.length?a:e(this[0].ownerDocument||document)},uniqueId:function(){var e=0;return function(){return this.each(function(){this.id||(this.id="ui-id-"+ ++e)})}}(),removeUniqueId:function(){return this.each(function(){/^ui-id-\d+$/.test(this.id)&&e(this).removeAttr("id")})}}),e.extend(e.expr[":"],{data:e.expr.createPseudo?e.expr.createPseudo(function(t){return function(i){return!!e.data(i,t)}}):function(t,i,s){return!!e.data(t,s[3])},focusable:function(i){return t(i,!isNaN(e.attr(i,"tabindex")))},tabbable:function(i){var s=e.attr(i,"tabindex"),n=isNaN(s);return(n||s>=0)&&t(i,!n)}}),e("").outerWidth(1).jquery||e.each(["Width","Height"],function(t,i){function s(t,i,s,a){return e.each(n,function(){i-=parseFloat(e.css(t,"padding"+this))||0,s&&(i-=parseFloat(e.css(t,"border"+this+"Width"))||0),a&&(i-=parseFloat(e.css(t,"margin"+this))||0)}),i}var n="Width"===i?["Left","Right"]:["Top","Bottom"],a=i.toLowerCase(),o={innerWidth:e.fn.innerWidth,innerHeight:e.fn.innerHeight,outerWidth:e.fn.outerWidth,outerHeight:e.fn.outerHeight};e.fn["inner"+i]=function(t){return void 0===t?o["inner"+i].call(this):this.each(function(){e(this).css(a,s(this,t)+"px")})},e.fn["outer"+i]=function(t,n){return"number"!=typeof t?o["outer"+i].call(this,t):this.each(function(){e(this).css(a,s(this,t,!0,n)+"px")})}}),e.fn.addBack||(e.fn.addBack=function(e){return this.add(null==e?this.prevObject:this.prevObject.filter(e))}),e("").data("a-b","a").removeData("a-b").data("a-b")&&(e.fn.removeData=function(t){return function(i){return arguments.length?t.call(this,e.camelCase(i)):t.call(this)}}(e.fn.removeData)),e.ui.ie=!!/msie [\w.]+/.exec(navigator.userAgent.toLowerCase()),e.fn.extend({focus:function(t){return function(i,s){return"number"==typeof i?this.each(function(){var t=this;setTimeout(function(){e(t).focus(),s&&s.call(t)},i)}):t.apply(this,arguments)}}(e.fn.focus),disableSelection:function(){var e="onselectstart"in document.createElement("div")?"selectstart":"mousedown";return function(){return this.bind(e+".ui-disableSelection",function(e){e.preventDefault()})}}(),enableSelection:function(){return this.unbind(".ui-disableSelection")},zIndex:function(t){if(void 0!==t)return this.css("zIndex",t);if(this.length)for(var i,s,n=e(this[0]);n.length&&n[0]!==document;){if(i=n.css("position"),("absolute"===i||"relative"===i||"fixed"===i)&&(s=parseInt(n.css("zIndex"),10),!isNaN(s)&&0!==s))return s;n=n.parent()}return 0}}),e.ui.plugin={add:function(t,i,s){var n,a=e.ui[t].prototype;for(n in s)a.plugins[n]=a.plugins[n]||[],a.plugins[n].push([i,s[n]])},call:function(e,t,i,s){var n,a=e.plugins[t];if(a&&(s||e.element[0].parentNode&&11!==e.element[0].parentNode.nodeType))for(n=0;a.length>n;n++)e.options[a[n][0]]&&a[n][1].apply(e.element,i)}};var s="ui-effects-",n=e;e.effects={effect:{}},function(e,t){function i(e,t,i){var s=d[t.type]||{};return null==e?i||!t.def?null:t.def:(e=s.floor?~~e:parseFloat(e),isNaN(e)?t.def:s.mod?(e+s.mod)%s.mod:0>e?0:e>s.max?s.max:e)}function s(i){var s=l(),n=s._rgba=[];return i=i.toLowerCase(),f(h,function(e,a){var o,r=a.re.exec(i),h=r&&a.parse(r),l=a.space||"rgba";return h?(o=s[l](h),s[u[l].cache]=o[u[l].cache],n=s._rgba=o._rgba,!1):t}),n.length?("0,0,0,0"===n.join()&&e.extend(n,a.transparent),s):a[i]}function n(e,t,i){return i=(i+1)%1,1>6*i?e+6*(t-e)*i:1>2*i?t:2>3*i?e+6*(t-e)*(2/3-i):e}var a,o="backgroundColor borderBottomColor borderLeftColor borderRightColor borderTopColor color columnRuleColor outlineColor textDecorationColor textEmphasisColor",r=/^([\-+])=\s*(\d+\.?\d*)/,h=[{re:/rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/,parse:function(e){return[e[1],e[2],e[3],e[4]]}},{re:/rgba?\(\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/,parse:function(e){return[2.55*e[1],2.55*e[2],2.55*e[3],e[4]]}},{re:/#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})/,parse:function(e){return[parseInt(e[1],16),parseInt(e[2],16),parseInt(e[3],16)]}},{re:/#([a-f0-9])([a-f0-9])([a-f0-9])/,parse:function(e){return[parseInt(e[1]+e[1],16),parseInt(e[2]+e[2],16),parseInt(e[3]+e[3],16)]}},{re:/hsla?\(\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/,space:"hsla",parse:function(e){return[e[1],e[2]/100,e[3]/100,e[4]]}}],l=e.Color=function(t,i,s,n){return new e.Color.fn.parse(t,i,s,n)},u={rgba:{props:{red:{idx:0,type:"byte"},green:{idx:1,type:"byte"},blue:{idx:2,type:"byte"}}},hsla:{props:{hue:{idx:0,type:"degrees"},saturation:{idx:1,type:"percent"},lightness:{idx:2,type:"percent"}}}},d={"byte":{floor:!0,max:255},percent:{max:1},degrees:{mod:360,floor:!0}},c=l.support={},p=e("

")[0],f=e.each;p.style.cssText="background-color:rgba(1,1,1,.5)",c.rgba=p.style.backgroundColor.indexOf("rgba")>-1,f(u,function(e,t){t.cache="_"+e,t.props.alpha={idx:3,type:"percent",def:1}}),l.fn=e.extend(l.prototype,{parse:function(n,o,r,h){if(n===t)return this._rgba=[null,null,null,null],this;(n.jquery||n.nodeType)&&(n=e(n).css(o),o=t);var d=this,c=e.type(n),p=this._rgba=[];return o!==t&&(n=[n,o,r,h],c="array"),"string"===c?this.parse(s(n)||a._default):"array"===c?(f(u.rgba.props,function(e,t){p[t.idx]=i(n[t.idx],t)}),this):"object"===c?(n instanceof l?f(u,function(e,t){n[t.cache]&&(d[t.cache]=n[t.cache].slice())}):f(u,function(t,s){var a=s.cache;f(s.props,function(e,t){if(!d[a]&&s.to){if("alpha"===e||null==n[e])return;d[a]=s.to(d._rgba)}d[a][t.idx]=i(n[e],t,!0)}),d[a]&&0>e.inArray(null,d[a].slice(0,3))&&(d[a][3]=1,s.from&&(d._rgba=s.from(d[a])))}),this):t},is:function(e){var i=l(e),s=!0,n=this;return f(u,function(e,a){var o,r=i[a.cache];return r&&(o=n[a.cache]||a.to&&a.to(n._rgba)||[],f(a.props,function(e,i){return null!=r[i.idx]?s=r[i.idx]===o[i.idx]:t})),s}),s},_space:function(){var e=[],t=this;return f(u,function(i,s){t[s.cache]&&e.push(i)}),e.pop()},transition:function(e,t){var s=l(e),n=s._space(),a=u[n],o=0===this.alpha()?l("transparent"):this,r=o[a.cache]||a.to(o._rgba),h=r.slice();return s=s[a.cache],f(a.props,function(e,n){var a=n.idx,o=r[a],l=s[a],u=d[n.type]||{};null!==l&&(null===o?h[a]=l:(u.mod&&(l-o>u.mod/2?o+=u.mod:o-l>u.mod/2&&(o-=u.mod)),h[a]=i((l-o)*t+o,n)))}),this[n](h)},blend:function(t){if(1===this._rgba[3])return this;var i=this._rgba.slice(),s=i.pop(),n=l(t)._rgba;return l(e.map(i,function(e,t){return(1-s)*n[t]+s*e}))},toRgbaString:function(){var t="rgba(",i=e.map(this._rgba,function(e,t){return null==e?t>2?1:0:e});return 1===i[3]&&(i.pop(),t="rgb("),t+i.join()+")"},toHslaString:function(){var t="hsla(",i=e.map(this.hsla(),function(e,t){return null==e&&(e=t>2?1:0),t&&3>t&&(e=Math.round(100*e)+"%"),e});return 1===i[3]&&(i.pop(),t="hsl("),t+i.join()+")"},toHexString:function(t){var i=this._rgba.slice(),s=i.pop();return t&&i.push(~~(255*s)),"#"+e.map(i,function(e){return e=(e||0).toString(16),1===e.length?"0"+e:e}).join("")},toString:function(){return 0===this._rgba[3]?"transparent":this.toRgbaString()}}),l.fn.parse.prototype=l.fn,u.hsla.to=function(e){if(null==e[0]||null==e[1]||null==e[2])return[null,null,null,e[3]];var t,i,s=e[0]/255,n=e[1]/255,a=e[2]/255,o=e[3],r=Math.max(s,n,a),h=Math.min(s,n,a),l=r-h,u=r+h,d=.5*u;return t=h===r?0:s===r?60*(n-a)/l+360:n===r?60*(a-s)/l+120:60*(s-n)/l+240,i=0===l?0:.5>=d?l/u:l/(2-u),[Math.round(t)%360,i,d,null==o?1:o]},u.hsla.from=function(e){if(null==e[0]||null==e[1]||null==e[2])return[null,null,null,e[3]];var t=e[0]/360,i=e[1],s=e[2],a=e[3],o=.5>=s?s*(1+i):s+i-s*i,r=2*s-o;return[Math.round(255*n(r,o,t+1/3)),Math.round(255*n(r,o,t)),Math.round(255*n(r,o,t-1/3)),a]},f(u,function(s,n){var a=n.props,o=n.cache,h=n.to,u=n.from;l.fn[s]=function(s){if(h&&!this[o]&&(this[o]=h(this._rgba)),s===t)return this[o].slice();var n,r=e.type(s),d="array"===r||"object"===r?s:arguments,c=this[o].slice();return f(a,function(e,t){var s=d["object"===r?e:t.idx];null==s&&(s=c[t.idx]),c[t.idx]=i(s,t)}),u?(n=l(u(c)),n[o]=c,n):l(c)},f(a,function(t,i){l.fn[t]||(l.fn[t]=function(n){var a,o=e.type(n),h="alpha"===t?this._hsla?"hsla":"rgba":s,l=this[h](),u=l[i.idx];return"undefined"===o?u:("function"===o&&(n=n.call(this,u),o=e.type(n)),null==n&&i.empty?this:("string"===o&&(a=r.exec(n),a&&(n=u+parseFloat(a[2])*("+"===a[1]?1:-1))),l[i.idx]=n,this[h](l)))})})}),l.hook=function(t){var i=t.split(" ");f(i,function(t,i){e.cssHooks[i]={set:function(t,n){var a,o,r="";if("transparent"!==n&&("string"!==e.type(n)||(a=s(n)))){if(n=l(a||n),!c.rgba&&1!==n._rgba[3]){for(o="backgroundColor"===i?t.parentNode:t;(""===r||"transparent"===r)&&o&&o.style;)try{r=e.css(o,"backgroundColor"),o=o.parentNode}catch(h){}n=n.blend(r&&"transparent"!==r?r:"_default")}n=n.toRgbaString()}try{t.style[i]=n}catch(h){}}},e.fx.step[i]=function(t){t.colorInit||(t.start=l(t.elem,i),t.end=l(t.end),t.colorInit=!0),e.cssHooks[i].set(t.elem,t.start.transition(t.end,t.pos))}})},l.hook(o),e.cssHooks.borderColor={expand:function(e){var t={};return f(["Top","Right","Bottom","Left"],function(i,s){t["border"+s+"Color"]=e}),t}},a=e.Color.names={aqua:"#00ffff",black:"#000000",blue:"#0000ff",fuchsia:"#ff00ff",gray:"#808080",green:"#008000",lime:"#00ff00",maroon:"#800000",navy:"#000080",olive:"#808000",purple:"#800080",red:"#ff0000",silver:"#c0c0c0",teal:"#008080",white:"#ffffff",yellow:"#ffff00",transparent:[null,null,null,0],_default:"#ffffff"}}(n),function(){function t(t){var i,s,n=t.ownerDocument.defaultView?t.ownerDocument.defaultView.getComputedStyle(t,null):t.currentStyle,a={};if(n&&n.length&&n[0]&&n[n[0]])for(s=n.length;s--;)i=n[s],"string"==typeof n[i]&&(a[e.camelCase(i)]=n[i]);else for(i in n)"string"==typeof n[i]&&(a[i]=n[i]);return a}function i(t,i){var s,n,o={};for(s in i)n=i[s],t[s]!==n&&(a[s]||(e.fx.step[s]||!isNaN(parseFloat(n)))&&(o[s]=n));return o}var s=["add","remove","toggle"],a={border:1,borderBottom:1,borderColor:1,borderLeft:1,borderRight:1,borderTop:1,borderWidth:1,margin:1,padding:1};e.each(["borderLeftStyle","borderRightStyle","borderBottomStyle","borderTopStyle"],function(t,i){e.fx.step[i]=function(e){("none"!==e.end&&!e.setAttr||1===e.pos&&!e.setAttr)&&(n.style(e.elem,i,e.end),e.setAttr=!0)}}),e.fn.addBack||(e.fn.addBack=function(e){return this.add(null==e?this.prevObject:this.prevObject.filter(e))}),e.effects.animateClass=function(n,a,o,r){var h=e.speed(a,o,r);return this.queue(function(){var a,o=e(this),r=o.attr("class")||"",l=h.children?o.find("*").addBack():o;l=l.map(function(){var i=e(this);return{el:i,start:t(this)}}),a=function(){e.each(s,function(e,t){n[t]&&o[t+"Class"](n[t])})},a(),l=l.map(function(){return this.end=t(this.el[0]),this.diff=i(this.start,this.end),this}),o.attr("class",r),l=l.map(function(){var t=this,i=e.Deferred(),s=e.extend({},h,{queue:!1,complete:function(){i.resolve(t)}});return this.el.animate(this.diff,s),i.promise()}),e.when.apply(e,l.get()).done(function(){a(),e.each(arguments,function(){var t=this.el;e.each(this.diff,function(e){t.css(e,"")})}),h.complete.call(o[0])})})},e.fn.extend({addClass:function(t){return function(i,s,n,a){return s?e.effects.animateClass.call(this,{add:i},s,n,a):t.apply(this,arguments)}}(e.fn.addClass),removeClass:function(t){return function(i,s,n,a){return arguments.length>1?e.effects.animateClass.call(this,{remove:i},s,n,a):t.apply(this,arguments)}}(e.fn.removeClass),toggleClass:function(t){return function(i,s,n,a,o){return"boolean"==typeof s||void 0===s?n?e.effects.animateClass.call(this,s?{add:i}:{remove:i},n,a,o):t.apply(this,arguments):e.effects.animateClass.call(this,{toggle:i},s,n,a)}}(e.fn.toggleClass),switchClass:function(t,i,s,n,a){return e.effects.animateClass.call(this,{add:i,remove:t},s,n,a)}})}(),function(){function t(t,i,s,n){return e.isPlainObject(t)&&(i=t,t=t.effect),t={effect:t},null==i&&(i={}),e.isFunction(i)&&(n=i,s=null,i={}),("number"==typeof i||e.fx.speeds[i])&&(n=s,s=i,i={}),e.isFunction(s)&&(n=s,s=null),i&&e.extend(t,i),s=s||i.duration,t.duration=e.fx.off?0:"number"==typeof s?s:s in e.fx.speeds?e.fx.speeds[s]:e.fx.speeds._default,t.complete=n||i.complete,t}function i(t){return!t||"number"==typeof t||e.fx.speeds[t]?!0:"string"!=typeof t||e.effects.effect[t]?e.isFunction(t)?!0:"object"!=typeof t||t.effect?!1:!0:!0}e.extend(e.effects,{version:"1.11.4",save:function(e,t){for(var i=0;t.length>i;i++)null!==t[i]&&e.data(s+t[i],e[0].style[t[i]])},restore:function(e,t){var i,n;for(n=0;t.length>n;n++)null!==t[n]&&(i=e.data(s+t[n]),void 0===i&&(i=""),e.css(t[n],i))},setMode:function(e,t){return"toggle"===t&&(t=e.is(":hidden")?"show":"hide"),t},getBaseline:function(e,t){var i,s;switch(e[0]){case"top":i=0;break;case"middle":i=.5;break;case"bottom":i=1;break;default:i=e[0]/t.height}switch(e[1]){case"left":s=0;break;case"center":s=.5;break;case"right":s=1;break;default:s=e[1]/t.width}return{x:s,y:i}},createWrapper:function(t){if(t.parent().is(".ui-effects-wrapper"))return t.parent();var i={width:t.outerWidth(!0),height:t.outerHeight(!0),"float":t.css("float")},s=e("

").addClass("ui-effects-wrapper").css({fontSize:"100%",background:"transparent",border:"none",margin:0,padding:0}),n={width:t.width(),height:t.height()},a=document.activeElement;try{a.id}catch(o){a=document.body}return t.wrap(s),(t[0]===a||e.contains(t[0],a))&&e(a).focus(),s=t.parent(),"static"===t.css("position")?(s.css({position:"relative"}),t.css({position:"relative"})):(e.extend(i,{position:t.css("position"),zIndex:t.css("z-index")}),e.each(["top","left","bottom","right"],function(e,s){i[s]=t.css(s),isNaN(parseInt(i[s],10))&&(i[s]="auto")}),t.css({position:"relative",top:0,left:0,right:"auto",bottom:"auto"})),t.css(n),s.css(i).show()},removeWrapper:function(t){var i=document.activeElement;return t.parent().is(".ui-effects-wrapper")&&(t.parent().replaceWith(t),(t[0]===i||e.contains(t[0],i))&&e(i).focus()),t},setTransition:function(t,i,s,n){return n=n||{},e.each(i,function(e,i){var a=t.cssUnit(i);a[0]>0&&(n[i]=a[0]*s+a[1])}),n}}),e.fn.extend({effect:function(){function i(t){function i(){e.isFunction(a)&&a.call(n[0]),e.isFunction(t)&&t()}var n=e(this),a=s.complete,r=s.mode;(n.is(":hidden")?"hide"===r:"show"===r)?(n[r](),i()):o.call(n[0],s,i)}var s=t.apply(this,arguments),n=s.mode,a=s.queue,o=e.effects.effect[s.effect];return e.fx.off||!o?n?this[n](s.duration,s.complete):this.each(function(){s.complete&&s.complete.call(this)}):a===!1?this.each(i):this.queue(a||"fx",i)},show:function(e){return function(s){if(i(s))return e.apply(this,arguments);var n=t.apply(this,arguments);return n.mode="show",this.effect.call(this,n)}}(e.fn.show),hide:function(e){return function(s){if(i(s))return e.apply(this,arguments);var n=t.apply(this,arguments);return n.mode="hide",this.effect.call(this,n)}}(e.fn.hide),toggle:function(e){return function(s){if(i(s)||"boolean"==typeof s)return e.apply(this,arguments);var n=t.apply(this,arguments);return n.mode="toggle",this.effect.call(this,n)}}(e.fn.toggle),cssUnit:function(t){var i=this.css(t),s=[];return e.each(["em","px","%","pt"],function(e,t){i.indexOf(t)>0&&(s=[parseFloat(i),t])}),s}})}(),function(){var t={};e.each(["Quad","Cubic","Quart","Quint","Expo"],function(e,i){t[i]=function(t){return Math.pow(t,e+2)}}),e.extend(t,{Sine:function(e){return 1-Math.cos(e*Math.PI/2)},Circ:function(e){return 1-Math.sqrt(1-e*e)},Elastic:function(e){return 0===e||1===e?e:-Math.pow(2,8*(e-1))*Math.sin((80*(e-1)-7.5)*Math.PI/15)},Back:function(e){return e*e*(3*e-2)},Bounce:function(e){for(var t,i=4;((t=Math.pow(2,--i))-1)/11>e;);return 1/Math.pow(4,3-i)-7.5625*Math.pow((3*t-2)/22-e,2)}}),e.each(t,function(t,i){e.easing["easeIn"+t]=i,e.easing["easeOut"+t]=function(e){return 1-i(1-e)},e.easing["easeInOut"+t]=function(e){return.5>e?i(2*e)/2:1-i(-2*e+2)/2}})}(),e.effects,e.effects.effect.highlight=function(t,i){var s=e(this),n=["backgroundImage","backgroundColor","opacity"],a=e.effects.setMode(s,t.mode||"show"),o={backgroundColor:s.css("backgroundColor")};"hide"===a&&(o.opacity=0),e.effects.save(s,n),s.show().css({backgroundImage:"none",backgroundColor:t.color||"#ffff99"}).animate(o,{queue:!1,duration:t.duration,easing:t.easing,complete:function(){"hide"===a&&s.hide(),e.effects.restore(s,n),i()}})}}); \ No newline at end of file diff --git a/tpl/part/comments.tpl b/tpl/part/comments.tpl index 7379279..7a3ad4a 100644 --- a/tpl/part/comments.tpl +++ b/tpl/part/comments.tpl @@ -1,21 +1,11 @@ -
- {* Comment list *} +{* Comment list *} +{include 'part/comments_list.tpl'} - {if $comments|count > 0} -

{__('Comments', 'Comments of polled people')}

- {foreach $comments as $comment} -
- {if $admin && !$expired} - - {/if} - {$comment->date|date_format:$date_format['txt_datetime_short']} - {$comment->name|html}  - {$comment->comment|escape|nl2br} -
- {/foreach} - {/if} + + + {* Add comment form *} {if $active && !$expired} diff --git a/tpl/part/comments_list.tpl b/tpl/part/comments_list.tpl new file mode 100644 index 0000000..ee56eba --- /dev/null +++ b/tpl/part/comments_list.tpl @@ -0,0 +1,16 @@ +
+ {if $comments|count > 0} +

{__('Comments', 'Comments of polled people')}

+ {foreach $comments as $comment} +
+ {if $admin && !$expired} + + {/if} + {$comment->date|date_format:$date_format['txt_datetime_short']} + {$comment->name|html}  + {$comment->comment|escape|nl2br} +
+ {/foreach} + {/if} +
+
\ No newline at end of file diff --git a/tpl/studs.tpl b/tpl/studs.tpl index f84fe6a..e5d1113 100644 --- a/tpl/studs.tpl +++ b/tpl/studs.tpl @@ -1,9 +1,12 @@ {extends file='page.tpl'} {block name="header"} + + + {/block} {block name=main} @@ -15,6 +18,7 @@ {/if} + {* Global informations about the current poll *} From 0e0becb5c416ce467e563e0a65244858cf85b5fc Mon Sep 17 00:00:00 2001 From: Antonin Date: Mon, 26 Oct 2015 16:26:22 +0100 Subject: [PATCH 3/5] Replacing :: by NotificationService:: --- adminstuds.php | 4 ++-- studs.php | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/adminstuds.php b/adminstuds.php index 5315422..422fc2b 100644 --- a/adminstuds.php +++ b/adminstuds.php @@ -139,7 +139,7 @@ if (isset($_POST['update_poll_info'])) { // Update poll in database if ($updated && $adminPollService->updatePoll($poll)) { $message = new Message('success', __('adminstuds', 'Poll saved')); - $notificationService->sendUpdateNotification($poll, $notificationService::UPDATE_POLL); + $notificationService->sendUpdateNotification($poll, NotificationService::UPDATE_POLL); } else { $message = new Message('danger', __('Error', 'Failed to save poll')); $poll = $pollService->findById($poll_id); @@ -304,7 +304,7 @@ if (isset($_POST['delete_poll'])) { if (isset($_POST['confirm_delete_poll'])) { if ($adminPollService->deleteEntirePoll($poll_id)) { $message = new Message('success', __('adminstuds', 'Poll fully deleted')); - $notificationService->sendUpdateNotification($poll, $notificationService::DELETED_POLL); + $notificationService->sendUpdateNotification($poll, NotificationService::DELETED_POLL); } else { $message = new Message('danger', __('Error', 'Failed to delete the poll')); } diff --git a/studs.php b/studs.php index 661b1e0..f4306f1 100644 --- a/studs.php +++ b/studs.php @@ -96,7 +96,7 @@ if (!empty($_POST['save'])) { // Save edition of an old vote } else { $message = new Message('success', __('studs', 'Update vote succeeded')); } - $notificationService->sendUpdateNotification($poll, $notificationService::UPDATE_VOTE, $name); + $notificationService->sendUpdateNotification($poll, NotificationService::UPDATE_VOTE, $name); } else { $message = new Message('danger', __('Error', 'Update vote failed')); } @@ -122,7 +122,7 @@ if (!empty($_POST['save'])) { // Save edition of an old vote } else { $message = new Message('success', __('studs', 'Adding the vote succeeded')); } - $notificationService->sendUpdateNotification($poll, $notificationService::ADD_VOTE, $name); + $notificationService->sendUpdateNotification($poll, NotificationService::ADD_VOTE, $name); } else { $message = new Message('danger', __('Error', 'Adding vote failed')); } @@ -146,7 +146,7 @@ if (isset($_POST['add_comment'])) { $result = $pollService->addComment($poll_id, $name, $comment); if ($result) { $message = new Message('success', __('Comments', 'Comment added')); - $notificationService->sendUpdateNotification($poll, $notificationService::ADD_COMMENT, $name); + $notificationService->sendUpdateNotification($poll, NotificationService::ADD_COMMENT, $name); } else { $message = new Message('danger', __('Error', 'Comment failed')); } From 974148550b7ec074179e9e07c6e88959436d52cc Mon Sep 17 00:00:00 2001 From: Antonin Date: Mon, 26 Oct 2015 16:28:59 +0100 Subject: [PATCH 4/5] Refactoring for better reading --- app/classes/Framadate/Services/NotificationService.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/classes/Framadate/Services/NotificationService.php b/app/classes/Framadate/Services/NotificationService.php index 7944c7f..f1f181c 100644 --- a/app/classes/Framadate/Services/NotificationService.php +++ b/app/classes/Framadate/Services/NotificationService.php @@ -36,31 +36,33 @@ class NotificationService { if ($poll->receiveNewVotes) { - if (self::isParticipation($type)) + if (self::isParticipation($type)) { $translationString = 'Poll\'s participation: %s'; - else + } else { $translationString = 'Notification of poll: %s'; + } $subject = '[' . NOMAPPLICATION . '] ' . __f('Mail', $translationString, $poll->title); $message = ''; - if (self::isParticipation($type)) - $message .= $name . ' '; $urlSondage = Utils::getUrlSondage($poll->admin_id, true); $link = '
' . $urlSondage . '' . "\n\n"; switch ($type) { case self::UPDATE_VOTE: + $message .= $name . ' '; $message .= __('Mail', "updated a vote.\nYou can find your poll at the link") . " :\n\n"; $message .= $link; break; case self::ADD_VOTE: + $message .= $name . ' '; $message .= __('Mail', "filled a vote.\nYou can find your poll at the link") . " :\n\n"; $message .= $link; break; case self::ADD_COMMENT: + $message .= $name . ' '; $message .= __('Mail', "wrote a comment.\nYou can find your poll at the link") . " :\n\n"; $message .= $link; break; From 5552cc4d9db05c2cd803e79f0f10232b1cef2e26 Mon Sep 17 00:00:00 2001 From: Antonin Date: Mon, 26 Oct 2015 16:46:08 +0100 Subject: [PATCH 5/5] studs.js refactoring. - Replacing "" by '' - Use chaining when possible - Correct the scrolling on comment correctly set. --- js/app/studs.js | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/js/app/studs.js b/js/app/studs.js index 6245c97..bb0c89b 100644 --- a/js/app/studs.js +++ b/js/app/studs.js @@ -18,18 +18,19 @@ $(document).ready(function () { - $("#poll_form").submit(function (event) { - var name = $("#name").val(); - name = name.trim(); + $('#poll_form').submit(function (event) { + var name = $('#name').val().trim(); if (name.length == 0) { event.preventDefault(); - var newMessage = $("#nameErrorMessage").clone(); - $("#message-container").empty(); - $("#message-container").append(newMessage); - newMessage.removeClass("hidden"); + var newMessage = $('#nameErrorMessage').clone(); + var messageContainer = $('#message-container'); + messageContainer + .empty() + .append(newMessage); + newMessage.removeClass('hidden'); $('html, body').animate({ - scrollTop: $("#message-container").offset().top + scrollTop: messageContainer.offset().top }, 750); } }); @@ -45,30 +46,40 @@ $(document).ready(function () { }); var form = $('#comment_form'); - form.submit(function(event) { event.preventDefault(); $.ajax({ - type: "POST", + type: 'POST', url: form.attr('action'), data: form.serialize(), dataType: 'json', success: function(data) { - $('#comment').val(""); + $('#comment').val(''); if (data.result) { - $("#comments_list").replaceWith(data.comments); - var lastComment = $("#comments_list").find("div.comment").last(); + $('#comments_list') + .replaceWith(data.comments); + var lastComment = $('#comments_list') + .find('div.comment') + .last(); lastComment.effect('highlight', {color: 'green'}, 401); $('html, body').animate({ - scrollTop: $("#comments_alerts").offset().top + scrollTop: lastComment.offset().top }, 750); } else { - var newMessage = $("#genericErrorTemplate").clone(); - newMessage.find(".contents").text(data.message.message); - $("#comments_alerts").empty().append(newMessage); + var newMessage = $('#genericErrorTemplate').clone(); + newMessage + .find('.contents') + .text(data.message.message); + var commentsAlert = $('#comments_alerts'); + commentsAlert + .empty() + .append(newMessage); + $('html, body').animate({ + scrollTop: commentsAlert.offset().top + }, 750); } } });