Thursday, June 6, 2013

RapydScript : RPC Call

/Applications/web2py/applications/Gallerie/static/js/main.py.html
import stdlib

JQuery = $

listDiv = ['raph','fam','baby']
pathTemplates = "/Gallerie/static/templates/"

def rpcCall(meth, params):
    d = $.Deferred()
    _url = '/Gallerie/default/call/jsonrpc'
    _data = JSON.stringify ({jsonrpc:'2.0',method:meth, params:[params],id:"jsonrpc"} )
    _type = "POST"
    _dataType: "json"
    _success =  def (result):
        d.resolve(result)
    _error = def (err, status, thrown):
        alert("Error")
    _complete = def (xhr, status):
        data = JQuery.parseJSON(xhr.responseText)
    param = { url : _url, data : _data, type : _type, success : _success, error : _error, complete:_complete  }
    JQuery.ajax(param)
    return d.promise()

def  getPhotos(arg, theme = "Hyeddd...;"):
    hideAllDivs()
    if (window.sessionStorage[arg] == 'loaded') :
        showDiv(arg)
        return
    alert("loading  " + arg)
    request =  rpcCall('getPhotos',{nom : arg})
    request.done(
                  def (r):
                      #alert(r.result)
                      showDiv(arg,r.result)
                      window.sessionStorage[arg] = "loaded"
                )

def hideAllDivs():
    for div in listDiv:
        $("#" + div).hide()

def showDiv(div,result):
    data = {title : "ALBUM", theme : result}
    html = new EJS({url: pathTemplates + 'displayphoto.ejs'}).render(data)
    elt = "#" + div
    $(elt).html(html)
    $(elt).show()

alert("main")
#Exported functions
window.getPhotos = getPhotos
-->

No comments:

Post a Comment