Aralot (aralot) wrote in changelog,
Aralot
aralot
changelog

[livejournal] r17307: LJSUP-6572: reject user form js

Committer: szhirkov
LJSUP-6572: reject user form js
U   trunk/htdocs/community/pending.bml
A   trunk/htdocs/js/reject.js
Modified: trunk/htdocs/community/pending.bml
===================================================================
--- trunk/htdocs/community/pending.bml	2010-09-08 09:21:07 UTC (rev 17306)
+++ trunk/htdocs/community/pending.bml	2010-09-08 10:29:55 UTC (rev 17307)
@@ -7,6 +7,7 @@
     use vars qw(%GET %POST);
 
     LJ::set_active_crumb('commpending');
+	LJ::need_res('js/reject.js');
 
     return LJ::server_down_html() if $LJ::SERVER_DOWN;
 
@@ -94,7 +95,7 @@
             } else {
                 $ret .= "<form method='post' action='pending.bml?authas=$cname'>\n";
                 $ret .= LJ::form_auth();
-                $ret .= '<ul class="b-pending-users"><li>' . join (", </li><li>", map { "<span><a href='" . $_->journal_base . "' target='_blank'>" . $_->{user} . "</a><i class='i-pending-close' title='" . $ML{'.button.remove'} . "'></i></span>" } @to_show) . "</li></ul>\n";
+                $ret .= '<ul class="b-pending-users"><li>' . join (", </li><li>", map { "<span><a href='" . $_->journal_base . "' target='_blank'>" . $_->{user} . "</a><i id=\"reject_user_id_".$_->{userid}."\" class='i-pending-close' title='" . $ML{'.button.remove'} . "'></i></span>" } @to_show) . "</li></ul>\n";
                 $ret .= LJ::html_hidden('ids', join(',', map { $_->{'userid'} } @to_show)) . "\n";
                 $ret .= "<textarea name='reason' rows='7' cols='50' class='b-pending-reason' placeholder='".$ML{'.reason.default.text'}."'></textarea>\n";
                 $ret .= LJ::html_hidden('reject_done', 1);

Added: trunk/htdocs/js/reject.js
===================================================================
--- trunk/htdocs/js/reject.js	                        (rev 0)
+++ trunk/htdocs/js/reject.js	2010-09-08 10:29:55 UTC (rev 17307)
@@ -0,0 +1,74 @@
+(function ($) {
+	$(function () {
+		rejectFormManager.init();
+	});
+	
+	var rejectFormManager = (function () {
+		var CONFIG = {
+			containerSelector : '.b-pending',
+			removeControlsSelector : '.i-pending-close',
+			textareaSelector : '.b-pending-reason',
+			hiddenWithIdsSelector : 'input[name=ids]',
+			userListSelector : '.b-pending-users'
+		};
+		
+		var _containter, _hiddenWithIds, _removeControls, _userList;
+		
+		function findElems () {
+			_container = $(CONFIG.containerSelector);
+			_hiddenWithIds = _container.find(CONFIG.hiddenWithIdsSelector);
+			_userList = _container.find(CONFIG.userListSelector);
+			_removeControls = _userList.find(CONFIG.removeControlsSelector);
+		}
+		
+		function bindRemoveUser () {
+			_removeControls.bind('click', removeUser);
+		}
+		
+		function removeUser (event) {
+			event.preventDefault();
+			
+			var currentControl = $(this),
+				elemToRemove = currentControl.closest('li'),
+				userId = currentControl.attr('id').replace(/\D+/g, '');
+			
+			removeUserIdFromHidden(userId);
+			
+			elemToRemove.remove();
+			removeUnwantedCommas();
+		}
+		
+		function removeUnwantedCommas () {
+			var userListLength = _userList.find('li').length,
+				firstUserElem, firstUserContent;
+			
+			if (userListLength === 1) {
+				firstUserElem = _userList.first();
+				contentWithoutCommas = firstUserElem.html().replace(/\,/g, '');
+				firstUserElem.html(contentWithoutCommas);
+			}
+		}
+		
+		function removeUserIdFromHidden (userId) {
+			var hiddenValue = _hiddenWithIds.val(),
+				regExpToCheck = new RegExp('(' + userId + ')' + '(\,)*', 'g'),
+				newHiddenValue = hiddenValue.replace(regExpToCheck, '');
+			
+			_hiddenWithIds.val(newHiddenValue);
+		}
+		
+		function initPlaceholder () {
+			var textarea = _container.find(CONFIG.textareaSelector);
+			
+			textarea.placeholder(); 
+		}
+		
+		return {
+			init : function () {
+				findElems();
+				bindRemoveUser();
+				initPlaceholder();
+			}
+		};
+	})();
+})(jQuery);

Tags: aralot, bml, js, livejournal
Subscribe

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments