Project

General

Profile

Bug #5946 ยป Home.cpp

Dennis Muriuki, 09/24/2017 02:14 AM

 
1
#include "Home.h"
2
#include <Wt/WBootstrapTheme>
3
#include <Wt/WNavigationBar>
4
#include <Wt/WStackedWidget>
5
#include <Wt/WTemplate>
6
#include <Wt/WAnchor>
7
#include <Wt/WLink>
8
#include <Wt/WText>
9
#include <Wt/WMenu>
10
#include <Wt/WPushButton>
11
#include <Wt/Auth/AuthModel>
12
#include <Wt/Auth/AuthWidget>
13
#include "../Session.h"
14
#include "../Account/AuthWidget.h"
15
#include "../View/EducationLevelModelFormView.h"
16
#include "../View/FamilySizeModelFormView.h"
17
#include "../View/GenderModelFormView.h"
18
#include "../View/IncomeLevelModelFormView.h"
19
#include "../View/OccupationModelFormView.h"
20
#include "../View/MaritalStatusModelFormView.h"
21
#include "../View/CountryModelFormView.h"
22
#include "../View/SkuCategoryModelFormView.h"
23
#include "../View/SkuBrandModelFormView.h"
24
#include "../View/SkuPackageModelFormView.h"
25
#include "../View/SkuMakeModelFormView.h"
26
#include "../View/SeasonModelFormView.h"
27
#include "../View/RegionModelFormView.h"
28
#include "../View/CountyModelFormView.h"
29
#include "../View/SubcountyModelFormView.h"
30
#include "../View/TownModelFormView.h"
31
#include "../View/EntreprenuerModelFormView.h"
32
#include "../View/EnterpriseModelFormView.h"
33
#include "../View/PersonnelModelFormView.h"
34
#include "../View/SkuModelFormView.h"
35
#include "../View/StoreModelFormView.h"
36
#include "../View/YesNoModelFormView.h"
37
#include "../View/AgentTypeModelFormView.h"
38
#include "../View/AgentStatusModelFormView.h"
39
#include "../View/AssignmentTypeModelFormView.h"
40
#include "../View/AgentModelFormView.h"
41
#include "../View/OrderStatusModelFormView.h"
42
#include "../View/OrderItemStatusModelFormView.h"
43
#include "../View/OrderModelFormView.h"
44
#include "../View/OrderItemModelFormView.h"
45
#include "../View/AgentAssignmentStatusModelFormView.h"
46
#include "../View/AgentAssignmentModelFormView.h"
47
#include "../View/AgentAssignmentTaskModelFormView.h"
48
#include "../View/WishlistModelFormView.h"
49
#include "../View/CartModelFormView.h"
50
#include "../View/MessageModelFormView.h"
51
#include "../View/Seller/SellerDsModelFormView.h"
52
#include "../View/Seller/SellerEntreprenuerModelFormView.h"
53
#include "../View/Seller/SellerEnterpriseModelFormView.h"
54
#include "../View/Seller/SellerPersonnelModelFormView.h"
55
#include "../View/Seller/SellerAgentModelFormView.h"
56
#include "../View/Seller/SellerStoreModelFormView.h"
57
#include "../View/Buyer/BuyerDsModelFormView.h"
58
#include "../View/HomePageModelFormView.h"
59

    
60
Home::Home(const Wt::WEnvironment& env, Session& session) : Wt::WApplication(env), session_(session)
61
{
62
	Wt::WBootstrapTheme * p_wtTheme = new Wt::WBootstrapTheme();
63
	p_wtTheme->setVersion(Wt::WBootstrapTheme::Version3);
64
	setTheme(p_wtTheme);
65
	setTitle("The BiZKiT");
66
	messageResourceBundle().use("strings");
67
	messageResourceBundle().use("templates");
68
	useStyleSheet("resources/themes/bootstrap/3/ie10-viewport-bug-workaround.css");
69
	useStyleSheet("resources/themes/bootstrap/3/navbar-fixed-top.css");
70
	useStyleSheet("resources/themes/bootstrap/3/bootstrap.css");
71
	useStyleSheet("resources/themes/bootstrap/3/chatwidget.css");
72
	useStyleSheet("resources/themes/bootstrap/3/chatwidget_ie6.css", "lt IE 7", "all");
73
	setLocale("");
74
	language_ = 0;
75
	
76
}
77

    
78
void Home::init()
79
{
80
	internalPathChanged().connect(this, &Home::setup);
81
	internalPathChanged().connect(this, &Home::setLanguageFromPath);
82
	//internalPathChanged().connect(this, &Home::logInternalPath);
83

    
84
	createHome();
85

    
86
	setLanguageFromPath();
87
}
88

    
89
void Home::setup()
90
{
91
	/*if (!homePage_) {
92
		std::cerr << this->internalPath() << " BLAH BLAH";
93
		root()->clear();
94
		createHome();
95
		root()->addWidget(homePage_);
96
	}*/	
97

    
98
	//if (this->internalPath() == "/sellerds")
99
	//{
100
	//	root()->clear();
101
	//	createHome();
102
	//	/*root()->clear();
103
	//	WTemplate *result = new WTemplate(tr("template.homepage"), root());
104
	//	homePage_ = result;
105
	//	result->bindWidget("contents", createSellerds());*/
106
	//}
107
	//else if (this->internalPath() == "/buyerds")
108
	//{
109
	//	root()->clear();
110
	//	createHome();
111
	//	/*root()->clear();
112
	//	WTemplate *result = new WTemplate(tr("template.homepage"), root());
113
	//	homePage_ = result;
114
	//	result->bindWidget("contents", createSellerds());*/
115
	//}
116
	//else
117
	//{
118
	//	createHome();
119
	//}
120
	root()->clear();
121
	createHome();
122
	root()->addWidget(homePage_);
123
}
124

    
125
void Home::createHome()
126
{
127
	try{
128
	WTemplate *result = new WTemplate(tr("template.homepage"), root());
129
	homePage_ = result;
130

    
131
	//std::cerr << std::endl << this->internalPath() << " BLAH BLAH" << std::endl;
132

    
133
	WContainerWidget *languagesDiv = new WContainerWidget();
134
	languagesDiv->setId("top_languages");
135

    
136
	for (unsigned i = 0; i < languages.size(); ++i) {
137
		if (i != 0)
138
			new WText("- ", languagesDiv);
139

    
140
		const Lang& l = languages[i];
141

    
142
		WAnchor *langAnchor = new WAnchor(WLink(WLink::InternalPath, l.path_),
143
			WString::fromUTF8(l.longDescription_), languagesDiv);
144
		langAnchor->addStyleClass("txtwhite");
145
	}
146

    
147
	Wt::WNavigationBar *navigationBar = new Wt::WNavigationBar();
148
	navigationBar->addStyleClass(Wt::WString::fromUTF8("navbar navbar-default"));
149
	navigationBar->setInline(0);
150
	navigationBar->setResponsive("1");
151

    
152
	WStackedWidget *contents = new WStackedWidget();
153
	WAnimation fade(WAnimation::Fade, WAnimation::Linear, 250);
154
	contents->setTransitionAnimation(fade);
155
	contents->setId("main_page");
156
	contents->addStyleClass("contents spacermargin bgwhite");
157

    
158
	mainMenu_ = new WMenu(contents, Horizontal);
159

    
160
	//mainMenu_->addItem(tr("home"), new WText(tr("product-sample")))->setPathComponent("");
161
	mainMenu_->addItem(tr("home"), showHomePage())->setPathComponent("");
162
	mainMenu_->addItem(tr("shop-collection"), status(),
163
		WMenuItem::PreLoading)->setPathComponent("shop-collection");
164
	mainMenu_->addItem(tr("seasons-theme"), status(),
165
		WMenuItem::PreLoading)->setPathComponent("seasons-theme");
166
	mainMenu_->addItem(tr("tech-discovery"), status(),
167
		WMenuItem::PreLoading)->setPathComponent("tech-discovery");
168
	mainMenu_->addItem(tr("faqs"), status(),
169
		WMenuItem::PreLoading)->setPathComponent("faqs");
170

    
171
	mainMenu_->setInternalPathEnabled("/");
172
	//mainMenu_->setInternalBasePath("/");
173

    
174
	navigationBar->addMenu(mainMenu_, Wt::AlignLeft);
175
	
176
	session_.login().changed().connect(this, &Home::AuthEvent);
177
	accountMenu_ = new WMenu(contents, Horizontal);
178
	usermenu_ = new Wt::WMenuItem(tr("menu-account"));
179
	accountpopup_ = new Wt::WPopupMenu(contents);
180

    
181
	signin_ = new Wt::WMenuItem(tr("menu-signin"), createLogin(), WMenuItem::LazyLoading);
182
	//signin_->setPathComponent(tr("path-signin").toUTF8());
183
	signin_->setLink(Wt::WLink(Wt::WLink::InternalPath, tr("path-signin").toUTF8()));
184

    
185
	buyerds_ = new Wt::WMenuItem(tr("menu-buyerds"), createBuyerds(), WMenuItem::LazyLoading);
186
	//buyerds_->setPathComponent("buyerds");
187
	buyerds_->setLink(Wt::WLink(Wt::WLink::InternalPath, tr("path-buyerds").toUTF8()));
188

    
189
	sellerds_ = new Wt::WMenuItem(tr("menu-sellerds"), createSellerds(), WMenuItem::LazyLoading);
190
	//sellerds_->setPathComponent("sellerds");
191
	sellerds_->setLink(Wt::WLink(Wt::WLink::InternalPath, tr("path-sellerds").toUTF8()));
192

    
193
	profile_ = new Wt::WMenuItem(tr("menu-profile"), new WText("Profile"), WMenuItem::LazyLoading);
194
	//profile_->setPathComponent("profile");
195
	profile_->setLink(Wt::WLink(Wt::WLink::InternalPath, tr("path-profile").toUTF8()));
196

    
197
	signout_ = new Wt::WMenuItem(tr("menu-signout"));
198
	signout_->clicked().connect(this, &Home::SignedOut);
199
	//signout_->setPathComponent("");
200
	signout_->setLink(Wt::WLink(Wt::WLink::InternalPath, ""));
201

    
202
	register_ = new Wt::WMenuItem(tr("menu-register"), new WText("Register"), WMenuItem::PreLoading);
203
	//register_->setPathComponent("register");
204
	//register_->setLink(Wt::WLink(Wt::WLink::InternalPath, tr("path-register"));
205

    
206
	accountpopup_->addItem(signin_);
207
	accountpopup_->addItem(profile_);
208
	accountpopup_->addItem(buyerds_);
209
	accountpopup_->addItem(sellerds_);
210
	accountpopup_->addSeparator();
211
	accountpopup_->addItem(register_);
212
	accountpopup_->addItem(signout_);
213
	usermenu_->setMenu(accountpopup_);
214
	accountMenu_->addItem(usermenu_);
215
	//accountMenu_->setInternalPathEnabled("").toUTF8());
216

    
217
	AuthAction();
218

    
219
	accountpopup_->itemSelected().connect(std::bind([=](Wt::WMenuItem *item)
220
	{
221
		if (session_.login().loggedIn() && item->text() == tr("path-signout").toUTF8())
222
		{
223
			session_.login().logout();
224
		}
225

    
226
	}, std::placeholders::_1));
227

    
228
	result->bindWidget("languages", languagesDiv);
229
	result->bindWidget("menu", navigationBar);
230
	result->bindWidget("accountmenu", accountMenu_);
231

    
232
	if (this->internalPath() == tr("path-sellerds").toUTF8())
233
	{
234
		result->bindWidget("contents", createSellerds());
235
	}
236
	else if (this->internalPath() == tr("path-buyerds").toUTF8())
237
	{
238
		result->bindWidget("contents", createBuyerds());
239
	}
240
	else if (this->internalPath() == tr("path-adminds").toUTF8())
241
	{
242
		result->bindWidget("contents", createAdminds());
243
	}
244
	else if (this->internalPath() == tr("path-educationlevel").toUTF8())
245
	{
246
		result->bindWidget("contents", showEducationLevel());
247
	}
248
	else if (this->internalPath() == tr("path-familysize").toUTF8())
249
	{
250
		result->bindWidget("contents", showFamilySize());
251
	}
252
	else if (this->internalPath() == tr("path-gender").toUTF8())
253
	{
254
		result->bindWidget("contents", showGender());
255
	}
256
	else if (this->internalPath() == tr("path-incomelevel").toUTF8())
257
	{
258
		result->bindWidget("contents", showIncomeLevel());
259
	}
260
	else if (this->internalPath() == tr("path-occupation").toUTF8())
261
	{
262
		result->bindWidget("contents", showOccupation());
263
	}
264
	else if (this->internalPath() == tr("path-maritalstatus").toUTF8())
265
	{
266
		result->bindWidget("contents", showMaritalStatus());
267
	}
268
	else if (this->internalPath() == tr("path-country").toUTF8())
269
	{
270
		result->bindWidget("contents", showCountry());
271
	}
272
	else if (this->internalPath() == tr("path-skucategory").toUTF8())
273
	{
274
		result->bindWidget("contents", showSkuCategory());
275
	}
276
	else if (this->internalPath() == tr("path-skubrand").toUTF8())
277
	{
278
		result->bindWidget("contents", showSkuBrand());
279
	}
280
	else if (this->internalPath() == tr("path-skupackage").toUTF8())
281
	{
282
		result->bindWidget("contents", showSkuPackage());
283
	}
284
	else if (this->internalPath() == tr("path-skumake").toUTF8())
285
	{
286
		result->bindWidget("contents", showSkuMake());
287
	}
288
	else if (this->internalPath() == tr("path-season").toUTF8())
289
	{
290
		result->bindWidget("contents", showSeason());
291
	}
292
	else if (this->internalPath() == tr("path-region").toUTF8())
293
	{
294
		result->bindWidget("contents", showRegion());
295
	}
296
	else if (this->internalPath() == tr("path-county").toUTF8())
297
	{
298
		result->bindWidget("contents", showCounty());
299
	}
300
	else if (this->internalPath() == tr("path-subcounty").toUTF8())
301
	{
302
		result->bindWidget("contents", showSubcounty());
303
	}
304
	else if (this->internalPath() == tr("path-town").toUTF8())
305
	{
306
		result->bindWidget("contents", showTown());
307
	}
308
	else if (this->internalPath() == tr("path-entreprenuer").toUTF8())
309
	{
310
		result->bindWidget("contents", showEntreprenuer());
311
	}
312
	else if (this->internalPath() == tr("path-enterprise").toUTF8())
313
	{
314
		result->bindWidget("contents", showEnterprise());
315
	}
316
	else if (this->internalPath() == tr("path-personnel").toUTF8())
317
	{
318
		result->bindWidget("contents", showPersonnel());
319
	}
320
	else if (this->internalPath() == tr("path-sku").toUTF8())
321
	{
322
		result->bindWidget("contents", showSku());
323
	}
324
	else if (this->internalPath() == tr("path-store").toUTF8())
325
	{
326
		result->bindWidget("contents", showStore());
327
	}
328
	else if (this->internalPath() == tr("path-yesno").toUTF8())
329
	{
330
		result->bindWidget("contents", showYesNo());
331
	}
332
	else if (this->internalPath() == tr("path-agenttype").toUTF8())
333
	{
334
		result->bindWidget("contents", showAgentType());
335
	}
336
	else if (this->internalPath() == tr("path-agentstatus").toUTF8())
337
	{
338
		result->bindWidget("contents", showAgentStatus());
339
	}
340
	else if (this->internalPath() == tr("path-assignmenttype").toUTF8())
341
	{
342
		result->bindWidget("contents", showAssignmentType());
343
	}
344
	else if (this->internalPath() == tr("path-agent").toUTF8())
345
	{
346
		result->bindWidget("contents", showAgent());
347
	}
348
	else if (this->internalPath() == tr("path-orderstatus").toUTF8())
349
	{
350
		result->bindWidget("contents", showOrderStatus());
351
	}
352
	else if (this->internalPath() == tr("path-orderitemstatus").toUTF8())
353
	{
354
		result->bindWidget("contents", showOrderItemStatus());
355
	}
356
	else if (this->internalPath() == tr("path-order").toUTF8())
357
	{
358
		result->bindWidget("contents", showOrder());
359
	}
360
	else if (this->internalPath() == tr("path-orderitem").toUTF8())
361
	{
362
		result->bindWidget("contents", showOrderItem());
363
	}
364
	else if (this->internalPath() == tr("path-agentassignmentstatus").toUTF8())
365
	{
366
		result->bindWidget("contents", showAgentAssignmentStatus());
367
	}
368
	else if (this->internalPath() == tr("path-agentassignment").toUTF8())
369
	{
370
		result->bindWidget("contents", showAgentAssignment());
371
	}
372
	else if (this->internalPath() == tr("path-agentassignmenttask").toUTF8())
373
	{
374
		result->bindWidget("contents", showAgentAssignmentTask());
375
	}
376
	else if (this->internalPath() == tr("path-wishlist").toUTF8())
377
	{
378
		result->bindWidget("contents", showWishlist());
379
	}
380
	else if (this->internalPath() == tr("path-cart").toUTF8())
381
	{
382
		result->bindWidget("contents", showCart());
383
	}
384
	else if (this->internalPath() == tr("path-message").toUTF8())
385
	{
386
		result->bindWidget("contents", showMessage());
387
	}
388
	else if (this->internalPath() == tr("path-sellerentreprenuer").toUTF8())
389
	{
390
		result->bindWidget("contents", showSellerEntreprenuer());
391
	}
392
	else if (this->internalPath() == tr("path-sellerenterprise").toUTF8())
393
	{
394
		result->bindWidget("contents", showSellerEnterprise());
395
	}
396
	else if (this->internalPath() == tr("path-sellerpersonnel").toUTF8())
397
	{
398
		result->bindWidget("contents", showSellerPersonnel());
399
	}
400
	else if (this->internalPath() == tr("path-selleragent").toUTF8())
401
	{
402
		result->bindWidget("contents", showSellerAgent());
403
	}
404
	else if (this->internalPath() == tr("path-sellerstore").toUTF8())
405
	{
406
		result->bindWidget("contents", showSellerStore());
407
	}
408
	else if (this->internalPath() == tr("path-home").toUTF8())
409
	{
410
		result->bindWidget("contents", showHomePage());
411
	}
412
	else if (this->internalPath() == tr("path-signin").toUTF8())
413
	{
414
		result->bindWidget("contents", createLogin());
415
	}
416
	else
417
	{
418
		result->bindWidget("contents", contents);
419
	}
420
	
421
	}
422
	catch (Wt::Dbo::Exception &e) {
423
		std::cerr << "Dbo exception: " << e.what() << std::endl;
424
	}
425
	catch (std::exception &e) {
426
		std::cerr << "exception: " << e.what() << std::endl;
427
	}
428

    
429
	doJavaScript("setTimeout(function() { loadScript('http://127.0.0.1:8082/chat.js?div=chat', null); }, 0); ");
430
}
431

    
432
void Home::setLanguage(int index)
433
{
434
	/*if (homePage_) {
435
		const Lang& l = languages[index];
436

    
437
		setLocale(l.code_);
438

    
439
		std::string langPath = l.path_;
440
		mainMenu_->setInternalBasePath(langPath);
441
		examplesMenu_->setInternalBasePath(langPath + "examples");
442
		BlogView *blog = dynamic_cast<BlogView *>(findWidget("blog"));
443
		if (blog)
444
			blog->setInternalBasePath(langPath + "blog/");
445
		updateTitle();
446

    
447
		language_ = index;
448
	}*/
449
}
450

    
451
void Home::setLanguageFromPath()
452
{
453
	/*std::string langPath = internalPathNextPart("/");
454

    
455
	if (langPath.empty())
456
		langPath = '/';
457
	else
458
		langPath = '/' + langPath + '/';
459

    
460
	int newLanguage = 0;
461

    
462
	for (unsigned i = 0; i < languages.size(); ++i) {
463
		if (languages[i].path_ == langPath) {
464
			newLanguage = i;
465
			break;
466
		}
467
	}
468

    
469
	if (newLanguage != language_)
470
		setLanguage(newLanguage);*/
471
}
472

    
473
void Home::chatSetUser(const WString& userName)
474
{
475
	WApplication::instance()->doJavaScript
476
	("if (window.chat && window.chat.emit) {"
477
		"""try {"
478
		""  "window.chat.emit(window.chat, 'login', "
479
		""                    "" + userName.jsStringLiteral() + "); "
480
		"""} catch (e) {"
481
		""  "window.chatUser=" + userName.jsStringLiteral() + ";"
482
		"""}"
483
		"} else "
484
		"""window.chatUser=" + userName.jsStringLiteral() + ";");
485
}
486

    
487
WString Home::tr(const char *key)
488
{
489
	return WString::tr(key);
490
}
491

    
492
WWidget *Home::status()
493
{
494
	return new WText("Status");
495
}
496

    
497
WWidget *Home::createLogin()
498
{
499
	AuthWidget *authWidget = new AuthWidget(session_);
500

    
501
	authWidget->model()->addPasswordAuth(&Session::passwordAuth());
502
	authWidget->model()->addOAuth(Session::oAuth());
503
	authWidget->setRegistrationEnabled(true);
504

    
505
	authWidget->processEnvironment();
506
	return authWidget;
507

    
508
}
509

    
510
WWidget *Home::createSellerds()
511
{
512
	SellerDsModelFormView *view = new SellerDsModelFormView(session_);
513

    
514
	return view;
515
	/*WTemplate *result = new WTemplate(tr("template.sellerds"));
516
	Wt::WPushButton *btnbuyerds = new Wt::WPushButton(Wt::WString::fromUTF8("<span>Switch to buyer dashboard</span> <span class = 'glyphicon glyphicon-share-alt'> </span>"), Wt::TextFormat::XHTMLUnsafeText);
517
	btnbuyerds->addStyleClass("btn btn-info productblock spacerpadding");
518
	result->bindWidget("btnbuyerds", btnbuyerds);
519

    
520
	btnbuyerds->setLink(Wt::WLink(Wt::WLink::InternalPath, "/buyerds"));
521
	return result;*/
522

    
523
}
524

    
525
WWidget *Home::createBuyerds()
526
{
527
	BuyerDsModelFormView *view = new BuyerDsModelFormView(session_);
528

    
529
	return view;
530
	/*WTemplate *result = new WTemplate(tr("Wt.Auth.template.logged-in"));
531
	Wt::WPushButton *btnsellerds = new Wt::WPushButton(Wt::WString::fromUTF8("<span>Switch to seller dashboard</span> <span class = 'glyphicon glyphicon-share-alt'> </span>"), Wt::TextFormat::XHTMLUnsafeText);
532
	btnsellerds->addStyleClass("btn btn-info productblock spacerpadding");
533
	result->bindWidget("btnsellerds", btnsellerds);
534

    
535
	btnsellerds->setLink(Wt::WLink(Wt::WLink::InternalPath, "/sellerds"));
536

    
537
	return result;*/
538

    
539
}
540

    
541
WWidget *Home::createAdminds()
542
{
543
	WTemplate *result = new WTemplate(tr("template.adminds"));
544
	Wt::WAnchor *lnkEducationLevel = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, tr("path-educationlevel").toUTF8()));
545
	lnkEducationLevel->setText("Education");
546
	result->bindWidget("lnkEducationLevel", lnkEducationLevel);
547

    
548
	Wt::WAnchor *lnkFamilySize = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, tr("path-familysize").toUTF8()));
549
	lnkFamilySize->setText("Family Size");
550
	result->bindWidget("lnkFamilySize", lnkFamilySize);
551

    
552
	Wt::WAnchor *lnkGender = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, tr("path-gender").toUTF8()));
553
	lnkGender->setText("Gender");
554
	result->bindWidget("lnkGender", lnkGender);
555

    
556
	Wt::WAnchor *lnkIncomeLevel = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, tr("path-incomelevel").toUTF8()));
557
	lnkIncomeLevel->setText("Income Level");
558
	result->bindWidget("lnkIncomeLevel", lnkIncomeLevel);
559

    
560
	Wt::WAnchor *lnkOccupation = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, tr("path-occupation").toUTF8()));
561
	lnkOccupation->setText("Occupation");
562
	result->bindWidget("lnkOccupation", lnkOccupation);
563

    
564
	Wt::WAnchor *lnkMaritalStatus = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, tr("path-maritalstatus").toUTF8()));
565
	lnkMaritalStatus->setText("Marital Status");
566
	result->bindWidget("lnkMaritalStatus", lnkMaritalStatus);
567

    
568
	Wt::WAnchor *lnkSeason = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, tr("path-season").toUTF8()));
569
	lnkSeason->setText("Season");
570
	result->bindWidget("lnkSeason", lnkSeason);
571

    
572
	Wt::WAnchor *lnkCountry = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, tr("path-country").toUTF8()));
573
	lnkCountry->setText("Country");
574
	result->bindWidget("lnkCountry", lnkCountry);
575

    
576
	Wt::WAnchor *lnkRegion = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, tr("path-region").toUTF8()));
577
	lnkRegion->setText("Region");
578
	result->bindWidget("lnkRegion", lnkRegion);
579

    
580
	Wt::WAnchor *lnkCounty = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, tr("path-county").toUTF8()));
581
	lnkCounty->setText("County");
582
	result->bindWidget("lnkCounty", lnkCounty);
583

    
584
	Wt::WAnchor *lnkSubcounty = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, tr("path-subcounty").toUTF8()));
585
	lnkSubcounty->setText("Subcounty");
586
	result->bindWidget("lnkSubcounty", lnkSubcounty);
587

    
588
	Wt::WAnchor *lnkTown = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, tr("path-town").toUTF8()));
589
	lnkTown->setText("Town");
590
	result->bindWidget("lnkTown", lnkTown);
591

    
592
	Wt::WAnchor *lnkEntreprenuer = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, tr("path-entreprenuer").toUTF8()));
593
	lnkEntreprenuer->setText("Entreprenuer");
594
	result->bindWidget("lnkEntreprenuer", lnkEntreprenuer);
595

    
596
	Wt::WAnchor *lnkEnterprise = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, tr("path-enterprise").toUTF8()));
597
	lnkEnterprise->setText("Enterprise");
598
	result->bindWidget("lnkEnterprise", lnkEnterprise);
599

    
600
	Wt::WAnchor *lnkPersonnel = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, tr("path-personnel").toUTF8()));
601
	lnkPersonnel->setText("Personnel");
602
	result->bindWidget("lnkPersonnel", lnkPersonnel);
603

    
604
	Wt::WAnchor *lnkStore = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, tr("path-store").toUTF8()));
605
	lnkStore->setText("Store");
606
	result->bindWidget("lnkStore", lnkStore);
607

    
608
	Wt::WAnchor *lnkSkuCategory = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, tr("path-skucategory").toUTF8()));
609
	lnkSkuCategory->setText("Category");
610
	result->bindWidget("lnkSkuCategory", lnkSkuCategory);
611

    
612
	Wt::WAnchor *lnkSkuBrand = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, tr("path-skubrand").toUTF8()));
613
	lnkSkuBrand->setText("Brand");
614
	result->bindWidget("lnkSkuBrand", lnkSkuBrand);
615

    
616
	Wt::WAnchor *lnkSkuPackage = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, tr("path-skupackage").toUTF8()));
617
	lnkSkuPackage->setText("Package");
618
	result->bindWidget("lnkSkuPackage", lnkSkuPackage);
619

    
620
	Wt::WAnchor *lnkSkuMake = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, tr("path-skumake").toUTF8()));
621
	lnkSkuMake->setText("Make");
622
	result->bindWidget("lnkSkuMake", lnkSkuMake);
623

    
624
	Wt::WAnchor *lnkSku = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, tr("path-sku").toUTF8()));
625
	lnkSku->setText("SKUs");
626
	result->bindWidget("lnkSku", lnkSku);
627

    
628
	Wt::WAnchor *lnkAgent = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, tr("path-agent").toUTF8()));
629
	lnkAgent->setText("Agent");
630
	result->bindWidget("lnkAgent", lnkAgent);
631

    
632
	Wt::WAnchor *lnkAgentAssignment = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, tr("path-agentassignment").toUTF8()));
633
	lnkAgentAssignment->setText("Agent Assignment");
634
	result->bindWidget("lnkAgentAssignment", lnkAgentAssignment);
635

    
636
	Wt::WAnchor *lnkAgentAssignmentTask = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, tr("path-agentassignmenttask").toUTF8()));
637
	lnkAgentAssignmentTask->setText("Agent Assignment Task");
638
	result->bindWidget("lnkAgentAssignmentTask", lnkAgentAssignmentTask);
639

    
640
	Wt::WAnchor *lnkWishlist = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, tr("path-wishlist").toUTF8()));
641
	lnkWishlist->setText("Wishlist");
642
	result->bindWidget("lnkWishlist", lnkWishlist);
643

    
644
	Wt::WAnchor *lnkCart = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, tr("path-cart").toUTF8()));
645
	lnkCart->setText("Cart");
646
	result->bindWidget("lnkCart", lnkCart);
647

    
648
	Wt::WAnchor *lnkOrder = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, tr("path-order").toUTF8()));
649
	lnkOrder->setText("Orders");
650
	result->bindWidget("lnkOrder", lnkOrder);
651

    
652
	Wt::WAnchor *lnkOrderItem = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, tr("path-orderitem").toUTF8()));
653
	lnkOrderItem->setText("Order Items");
654
	result->bindWidget("lnkOrderItem", lnkOrderItem);
655

    
656
	Wt::WAnchor *lnkMessage = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, tr("path-message").toUTF8()));
657
	lnkMessage->setText("Message");
658
	result->bindWidget("lnkMessage", lnkMessage);
659

    
660
	Wt::WAnchor *lnkYesNo = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, tr("path-yesno").toUTF8()));
661
	lnkYesNo->setText("Yes/No");
662
	result->bindWidget("lnkYesNo", lnkYesNo);
663

    
664
	Wt::WAnchor *lnkAgentType = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, tr("path-agenttype").toUTF8()));
665
	lnkAgentType->setText("Agent Type");
666
	result->bindWidget("lnkAgentType", lnkAgentType);
667

    
668
	Wt::WAnchor *lnkAgentStatus = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, tr("path-agentstatus").toUTF8()));
669
	lnkAgentStatus->setText("Agent Status");
670
	result->bindWidget("lnkAgentStatus", lnkAgentStatus);
671

    
672
	Wt::WAnchor *lnkAssignmentType = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, tr("path-assignmenttype").toUTF8()));
673
	lnkAssignmentType->setText("Assignment Type");
674
	result->bindWidget("lnkAssignmentType", lnkAssignmentType);
675

    
676
	Wt::WAnchor *lnkAgentAssignmentStatus = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, tr("path-agentassignmentstatus").toUTF8()));
677
	lnkAgentAssignmentStatus->setText("Agent Assignment Status");
678
	result->bindWidget("lnkAgentAssignmentStatus", lnkAgentAssignmentStatus);
679

    
680
	Wt::WAnchor *lnkOrderStatus = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, tr("path-orderstatus").toUTF8()));
681
	lnkOrderStatus->setText("Order Status");
682
	result->bindWidget("lnkOrderStatus", lnkOrderStatus);
683

    
684
	Wt::WAnchor *lnkOrderItemStatus = new Wt::WAnchor(Wt::WLink(Wt::WLink::InternalPath, tr("path-orderitemstatus").toUTF8()));
685
	lnkOrderItemStatus->setText("Order Item Status");
686
	result->bindWidget("lnkOrderItemStatus", lnkOrderItemStatus);
687

    
688
	return result;
689

    
690
}
691

    
692
WWidget *Home::showEducationLevel()
693
{
694
	EducationLevelModelFormView *view = new EducationLevelModelFormView(session_);
695

    
696
	return view;
697

    
698
}
699

    
700
WWidget *Home::showFamilySize()
701
{
702
	FamilySizeModelFormView *view = new FamilySizeModelFormView(session_);
703

    
704
	return view;
705

    
706
}
707

    
708
WWidget *Home::showGender()
709
{
710
	GenderModelFormView *view = new GenderModelFormView(session_);
711

    
712
	return view;
713

    
714
}
715

    
716
WWidget *Home::showIncomeLevel()
717
{
718
	IncomeLevelModelFormView *view = new IncomeLevelModelFormView(session_);
719

    
720
	return view;
721

    
722
}
723

    
724
WWidget *Home::showOccupation()
725
{
726
	OccupationModelFormView *view = new OccupationModelFormView(session_);
727

    
728
	return view;
729

    
730
}
731

    
732
WWidget *Home::showMaritalStatus()
733
{
734
	MaritalStatusModelFormView *view = new MaritalStatusModelFormView(session_);
735

    
736
	return view;
737

    
738
}
739

    
740
WWidget *Home::showCountry()
741
{
742
	CountryModelFormView *view = new CountryModelFormView(session_);
743

    
744
	return view;
745

    
746
}
747

    
748
WWidget *Home::showSkuCategory()
749
{
750
	SkuCategoryModelFormView *view = new SkuCategoryModelFormView(session_);
751

    
752
	return view;
753

    
754
}
755

    
756
WWidget *Home::showSkuBrand()
757
{
758
	SkuBrandModelFormView *view = new SkuBrandModelFormView(session_);
759

    
760
	return view;
761

    
762
}
763

    
764
WWidget *Home::showSkuPackage()
765
{
766
	SkuPackageModelFormView *view = new SkuPackageModelFormView(session_);
767

    
768
	return view;
769

    
770
}
771

    
772
WWidget *Home::showSkuMake()
773
{
774
	SkuMakeModelFormView *view = new SkuMakeModelFormView(session_);
775

    
776
	return view;
777

    
778
}
779

    
780
WWidget *Home::showSeason()
781
{
782
	SeasonModelFormView *view = new SeasonModelFormView(session_);
783

    
784
	return view;
785

    
786
}
787

    
788
WWidget *Home::showRegion()
789
{
790
	RegionModelFormView *view = new RegionModelFormView(session_);
791

    
792
	return view;
793

    
794
}
795

    
796
WWidget *Home::showCounty()
797
{
798
	CountyModelFormView *view = new CountyModelFormView(session_);
799

    
800
	return view;
801

    
802
}
803

    
804
WWidget *Home::showSubcounty()
805
{
806
	SubcountyModelFormView *view = new SubcountyModelFormView(session_);
807

    
808
	return view;
809

    
810
}
811

    
812
WWidget *Home::showTown()
813
{
814
	TownModelFormView *view = new TownModelFormView(session_);
815

    
816
	return view;
817

    
818
}
819

    
820
WWidget *Home::showEntreprenuer()
821
{
822
	EntreprenuerModelFormView *view = new EntreprenuerModelFormView(session_);
823

    
824
	return view;
825

    
826
}
827

    
828
WWidget *Home::showEnterprise()
829
{
830
	EnterpriseModelFormView *view = new EnterpriseModelFormView(session_);
831

    
832
	return view;
833
}
834

    
835
WWidget *Home::showPersonnel()
836
{
837
	PersonnelModelFormView *view = new PersonnelModelFormView(session_);
838

    
839
	return view;
840
}
841

    
842
WWidget *Home::showSku()
843
{
844
	SkuModelFormView *view = new SkuModelFormView(session_);
845

    
846
	return view;
847
}
848

    
849
WWidget *Home::showStore()
850
{
851
	StoreModelFormView *view = new StoreModelFormView(session_);
852

    
853
	return view;
854
}
855

    
856
WWidget *Home::showYesNo()
857
{
858
	YesNoModelFormView *view = new YesNoModelFormView(session_);
859

    
860
	return view;
861
}
862

    
863
WWidget *Home::showAgentType()
864
{
865
	AgentTypeModelFormView *view = new AgentTypeModelFormView(session_);
866

    
867
	return view;
868
}
869

    
870
WWidget *Home::showAssignmentType()
871
{
872
	AssignmentTypeModelFormView *view = new AssignmentTypeModelFormView(session_);
873

    
874
	return view;
875
}
876

    
877
WWidget * Home::showAgent()
878
{
879
	AgentModelFormView *view = new AgentModelFormView(session_);
880

    
881
	return view;
882
}
883

    
884
WWidget * Home::showAgentAssignment()
885
{
886
	AgentAssignmentModelFormView *view = new AgentAssignmentModelFormView(session_);
887

    
888
	return view;
889
}
890

    
891
WWidget * Home::showAgentAssignmentTask()
892
{
893
	AgentAssignmentTaskModelFormView *view = new AgentAssignmentTaskModelFormView(session_);
894

    
895
	return view;
896
}
897

    
898
WWidget *Home::showWishlist()
899
{
900
	WishlistModelFormView *view = new WishlistModelFormView(session_);
901

    
902
	return view;
903
}
904

    
905
WWidget *Home::showCart()
906
{
907
	CartModelFormView *view = new CartModelFormView(session_);
908

    
909
	return view;
910
}
911

    
912
WWidget *Home::showAgentStatus()
913
{
914
	AgentStatusModelFormView *view = new AgentStatusModelFormView(session_);
915

    
916
	return view;
917
}
918

    
919
WWidget *Home::showOrderStatus()
920
{
921
	OrderStatusModelFormView *view = new OrderStatusModelFormView(session_);
922

    
923
	return view;
924
}
925

    
926
WWidget *Home::showOrderItemStatus()
927
{
928
	OrderItemStatusModelFormView *view = new OrderItemStatusModelFormView(session_);
929

    
930
	return view;
931
}
932

    
933
WWidget *Home::showOrder()
934
{
935
	OrderModelFormView *view = new OrderModelFormView(session_);
936

    
937
	return view;
938
}
939

    
940
WWidget *Home::showOrderItem()
941
{
942
	OrderItemModelFormView *view = new OrderItemModelFormView(session_);
943

    
944
	return view;
945
}
946

    
947
WWidget *Home::showMessage()
948
{
949
	MessageModelFormView *view = new MessageModelFormView(session_);
950

    
951
	return view;
952
}
953
WWidget *Home::showAgentAssignmentStatus()
954
{
955
	AgentAssignmentStatusModelFormView *view = new AgentAssignmentStatusModelFormView(session_);
956

    
957
	return view;
958
}
959

    
960
WWidget *Home::showSellerEntreprenuer()
961
{
962
	SellerEntreprenuerModelFormView *view = new SellerEntreprenuerModelFormView(session_);
963

    
964
	return view;
965
}
966

    
967
WWidget *Home::showSellerEnterprise()
968
{
969
	SellerEnterpriseModelFormView *view = new SellerEnterpriseModelFormView(session_);
970

    
971
	return view;
972
}
973

    
974
WWidget *Home::showSellerPersonnel()
975
{
976
	SellerPersonnelModelFormView *view = new SellerPersonnelModelFormView(session_);
977

    
978
	return view;
979
}
980

    
981
WWidget *Home::showSellerAgent()
982
{
983
	SellerAgentModelFormView *view = new SellerAgentModelFormView(session_);
984

    
985
	return view;
986
}
987

    
988
WWidget *Home::showSellerStore()
989
{
990
	SellerStoreModelFormView *view = new SellerStoreModelFormView(session_);
991

    
992
	return view;
993
}
994

    
995
WWidget *Home::showHomePage()
996
{
997
	HomePageModelFormView *view = new HomePageModelFormView(session_);
998

    
999
	return view;
1000
}
1001

    
1002
//WWidget *Home::createLogout()
1003
//{
1004
//	if (session_.login().loggedIn() && item->text() == tr("path-signout").toUTF8())
1005
//	{
1006
//		session_.login().logout();
1007
//	}
1008
//
1009
//}
1010

    
1011
void Home::AuthEvent()
1012
{
1013

    
1014
	if (session_.login().loggedIn())
1015
	{
1016
		const Wt::Auth::User& u = session_.login().user();
1017
		std::cerr << "User " << u.id() << std::endl;
1018
		std::cerr << " (" << u.identity(Wt::Auth::Identity::LoginName) << ")" << std::endl;
1019
		std::cerr << " logged in." << std::endl;
1020
	}
1021
	else
1022
	{
1023
		std::cerr << "User logged out.";
1024
	}
1025

    
1026
	AuthAction();
1027
}
1028

    
1029
void Home::AuthAction()
1030
{
1031
	if (session_.login().loggedIn())
1032
	{
1033
		const Wt::Auth::User& u = session_.login().user();
1034
		usermenu_->setText(u.identity(Wt::Auth::Identity::LoginName));
1035
		signin_->hide();
1036
		profile_->show();
1037
		buyerds_->show();
1038
		sellerds_->show();
1039
		signout_->show();
1040
		register_->hide();
1041
		usermenu_->setText(tr("hello-user") + u.identity(Wt::Auth::Identity::LoginName));
1042
	}
1043
	else
1044
	{
1045
		usermenu_->setText(tr("hello-guest"));
1046
		signin_->show();
1047
		profile_->hide();
1048
		buyerds_->hide();
1049
		sellerds_->hide();
1050
		signout_->hide();
1051
		register_->show();
1052
		usermenu_->setText(tr("hello-guest"));
1053
	}
1054
}
1055

    
1056
void Home::SignedOut()
1057
{	
1058
	if (session_.login().loggedIn())
1059
	{
1060
		session_.login().logout();
1061
	}
1062

    
1063
	setup();
1064
	//AuthAction();
1065
}
    (1-1/1)