Савинцев Егор 🚶 (savintsev_egor) wrote in changelog,
Савинцев Егор 🚶
savintsev_egor
changelog

[ljcom] r9361: LJSUP-6482: SMS Notification

Committer: esavintcev
LJSUP-6482: SMS Notification
A   trunk/htdocs/img/icons/smsn.gif
A   trunk/htdocs/js/editprofile.js
Added: trunk/htdocs/img/icons/smsn.gif
===================================================================
(Binary files differ)


Property changes on: trunk/htdocs/img/icons/smsn.gif
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: trunk/htdocs/js/editprofile.js
===================================================================
--- trunk/htdocs/js/editprofile.js	                        (rev 0)
+++ trunk/htdocs/js/editprofile.js	2010-08-20 03:16:16 UTC (rev 9361)
@@ -0,0 +1,208 @@
+(function($)
+{
+	var PhoneVerification = {
+		init: function()
+		{
+			this.supportedProviders = ['beeline', 'megafon'];
+			this.table = $('#phone_verification');
+			this.ui = {
+				table: this.table,
+				provider: this.table.find('[name=txtmsg_provider]'),
+				resendBtn: this.table.find('[name=sendsms]'),
+				phInput: this.table.find('[name=txtmsg_number]'),
+				phViewOptions: $('#phone_view_options'),
+				notification: this.table.find('.b-manage-smsn-status')
+			}
+			this.verifyTimer = null;
+			this.endpoint = "/tools/endpoints/validate_phone.bml";
+
+			this.supportedProviderEls = this.table.find('.b-manage-smsn-status')
+				.add(this.table.find('.b-manage-smsn-btn'))
+				.add(this.table.find('.helper'))
+			this.unsupportedProviderEls = this.ui.phViewOptions
+				.add(this.table.find('tr:first span'))
+			this.verifiedElement = this.table.find('.b-manage-smsn-btn');
+
+			this.table.find('.b-manage-smsn').removeClass('b-manage-smsn-hide');
+			var that = this;
+
+			this.viewOptionsValue = '';
+			this.ui.provider.change(function()
+			{
+				that.checkProvider(this.value);
+			});
+
+			if(this.checkProvider(this.ui.provider.val()))
+			{
+				if(this.testPhoneNumber(this.ui.phInput.val()))
+					this.checkVerification();
+				else 
+					that.setState('badNum', 'error', 'badnum');
+			}
+			else {
+				this.setState('initial', 'info', 'initial');
+			}
+
+			this.ui.phInput.keypress(function(ev)
+			{
+				var input = this;
+				setTimeout(function()
+				{
+					if(input.value.length == 0)
+					{
+						that.setState('initial', 'info', 'initial');
+						return;
+					}
+
+					if(that.testPhoneNumber(input.value))
+					{
+						that.setState('correctNum', 'success', 'correctnum');
+					}
+					else {
+						that.setState('badNum', 'error', 'badnum');
+					}
+				},0);
+			});
+
+			this.ui.resendBtn.click(function()
+			{
+				var phone = that.ui.phInput.val();
+				that.sendVerification(phone);
+			});
+
+			this.ui.notification.ajaxError(function(ev, req, settings)
+			{
+				$(this).html('ajax error').setClass('notifyerror');
+			});
+		},
+
+		checkProvider: function(selectVal)
+		{
+			if($.inArray(selectVal, this.supportedProviders) >= 0)
+			{
+				this.supportedProviderEls.css('display','');
+				this.unsupportedProviderEls.css('display','none');
+				this.setState('initial', 'info', 'initial');
+				this.viewOptionsValue = this.ui.phViewOptions.val();
+				this.ui.phViewOptions.val('friends');
+				this.ui.resendBtn.attr('disabled', false);
+				return true;
+			}
+			else
+			{
+				this.supportedProviderEls.css('display','none');
+				this.unsupportedProviderEls.css('display','');
+				this.ui.phViewOptions.val(this.viewOptionsValue);
+				this.viewOptionsValue = '';
+				return false;
+			}
+		},
+
+		sendVerification: function(number)
+		{
+			var that = this;
+			$.get(this.endpoint + '?action=validate&phone=' + number,function(data)
+			{
+				var answer = $.trim(data);
+				switch(answer)
+				{
+					case 'accepted': that.setState('requestsent', 'success', 'reqsent'); 
+									that.checkVerification();
+									break;
+					case 'rate_limit_exceded': that.setState('totallimitexceeded', 'error', 'rateexceed'); break;
+				}
+			});
+		},
+
+		checkVerification: function()
+		{
+			var that = this;
+			this.verifyTimer = setInterval(function()
+			{
+				$.get(that.endpoint, function(data)
+				{
+					var result = $.trim(data.replace('status:',''));
+					switch(result)
+					{
+						case 'rate_limit_exceded': that.setState('totallimitexceeded', 'error', 'rateexceed'); break;
+						case 'verification_sms_sended': that.setState('smssent', 'success', 'smssent'); break;
+						case 'wrong_rcpt_number': that.setState('notasubscriber', 'error'); break;
+						case 'verified': that.setState('verified', 'success', 'verified'); break;
+						case 'verification_outdated': that.setState('linkexpired', 'error'); break;
+						case 'added': that.setState('requestsent', 'success', 'reqsent'); break;
+					}
+				});
+			}, 1500);
+		},
+
+		setState: function(text, status, event)
+		{
+			event = event || "";
+			var n = this.ui.notification,
+				bt = this.ui.resendBtn,
+				dict = smsNotifyDict || {},
+				bubble = n.find('.i-bubble');
+
+			function setBubble(state)
+			{
+				var states = {
+					'info':  'b-bubble-lite',
+					'success':  'b-bubble-alert',
+					'error': 'b-bubble-warning'
+				}
+
+				for(var i in states)
+					bubble[(state == i)?"addClass":"removeClass"](states[i]);
+			}
+
+			switch(status)
+			{
+				case 'info': setBubble('info'); break;
+				case 'success': setBubble('success'); break;
+				case 'error': setBubble('error'); break;
+			}
+
+			if(event.length > 0)
+			{
+				var eventClasses = ['initial', 'badnum', 'correctnum', 'reqsent', 'rateexceed', 'verified'];
+				n.find(".i-manage-smsn-icon").removeClass($.map(eventClasses, function(el){ return "i-manage-smsn-" + el }).join(' '));
+				n.find(".i-manage-smsn-icon").addClass("i-manage-smsn-" + event);
+				switch(event)
+				{
+					case 'initial':
+					case 'badnum':  bt.attr('disabled', true);
+									bt.val(smsNotifyDict['sendsmsbut']);
+									this.ui.resendBtn.parent('.b-manage-smsn-btn').css('display','');
+									clearInterval(this.verifyTimer);
+									break;
+					case 'correctnum': bt.attr('disabled', false);
+									bt.val(smsNotifyDict['sendsmsbut']);
+									this.ui.resendBtn.parent('.b-manage-smsn-btn').css('display','');
+									clearInterval(this.verifyTimer);
+									break;
+					case 'reqsent':	bt.val( dict['resendsmsbut']);
+									this.ui.resendBtn.parent('.b-manage-smsn-btn').css('display','');
+									break;
+					case 'rateexceed': bt.attr('disabled', true);
+									this.ui.resendBtn.parent('.b-manage-smsn-btn').css('display','');
+									break;
+					case 'verified': /* hide send button */
+									clearInterval(this.verifyTimer);
+									this.ui.resendBtn.parent('.b-manage-smsn-btn').css('display','none');
+									break;
+				}
+			}
+
+			var msg = smsNotifyDict[text] || text;
+			bubble.find('span').html(msg);
+		},
+
+		testPhoneNumber: function(number)
+		{
+			return /^\+\d{11,16}$/.test(number);
+		}
+	}
+
+	$(function(){ PhoneVerification.init() });
+
+})(jQuery);

Tags: gif, js, ljcom, savintsev_egor
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