summaryrefslogtreecommitdiffstats
path: root/web-gui/login/source/class/login/Application.js
blob: 6d0e0e5655fe0ade7036ca3e5bb6981b29cc4f40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/* ************************************************************************

	 Copyright:

	 License:

	 Authors:

************************************************************************ */

/* ************************************************************************

#asset(login/*)

************************************************************************ */

/**
 * This is the main application class of your custom application "login"
 */
qx.Class.define("login.Application",
{
extend : qx.application.Standalone,



/*
*****************************************************************************
	 MEMBERS
*****************************************************************************
*/

members :
{
	__users: null,
	__result: null,
	__error: null,
	__rpc: null,
	/**
	 * This method contains the initial application code and gets called 
	 * during startup of the application
	 * 
	 * @lint ignoreDeprecated(alert)
	 */
	main : function()
	{
		// Call super class
		this.base(arguments);

		// Enable logging in debug variant
		if (qx.core.Variant.isSet("qx.debug", "on"))
		{
			// support native logging capabilities, e.g. Firebug for Firefox
			qx.log.appender.Native;
			// support additional cross-browser console. Press F7 to toggle visibility
			qx.log.appender.Console;
		}

		/*
		-------------------------------------------------------------------------
			Below is your actual application code...
		-------------------------------------------------------------------------
		*/

		var doc = this.getRoot();
		doc.setBackgroundColor("#ffffff");

		var back = new qx.ui.basic.Image("login/back.png");
		back.setScale(true);
		doc.add(back, {left:0, top: 0});


		var core = new qx.ui.container.Composite(new qx.ui.layout.Grid());
		doc.add(core, {left: 120, top: 100});
		core.getLayout().setSpacing(10);
		core.getLayout().setColumnAlign(0, "left", "middle");
		core.getLayout().setColumnFlex(3, 100);
		core.setWidth(800);


		core.add( new qx.ui.basic.Label("Login Data:"), {row: 0, column: 0, colSpan: 3});

		var lUser = new qx.ui.form.RadioButton("User Role");
		core.add(lUser, {row: 1, column: 0});
		lUser.user = "tux";
		lUser.passwd = "fisch";
		lUser.url = "http://localhost:8080/rpc/user"
		var lAdmin = new qx.ui.form.RadioButton("Admin Role");
		core.add(lAdmin, {row: 1, column: 1});
		lAdmin.user = "admin";
		lAdmin.passwd = "geheim";
		lAdmin.url = "http://localhost:8080/rpc/admin"
		var lInvalid = new qx.ui.form.RadioButton("Invalid Login Data");
		core.add(lInvalid, {row: 1, column: 2});
		lInvalid.user = "tux";
		lInvalid.passwd = "wrong";
		lInvalid.url = "http://localhost:8080/rpc/user"

		this.__users = new qx.ui.form.RadioGroup(lUser, lAdmin, lInvalid);

		core.add( new qx.ui.basic.Label("Call:"), {row: 2, column: 0, colSpan: 3});
		this.__users.setSelection([lUser]);

		var helloWorld = new qx.ui.form.Button("Hello World");
		core.add(helloWorld, {row: 3, column: 0});
		helloWorld.addListener("execute", function() {
			this.__call("HelloWorld");}, this);
		var helloUser = new qx.ui.form.Button("Hello User");
		core.add(helloUser, {row: 3, column: 1});
		helloUser.addListener("execute", function() {
			this.__call("HelloUser");}, this);
		var helloAdmin = new qx.ui.form.Button("Hello Admin");
		core.add(helloAdmin, {row: 3, column: 2});
		helloAdmin.addListener("execute", function() {
			this.__call("HelloAdmin");}, this);

		core.add( new qx.ui.basic.Label("Result:"), {row: 4, column: 0});
		this.__result = new qx.ui.basic.Label("<result>");
		core.add(this.__result, {row: 4, column: 1, colSpan: 3});

		core.add( new qx.ui.basic.Label("Error:"), {row: 5, column: 0});
		this.__error = new qx.ui.basic.Label("<error>");
		this.__error.setRich(true);
		core.add(this.__error, {row: 5, column: 1, colSpan: 4});

		this.__rpc = new qx.io.remote.Rpc("http://localhost:8080/rpc", "com.pengutronix.jdb.Hello|/");
		this.__rpc.setUseBasicHttpAuth(true);
	},
	__call: function(func) {
		var radio = this.__users.getSelection()[0];
		this.__rpc.setUsername(radio.user);
		this.__rpc.setPassword(radio.passwd);
		this.__rpc.setUrl(radio.url);
		this.__rpc.callAsync(qx.lang.Function.bind(this.__callback, this),
			"com.pengutronix.jdb.Hello." + func);
	},
	__callback: function(result, error) {
		if (error != null) {
			this.__result.setValue("");
			this.__error.setValue(error);
		}
		else {
			this.__result.setValue(result);
			this.__error.setValue("");
		}
	}
}
});