app/script.js
/* Loads a number of notes from the server and renders the result. The actual number to be loaded 
  is passed in as 'count'. */
Loads a number of notes from the server and renders the result. The actual number to be loaded
is passed in as 'count'.
Loads a number of notes from the server and renders the result . The actual number to be loaded is passed in as ' count ' .
function loadnotes(count) {
    $('#message').hide();
    count = count || 100;
    var storage = new nive.DataStorage({name:'notes'});
    storage.list({key:'note', sort:'timestamp', order:'>', size:count})
        .done(function (data, message, xhr) {
            var notes = data.items;
            var blocks = "";
            for(i=0;i<notes.length;i++) {
                var html = note_tmpl;
                var newDate = new Date();
                newDate.setTime(notes[i].timestamp*1000);
                ts = newDate.toLocaleString();
                html = html.replace("-id-", notes[i].id);
                html = html.replace("-id-", notes[i].id);
                html = html.replace("-id-", notes[i].id);
                html = html.replace("-text-", notes[i].value);
                html = html.replace("-date-", ts);
                blocks += html;
            }
            $('#notecontainer').after(blocks);
        })
        .fail(function (jqXHR, message, error) {
            if(jqXHR.status=='403') {
                $('#message span').html('Please sign in!');
                $('#message').show('fast');
            } else {
                $('#message span').html('Sorry! ' + error + '. ' + jqXHR.responseJSON.error);
                $('#message').show('fast');
            }
        });
}
function loadnotes ( count ) { $ ( '#message' ) . hide ( ) ; count = count || 100 ; var storage = new nive . DataStorage ( { name : 'notes' } ) ; storage . list ( { key : 'note' , sort : 'timestamp' , order : '>' , size : count } ) . done ( function ( data , message , xhr ) { var notes = data . items ; var blocks = "" ; for ( i = 0 ; i < notes . length ; i ++ ) { var html = note_tmpl ; var newDate = new Date ( ) ; newDate . setTime ( notes [ i ] . timestamp * 1000 ) ; ts = newDate . toLocaleString ( ) ; html = html . replace ( "-id-" , notes [ i ] . id ) ; html = html . replace ( "-id-" , notes [ i ] . id ) ; html = html . replace ( "-id-" , notes [ i ] . id ) ; html = html . replace ( "-text-" , notes [ i ] . value ) ; html = html . replace ( "-date-" , ts ) ; blocks += html ; } $ ( '#notecontainer' ) . after ( blocks ) ; } ) . fail ( function ( jqXHR , message , error ) { if ( jqXHR . status == '403' ) { $ ( '#message span' ) . html ( 'Please sign in!' ) ; $ ( '#message' ) . show ( 'fast' ) ; } else { $ ( '#message span' ) . html ( 'Sorry! ' + error + '. ' + jqXHR . responseJSON . error ) ; $ ( '#message' ) . show ( 'fast' ) ; } } ) ; }
Loads a number of notes from the server and renders the result.
Loads a number of notes from the server and renders the result .
// creates a nive DataStorage object and calls 'list()' to retrieve the notes from // the server.  // success: notes received // error: something went wrong