View file main/templates/js/extra-js.html

File size: 3.15Kb
<script>
	function follow(user_id,object){
		if (!user_id || !object) { return false; }
		if (not(is_logged())) {
			redirect('welcome');
			return false;
		}

		object = $(object);

		var profile_type = object.attr('data-profile-type');
		if (profile_type == 0 || profile_type == 1) {
			if(object.hasClass('btn-requested') == true){
				object.find('span').text("{{LANG follow}}");
				object.find('svg').html('<path d="M16 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"></path><circle cx="8.5" cy="7" r="4"></circle><line x1="20" y1="8" x2="20" y2="14"></line><line x1="23" y1="11" x2="17" y2="11"></line>');

				if (object.hasClass('btn-requested')) {
					object.removeClass('btn-requested');
				}
			}
			else if(object.hasClass('btn-following') == true){
				object.find('span').text("{{LANG follow}}");
				object.find('svg').html('<path d="M16 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"></path><circle cx="8.5" cy="7" r="4"></circle><line x1="20" y1="8" x2="20" y2="14"></line><line x1="23" y1="11" x2="17" y2="11"></line>');

				if (object.hasClass('btn-following')) {
					object.removeClass('btn-following');
				}
			}
			else if (object.hasClass('btn-following') == false && object.hasClass('btn-requested') == false) {
				object.find('span').text("{{LANG requested}}");
				object.find('svg').html('<path d="M16 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"></path><circle cx="8.5" cy="7" r="4"></circle><polyline points="17 11 19 13 23 9"></polyline>');

				if (!object.hasClass('btn-requested')) {
					object.addClass('btn-requested');
				}
			}
		}
		else{
			if (object.hasClass('btn-following') == false) {
				object.find('span').text("{{LANG following}}");
				object.find('svg').html('<path d="M16 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"></path><circle cx="8.5" cy="7" r="4"></circle><polyline points="17 11 19 13 23 9"></polyline>');

				if (!object.hasClass('btn-following')) {
					object.addClass('btn-following');
				}
			}
			else if(object.hasClass('btn-following') == true){
				object.find('span').text("{{LANG follow}}");
				object.find('svg').html('<path d="M16 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"></path><circle cx="8.5" cy="7" r="4"></circle><line x1="20" y1="8" x2="20" y2="14"></line><line x1="23" y1="11" x2="17" y2="11"></line>');

				if (object.hasClass('btn-following')) {
					object.removeClass('btn-following');
				}
			}
			else{
				return false;
			}

		}

		
		
		$.ajax({
			url: link('main/follow'),
			type: 'GET',
			dataType: 'json',
			data: {user_id:user_id},
		}).done(function(data) {});
	}

	function report_post(post_id,zis) {
		if (not(is_logged())) {
			redirect('welcome');
			return false;
		}
		if (!post_id || !zis) {
			return false;
		}

		$.ajax({
			url: link('posts/report'),
			type: 'POST',
			dataType: 'json',
			data: {id: post_id},
		})
		.done(function(data) {
			if (data.status == 200 && data.code == 1) {
				$(zis).find('a').text('{{LANG cancel_report}}');
			}
			else if(data.status == 200 && data.code == 0){
				$(zis).find('a').text('{{LANG report_post}}');
			}

			$.toast(data.message,{
              duration: 5000, 
              type: '',
              align: 'top-right',
              singleton: false
            });
		});
	}
</script>