diff --git a/core_src/beluga/Beluga.hx b/core_src/beluga/Beluga.hx index 3157092..d15570d 100644 --- a/core_src/beluga/Beluga.hx +++ b/core_src/beluga/Beluga.hx @@ -41,8 +41,8 @@ class Beluga { public var api(default, null) : BelugaApi; private var modules = new ObjectMap(); private static var instance = null; + public var remoting = new haxe.remoting.Context(); - public static var remotingCtx; public static function getInstance(cnx: Connection = null) : Beluga { if (instance == null) { instance = new Beluga(cnx); @@ -66,7 +66,6 @@ class Beluga { initDatabase(cnx); //Create beluga API api = new BelugaApi(); - remotingCtx = new haxe.remoting.Context(); //Compile JS assets beluga.resource.JavascriptBuilder.compile(); @@ -131,8 +130,8 @@ class Beluga { throw new BelugaException("Beluga Rest Api not yet supported"); }, doDefault: function(d : Dispatch) { - if (!haxe.remoting.HttpConnection.handleRequest(remotingCtx)) { - d.dispatch(api); + if (!haxe.remoting.HttpConnection.handleRequest(remoting)) { + d.dispatch(api); } } diff --git a/core_src/beluga/ConfigLoader.hx b/core_src/beluga/ConfigLoader.hx index 54d17ba..cfb8889 100644 --- a/core_src/beluga/ConfigLoader.hx +++ b/core_src/beluga/ConfigLoader.hx @@ -125,7 +125,7 @@ class ConfigLoader { macro private static function loadConfig() : Expr { //Load configuration - builtConfigString = File.getContent(configFilePath); + builtConfigString = File.getContent(Context.resolvePath(configFilePath)); var xml = Xml.parse(builtConfigString); clearForTarget(xml, getCompilationTarget()); diff --git a/module_src/beluga/module/account/Account.hx b/module_src/beluga/module/account/Account.hx index 6bc6076..e7fcbf0 100644 --- a/module_src/beluga/module/account/Account.hx +++ b/module_src/beluga/module/account/Account.hx @@ -58,6 +58,11 @@ class Account extends Module { this.widgets = new AccountWidget(); beluga.db.initTable(User); beluga.api.register("account", new AccountApi(beluga, this)); + beluga.remoting.addObject("Account", { + login : function (param1, param2) { + return "param receive " + param1 + " " + param2; + } + }); } public function getLoggedUser() : User { @@ -68,12 +73,11 @@ class Account extends Module { this.loggedUser = null; triggers.afterLogout.dispatch(); } - + public function login(args : { login : String, password : String }) { - var user : List = User.manager.dynamicSearch({login : args.login}); if (user.length > 1) { //Somethings wrong in database diff --git a/module_src/beluga/module/account/view/js/Login.hx b/module_src/beluga/module/account/view/js/Login.hx deleted file mode 100644 index aabd0dc..0000000 --- a/module_src/beluga/module/account/view/js/Login.hx +++ /dev/null @@ -1,19 +0,0 @@ -package beluga.module.account.view.js; - -/** - * ... - * @author brissa_A - */ -class Login -{ - - public static function main() { - - } - - public function new() - { - - } - -} \ No newline at end of file diff --git a/module_src/beluga/module/account/view/js/LoginFormJs.hx b/module_src/beluga/module/account/view/js/LoginFormJs.hx new file mode 100644 index 0000000..276f50c --- /dev/null +++ b/module_src/beluga/module/account/view/js/LoginFormJs.hx @@ -0,0 +1,43 @@ +// Copyright 2014 The Beluga Project Developers. See the LICENCE.md +// file at the top-level directory of this distribution and at +// http://haxebeluga.github.io/licence.html. +// +// Licensed under the MIT License. +// This file may not be copied, modified, or distributed +// except according to those terms. + +package beluga.module.account.view.js; + +#if js +import js.Browser; +#end + +class LoginFormJs implements beluga.resource.Javascript { + + #if js + private var cnx : haxe.remoting.HttpAsyncConnection ; + #end + + public function new() { + #if js + //Called when the script is loaded + js.Browser.window.console.log("LoginFormJs script started"); + cnx = haxe.remoting.HttpAsyncConnection.urlConnect("http://" + Browser.location.host + "/beluga/"); + cnx.setErrorHandler( function(err) { trace("Error : " + Std.string(err)); } ); + cnx.Account.login.call(["toto", "tata"], onLogin); + #end + } + + public function onLogin(v) { + trace(v); + } + + public function ready() + { + #if js + //Called when the DOM is ready + js.Browser.window.console.log("DOM Ready"); + #end + } + +} diff --git a/module_src/beluga/module/account/widget/LoginForm.hx b/module_src/beluga/module/account/widget/LoginForm.hx index 9560d6a..e7ef333 100644 --- a/module_src/beluga/module/account/widget/LoginForm.hx +++ b/module_src/beluga/module/account/widget/LoginForm.hx @@ -17,6 +17,8 @@ import beluga.I18n; import beluga.tool.DynamicTool; import beluga.resource.ResourceManager; +import beluga.module.account.view.js.LoginFormJs; + class LoginForm extends MttWidget { public function new (?mttfile : String) { diff --git a/test/src/Main.hx b/test/src/Main.hx index 6bf18a3..60fe3b5 100644 --- a/test/src/Main.hx +++ b/test/src/Main.hx @@ -75,9 +75,9 @@ class Main { notification = new NotificationTest(beluga); if (!beluga.handleRequest()) { Dispatch.run(beluga.getDispatchUri(), Web.getParams(), new Main()); + Log.flush(); } beluga.cleanup(); - Log.flush(); } catch (e: BelugaException) { trace(e); } diff --git a/test/src/ModuleTestApi.hx b/test/src/ModuleTestApi.hx new file mode 100644 index 0000000..c44180c --- /dev/null +++ b/test/src/ModuleTestApi.hx @@ -0,0 +1,14 @@ +package ; + +import haxe.macro.Expr; +import haxe.web.Dispatch; + +class ModuleTestApi +{ + public static var module_test_map = new Map (); + + macro public static function addModule(name : Expr, module : Expr) { + return macro ModuleTestApi.module_test_map[${name}] = haxe.web.Dispatch.make(${module}); + } + +} \ No newline at end of file