Skip to content

Commit d5882a6

Browse files
committed
UI components are initialized using the corresponding jQuery element
1 parent 42f04b5 commit d5882a6

File tree

6 files changed

+44
-36
lines changed

6 files changed

+44
-36
lines changed

bin/puremvc-typescript-employeeadmin-1.0-min.js

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/puremvc-typescript-employeeadmin-1.0.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ if( typeof define === "function" )
510510
"use strict";
511511
var UserList = (function (_super) {
512512
__extends(UserList, _super);
513-
function UserList(selector) {
513+
function UserList(view) {
514514
_super.call(this);
515515
this.userListPanel = null;
516516
this.userList = null;
@@ -519,7 +519,7 @@ if( typeof define === "function" )
519519
this.selectedUser = null;
520520
this.userTotal = null;
521521
this.users = null;
522-
this.userListPanel = jQuery(selector);
522+
this.userListPanel = view;
523523
this.initializeChildren();
524524
this.bindListeners();
525525
}
@@ -738,7 +738,7 @@ if( typeof define === "function" )
738738
"use strict";
739739
var UserForm = (function (_super) {
740740
__extends(UserForm, _super);
741-
function UserForm(selector) {
741+
function UserForm(view) {
742742
_super.call(this);
743743
this.userFormPanel = null;
744744
this.uname = null;
@@ -754,7 +754,7 @@ if( typeof define === "function" )
754754
this.user = null;
755755
this.userRoles = null;
756756
this.mode = null;
757-
this.userFormPanel = jQuery(selector);
757+
this.userFormPanel = view;
758758
this.initializeChildren();
759759
this.bindListeners();
760760
this.clearForm();
@@ -945,7 +945,7 @@ if( typeof define === "function" )
945945
} else {
946946
this.setFieldError("department", false);
947947
}
948-
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
948+
var emailReg = /^[a-z0-9!#$%&'*+\/=?^_`\{|\}~\.-]+@[a-z0-9-]+(\.[a-z0-9-]+)*$/;
949949
if(this.email.val() != "" && !emailReg.test(this.email.val())) {
950950
this.setFieldError("email", error = true);
951951
} else {
@@ -1081,7 +1081,7 @@ if( typeof define === "function" )
10811081
"use strict";
10821082
var RolePanel = (function (_super) {
10831083
__extends(RolePanel, _super);
1084-
function RolePanel(selector) {
1084+
function RolePanel(view) {
10851085
_super.call(this);
10861086
this.user = null;
10871087
this.userRoles = null;
@@ -1093,7 +1093,7 @@ if( typeof define === "function" )
10931093
this.addRoleButton = null;
10941094
this.removeRoleButton = null;
10951095
this.selectedFullname = null;
1096-
this.rolePanel = jQuery(selector);
1096+
this.rolePanel = view;
10971097
this.initializeChildren();
10981098
this.bindListeners();
10991099
this.fillRoleList();
@@ -1378,9 +1378,10 @@ if( typeof define === "function" )
13781378

13791379
}
13801380
PrepViewCommand.prototype.execute = function (note) {
1381-
var userForm = new EmployeeAdmin.UserForm(".user-form-panel");
1382-
var userList = new EmployeeAdmin.UserList(".user-list-panel");
1383-
var rolePanel = new EmployeeAdmin.RolePanel(".role-panel");
1381+
var mainView = note.getBody();
1382+
var userForm = new EmployeeAdmin.UserForm(mainView.find(".user-form-panel"));
1383+
var userList = new EmployeeAdmin.UserList(mainView.find(".user-list-panel"));
1384+
var rolePanel = new EmployeeAdmin.RolePanel(mainView.find(".role-panel"));
13841385
var userListMediator = new EmployeeAdmin.UserListMediator(EmployeeAdmin.MediatorNames.USER_LIST_MEDIATOR, userList);
13851386
var userFormMediator = new EmployeeAdmin.UserFormMediator(EmployeeAdmin.MediatorNames.USER_FORM_MEDIATOR, userForm);
13861387
var rolePanelMediator = new EmployeeAdmin.RolePanelMediator(EmployeeAdmin.MediatorNames.ROLE_PANEL_MEDIATOR, rolePanel);

src/controller/PrepViewCommand.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
///<reference path='../../lib/puremvc/puremvc-typescript-standard-1.0.d.ts'/>
2+
///<reference path='../../lib/jquery/jquery-1.7.x-jqueryui-1.8.x.d.ts'/>
23

34
///<reference path='../abc/MediatorNames.ts'/>
45

@@ -25,12 +26,14 @@ module EmployeeAdmin
2526
*/
2627
execute( note:puremvc.INotification )
2728
{
29+
var mainView:JQuery = note.getBody();
30+
2831
/*
29-
* View Components initialization
32+
* View Components are initialized using the application main view selector
3033
*/
31-
var userForm:UserForm = new UserForm(".user-form-panel");
32-
var userList:UserList = new UserList(".user-list-panel");
33-
var rolePanel:RolePanel = new RolePanel(".role-panel");
34+
var userForm:UserForm = new UserForm( mainView.find(".user-form-panel") );
35+
var userList:UserList = new UserList( mainView.find(".user-list-panel") );
36+
var rolePanel:RolePanel = new RolePanel( mainView.find(".role-panel") );
3437

3538
/*
3639
* Mediators initialization

src/view/components/RolePanel.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ module EmployeeAdmin
6969
/**
7070
* Constructs a <code>RolePanel</code> instance.
7171
*
72-
* @param selector
73-
* The jQuery selector giving access to the UI component instance in the page.
72+
* @param view
73+
* The jQuery element giving access to the corresponding UI HTML element in the page.
7474
*/
75-
constructor( selector:string )
75+
constructor( view:JQuery )
7676
{
7777
super();
7878

79-
this.rolePanel = jQuery(selector);
79+
this.rolePanel = view;
8080

8181
this.initializeChildren();
8282
this.bindListeners();

src/view/components/UserForm.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ module EmployeeAdmin
9090
/**
9191
* Constructs a <code>UserForm</code> instance.
9292
*
93-
* @param selector
94-
* The jQuery selector giving access to the UI component instance in the page.
93+
* @param view
94+
* The jQuery element giving access to the corresponding UI HTML element in the page.
9595
*/
96-
constructor( selector:string )
96+
constructor( view:JQuery )
9797
{
9898
super();
9999

100-
this.userFormPanel = jQuery(selector);
100+
this.userFormPanel = view;
101101

102102
this.initializeChildren();
103103
this.bindListeners();
@@ -406,7 +406,11 @@ module EmployeeAdmin
406406
else
407407
this.setFieldError( "department", false );
408408

409-
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
409+
/**
410+
* The e-mail verification rule is the one used by HTML5 e-mail inputs.
411+
* @see http://stackoverflow.com/questions/7786058/find-the-regex-used-by-html5-forms-for-validation
412+
*/
413+
var emailReg:RegExp = /^[a-z0-9!#$%&'*+\/=?^_`\{|\}~\.-]+@[a-z0-9-]+(\.[a-z0-9-]+)*$/;
410414
if( this.email.val() != "" && !emailReg.test(this.email.val()) )
411415
this.setFieldError( "email", error = true );
412416
else

src/view/components/UserList.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ module EmployeeAdmin
5353
/**
5454
* Constructs a <code>UserList</code> instance.
5555
*
56-
* @param selector
57-
* The jQuery selector giving access to the UI component instance in the page.
56+
* @param view
57+
* The jQuery element giving access to the corresponding UI HTML element in the page.
5858
*/
59-
constructor( selector:string )
59+
constructor( view:JQuery )
6060
{
6161
super();
6262

63-
this.userListPanel = jQuery(selector);
63+
this.userListPanel = view;
6464

6565
this.initializeChildren();
6666
this.bindListeners();

0 commit comments

Comments
 (0)