lib/http/public/javascripts/main.js
function refreshJobs(state, fn) {
    // TODO: clean this crap up
    var jobHeight = o('#jobs .job .block').outerHeight(true)
        , top = o(window).scrollTop()
        , height = window.innerHeight
        , visibleFrom = Math.max(0, Math.floor(top / jobHeight))
        , visibleTo = Math.floor((top + height) / jobHeight)
        , url = './jobs/'
            + (filter ? filter + '/' : '')
            + state + '/0..' + to
            + '/' + sort;

    // var color = ['blue', 'red', 'yellow', 'green', 'purple'][Math.random() * 5 | 0];

    request(url, function (jobs) {
        var len = jobs.length
            , job
            , el;

        // remove jobs which have changed their state
        o('#jobs .job').each(function (i, el) {
            var el = $(el)
                , id = (el.attr('id') || '').replace('job-', '')
                , found = jobs.some(function (job) {
                    return job && id == job.id;
                });
            if (!found) el.remove();
        });

        for (var i = 0; i < len; ++i) {
            if (!jobs[i]) continue;

            // exists
            if (o('#job-' + jobs[i].id).length) {
                if (i < visibleFrom || i > visibleTo) continue;
                el = o('#job-' + jobs[i].id);
                // el.css('background-color', color);
                job = el.get(0).job;
                job.update(jobs[i])
                    .showProgress('active' == active)
                    .showErrorMessage('failed' == active)
                    .render();
                // new
            } else {
                job = new Job(jobs[i]);
                el = job.showProgress('active' == active)
                    .showErrorMessage('failed' == active)
                    .render(true);

                el.get(0).job = job;
                el.appendTo('#jobs');
            }
        }

        fn();
    });
}
function refreshJobs(state, fn) {
    // TODO: clean this crap up
    var jobHeight = o('#jobs .job .block').outerHeight(true)
        , top = o(window).scrollTop()
        , height = window.innerHeight
        , visibleFrom = Math.max(0, Math.floor(top / jobHeight))
        , visibleTo = Math.floor((top + height) / jobHeight)
        , url = './jobs/'
            + (filter ? filter + '/' : '')
            + state + '/0..' + to
            + '/' + sort;

    // var color = ['blue', 'red', 'yellow', 'green', 'purple'][Math.random() * 5 | 0];

    request(url, function (jobs) {
        var len = jobs.length
            , job
            , el;

        // remove jobs which have changed their state
        o('#jobs .job').each(function (i, el) {
            var el = $(el)
                , id = (el.attr('id') || '').replace('job-', '')
                , found = jobs.some(function (job) {
                    return job && id == job.id;
                });
            if (!found) el.remove();
        });

        for (var i = 0; i < len; ++i) {
            if (!jobs[i]) continue;

            // exists
            if (o('#job-' + jobs[i].id).length) {
                if (i < visibleFrom || i > visibleTo) continue;
                el = o('#job-' + jobs[i].id);
                // el.css('background-color', color);
                job = el.get(0).job;
                job.update(jobs[i])
                    .showProgress('active' == active)
                    .showErrorMessage('failed' == active)
                    .render();
                // new
            } else {
                job = new Job(jobs[i]);
                el = job.showProgress('active' == active)
                    .showErrorMessage('failed' == active)
                    .render(true);

                el.get(0).job = job;
                el.appendTo('#jobs');
            }
        }

        fn();
    });
}
function refreshJobs ( state , fn ) { // TODO: clean this crap up var jobHeight = o ( '#jobs .job .block' ) . outerHeight ( true ) , top = o ( window ) . scrollTop ( ) , height = window . innerHeight , visibleFrom = Math . max ( 0 , Math . floor ( top / jobHeight ) ) , visibleTo = Math . floor ( ( top + height ) / jobHeight ) , url = './jobs/' + ( filter ? filter + '/' : '' ) + state + '/0..' + to + '/' + sort ; // var color = ['blue', 'red', 'yellow', 'green', 'purple'][Math.random() * 5 | 0]; request ( url , function ( jobs ) { var len = jobs . length , job , el ; // remove jobs which have changed their state o ( '#jobs .job' ) . each ( function ( i , el ) { var el = $ ( el ) , id = ( el . attr ( 'id' ) || '' ) . replace ( 'job-' , '' ) , found = jobs . some ( function ( job ) { return job && id == job . id ; } ) ; if ( ! found ) el . remove ( ) ; } ) ; for ( var i = 0 ; i < len ; ++ i ) { if ( ! jobs [ i ] ) continue ; // exists if ( o ( '#job-' + jobs [ i ] . id ) . length ) { if ( i < visibleFrom || i > visibleTo ) continue ; el = o ( '#job-' + jobs [ i ] . id ) ; // el.css('background-color', color); job = el . get ( 0 ) . job ; job . update ( jobs [ i ] ) . showProgress ( 'active' == active ) . showErrorMessage ( 'failed' == active ) . render ( ) ; // new } else { job = new Job ( jobs [ i ] ) ; el = job . showProgress ( 'active' == active ) . showErrorMessage ( 'failed' == active ) . render ( true ) ; el . get ( 0 ) . job = job ; el . appendTo ( '#jobs' ) ; } } fn ( ) ; } ) ; }
Re-request and refresh job elements.

@param {String} state
@param {Function} fn
Re - request and refresh job elements .