diff --git a/cgi-bin/compilejs.py b/cgi-bin/compilejs.py index aaf8e65010..9c2a8e1af8 100644 --- a/cgi-bin/compilejs.py +++ b/cgi-bin/compilejs.py @@ -70,4 +70,4 @@ class wnJSCompiler: if __name__=="__main__": a = wnJSCompiler() - print a.compilejs('../js/wntest') + print a.compilejs('../js/wn') diff --git a/cgi-bin/getjsfile.cgi b/cgi-bin/getjsfile.cgi index 889e8c6c15..2845026485 100755 --- a/cgi-bin/getjsfile.cgi +++ b/cgi-bin/getjsfile.cgi @@ -28,7 +28,6 @@ try: global jsonout import webnotes.utils.jsnamespace as jsn filename = jsn.jsNamespace.modname_to_filename(module_name,jsdir) - print 'filename is ' + filename import os try: f = open(os.path.join(filename)) @@ -41,6 +40,7 @@ try: jsonout[module_name]=out def load_js_module(module_name): + global jsonout from webnotes import defs devmode = getattr(defs,'developer_mode') if devmode: @@ -49,12 +49,11 @@ try: if module_name not in jsonout: dependent_mods = get_dependencies(module_name) for module in dependent_mods: - load_js_module(module) - load_js_from_file(module_name) + load_js_from_file(module) + load_js_from_file(module_name) def get_dependencies(module_name): import webnotes.utils.jsdependency as jsd - print 'module_name is ' + module_name ret = jsd.jsDependencyBuilder.build_dependency(jsdir,module_name) return ret @@ -74,7 +73,8 @@ try: except: pass - load_js_module('wntest.a.s') + load_js_module(form.getvalue('module')) + #load_js_module('wn.modules') if compress and len(out)>512: out_buf = compress_string(str_out) diff --git a/cgi-bin/webnotes/utils/jstimestamp.py b/cgi-bin/webnotes/utils/jstimestamp.py index a5785c2fb9..57eb6055af 100644 --- a/cgi-bin/webnotes/utils/jstimestamp.py +++ b/cgi-bin/webnotes/utils/jstimestamp.py @@ -1,5 +1,5 @@ class generateTimestamp: - ts_filename = 'timestamp.json' + ts_filename = 'timestamp.js' @staticmethod def list_js_files(jsdir,ext='js'): import os @@ -13,7 +13,7 @@ class generateTimestamp: for filename in files: if filename.endswith(ext): all_files.append(os.path.join(root,filename)) - + os.chdir(oldcwd) for i in nono: for j in all_files: @@ -41,6 +41,7 @@ class generateTimestamp: filename = filename.lstrip('./') filename = filename.rstrip('.js') filename = filename.replace('/','.') + #TODO Remove _packagename from the end if file is a package tsdict[filename] = ts os.chdir(oldcwd) return tsdict @@ -69,6 +70,8 @@ class generateTimestamp: import json import os tsdict = generateTimestamp.gents(jsdir) - f = open(os.path.join(jsdir,generateTimestamp.ts_filename),'w') + f = open(os.path.join(jsdir,'wn',generateTimestamp.ts_filename),'w') #FIXME Hard coded! + f.write('wn={}\n') + f.write('wn.timestamp=') f.write(json.dumps(tsdict)) f.close() diff --git a/js/wn/modules.js b/js/wn/modules.js index 2fddf8c734..ec4f617ce1 100644 --- a/js/wn/modules.js +++ b/js/wn/modules.js @@ -13,37 +13,51 @@ wn.module = { if(wn[module_name]) return; wn.module.load(module_name, callback); }, - + load: function(module_name, callback) { // if loaded in local and recent + alert('checking in local') if(wn.module.in_local(module_name)) { if(callback) callback(); return; } + alert('loading from server') + wn.module.get_from_server(module_name,callback ) + + + }, + get_from_server : function(module_name, callback) { - var req = $.ajax({ - url: 'js/' + module_name.replace(/./g, "/"), - datatype:'script', - success: wn.module.accept - }); - req.module_name = module_name; - req.callback = callback; + req = $.ajax({ + url: 'cgi-bin/getjsfile.cgi?module=' + module_name, // TODO use getjsfile.cgi, replace not reqd + datatype:'text', + success: [wn.module.accept,callback] + }) }, in_local: function(module_name) { - var m = localStorage.getItem(module_name); - if(m && m.timestamp == wn.timestamps[module_name]) { + // check if module in local and recent + var m = JSON.parse(localStorage.getItem(module_name)); + alert('in_local' + m.timestamp) + if( m && m.timestamp == wn.timestamps[module_name]) { eval(m.code); return true; } + return false }, - accept: function(data, status, req) { - var m = { - timestamp: wn.timestamps[req.module_name], - code: data, + accept: function(data, status, jqXHR) { + + data = JSON.parse(data) + for (var codename in data) + { + localStorage.setItem(codename, JSON.stringify({ + + timestamp : wn.timestamps[codename], + code : data[codename] + + })) + eval(data[codename]) } - localStorage.setItem(req.module_name, m); - if(req.callback) req.callback(); } } diff --git a/test.html b/test.html new file mode 100644 index 0000000000..aa5d63688f --- /dev/null +++ b/test.html @@ -0,0 +1,11 @@ + +
+ + + + + + + loaded + +