Vlad Kurkin (b_vladi) wrote in changelog,
Vlad Kurkin
b_vladi
changelog

[livejournal] r21484: LJSUP-11421: Cliend-side development for...

Committer: vkurkin
LJSUP-11421: Cliend-side development for Trava.ru
U   trunk/htdocs/js/settings.js
Modified: trunk/htdocs/js/settings.js
===================================================================
--- trunk/htdocs/js/settings.js	2012-03-21 08:30:18 UTC (rev 21483)
+++ trunk/htdocs/js/settings.js	2012-03-21 08:51:50 UTC (rev 21484)
@@ -36,32 +36,32 @@
 			Trava: '#LJ__Setting__Music__Trava_',
 			LastFM: '#LJ__Setting__Music__LastFM_',
 			connectLink: '.music-settings-connect',
-			uIdInput: 'input name="LJ__Setting__Music__Trava_trava_uid"'
+			uIdInput: 'input[name="LJ__Setting__Music__Trava_trava_uid"]'
 		},
 		classNames: {
 			login: 'music-settings-login',
 			disconnect: 'music-settings-disconnect',
 			loading: 'music-settings-loading',
 			error: 'music-settings-error'
-		},
-		url: {
-			trava: 'http://trava.ru/json/autologin'
 		}
 	};
 
 	var travaElement = $(options.selectors.Trava);
+	var hiddenField = travaElement.find(options.selectors.uIdInput);
 
-	function onGetUserData(data) {
-		travaElement
-			.removeClass(options.classNames.loading)
-			.removeClass(options.classNames.error)
-			.addClass(data.uid === 1 ? options.classNames.disconnect : options.classNames.login);
-		$(options.selectors.uIdInput).val(data.uid);
-	}
+	function onLogin(evt, data) {
+		if (data) {
+			travaElement
+				.removeClass(options.classNames.loading)
+				.removeClass(options.classNames.error)
+				.removeClass(options.classNames.disconnect)
+				.addClass(data.uid === 1 ? options.classNames.disconnect : options.classNames.login);
 
-	function errorGetUserData() {
-		travaElement.addClass(options.classNames.error);
-		travaElement.removeClass(options.classNames.loading);
+			hiddenField.val(data.uid);
+		} else {
+			travaElement.addClass(options.classNames.error);
+			travaElement.removeClass(options.classNames.loading);
+		}
 	}
 
 	$('select[name="music_select"]').bind('change', function () {
@@ -72,17 +72,12 @@
 		$(currentID).show();
 	}).trigger('change');
 
+	travaElement.trava().bind('travalogin', onLogin);
 
 	travaElement.delegate(options.selectors.connectLink, 'click', function (evt) {
 		evt.preventDefault();
 		travaElement.addClass(options.classNames.loading);
-		$.ajax({
-			url: options.url.trava,
-			cache: false,
-			dataType: 'jsonp',
-			success: onGetUserData,
-			error: errorGetUserData
-		});
+		travaElement.trava('login');
 	});
 });
 

Tags: b_vladi, js, livejournal, vkurkin
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