Click here to Skip to main content
15,884,099 members
Articles / Web Development / ASP.NET

AsyncMethods - An Improvement on Microsoft's ScriptMethods

Rate me:
Please Sign up or sign in to vote.
4.76/5 (9 votes)
10 Aug 2011CPOL11 min read 29K   362   17  
A lightweight, secure, and better organized version of Microsoft's ScriptMethods.
$(document).ready(function()
{
    $('#users_refresh').click(refreshUsers);

    $('#login_button').click(function()
    {
        Forums.Login($('#un').val(), $('#pw').val(), function(result)
        {
            if (result)
            {
                window.location = window.location;
            }
            else
            {
                alert('Login failed. Please try again.');
                return;
            }
        }, alertResult);
    });

    refreshPosts();

    if ($('#users').length > 0) refreshUsers();
});

function refreshPosts()
{
    Forums.GetForumPosts(setContent, setContent, '#posts');
}

function refreshUsers()
{
    Forums.GetUsers(setContent, setContent, '#users');
}

function addPost()
{
    var text = $('#post_text').val();

    if (text == '')
    {
        alert('You must provide post text');
        return;
    }

    Forums.AddPost(text, function()
    {
        $('#post_text').val('');
        refreshPosts();
    }, alertResult);
}

function approvePost(id)
{
    if (!confirm('Are you sure you want to approve this post?')) return;

    Forums.ApprovePost(id, refreshPosts, alertResult);    
}

function deletePost(id)
{
    if (!confirm('Are you sure you want to delete this post?')) return;
    Forums.DeletePost(id, refreshPosts, alertResult);
}

function addUser()
{
    var un = $('#new_un').val();
    var pw = $('#new_pw').val();
    var role = $('#new_role').val();

    if (un == '' || pw == '')
    {
        alert('You must provide a user name and password');
        return;
    }

    Forums.AddUser(un, pw, role, function()
    {
        $('#new_un').val('');
        $('#new_pw').val('');
        $('#new_role').val('User');

        refreshUsers();
    }, alertResult);
}

function deleteUser(un)
{
    if (!confirm('Are you sure you want to delete ' + un + '?')) return;

    Forums.DeleteUser(un, refreshUsers, alertResult);
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) digifi inc.
Canada Canada
Clayton Rumley is web developer for hire from Winnipeg, Manitoba, Canada.

Comments and Discussions