Skip to content

Commit f26d0af

Browse files
author
VGGeorgiev
committed
Updated Bookmarks exam preparation
1 parent 12a320a commit f26d0af

File tree

6 files changed

+89
-23
lines changed

6 files changed

+89
-23
lines changed

7. ExamPreparation-Bookmarks/Vlado/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
<script src="scripts/ajax-requester.js"></script>
2323
<script src="scripts/data-persister.js"></script>
24-
<script src="scripts/ui-controls.js"></script>
2524
<script src="scripts/controller.js"></script>
2625
<script src="scripts/app.js"></script>
2726
</body>

7. ExamPreparation-Bookmarks/Vlado/scripts/app.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,40 @@
33
var ajaxRequester = app.ajaxRequester.get();
44
var dataPersister = app.dataPersister.get(rootUrl, ajaxRequester);
55
var controller = app.controller.get(dataPersister);
6-
6+
controller.attachEventHandlers();
7+
78
app.routes = Sammy(function () {
89
var selector = '#wrapper';
910
this.get('#/', function () {
10-
controller.loadHome(selector);
11+
// controller.loadHome(selector);
12+
$.get('templates/home.html', function (template) {
13+
$(selector).html(template);
14+
});
1115
});
1216

1317
this.get('#/login', function () {
14-
controller.loadLogin(selector);
18+
//controller.loadLogin(selector);
19+
$.get('templates/login.html', function (template) {
20+
$(selector).html(template);
21+
});
1522
});
1623

1724
this.get('#/register', function () {
18-
controller.loadRegister(selector);
25+
//controller.loadRegister(selector);
26+
$.get('templates/register.html', function (template) {
27+
$(selector).html(template);
28+
});
1929
});
2030

2131
this.get('#/bookmarks', function () {
22-
controller.loadBookmarks(selector);
32+
//controller.loadBookmarks(selector);
33+
dataPersister.bookmarks.getAll()
34+
.then(function (data) {
35+
$.get('templates/bookmarks.html', function (template) {
36+
var output = Mustache.render(template, data);
37+
$(selector).html(output);
38+
})
39+
});
2340
});
2441
});
2542

7. ExamPreparation-Bookmarks/Vlado/scripts/controller.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,35 @@ app.controller = (function () {
3535
});
3636
}
3737

38+
Controller.prototype.attachEventHandlers = function () {
39+
attachLoginHandler.call(this);
40+
attachRegisterHandler.call(this);
41+
}
42+
43+
function attachLoginHandler() {
44+
var _this = this;
45+
$('#wrapper').on('click', '#login-btn', function (e) {
46+
var username = $('#username').val();
47+
password = $('#password').val();
48+
_this._dataPersister.users.login(username, password)
49+
.then(function (data) {
50+
console.log(data);
51+
});
52+
});
53+
}
54+
55+
function attachRegisterHandler() {
56+
var _this = this;
57+
$('#wrapper').on('click', '#register-btn', function (e) {
58+
var username = $('#username').val();
59+
password = $('#password').val();
60+
_this._dataPersister.users.register(username, password)
61+
.then(function (data) {
62+
console.log(data);
63+
});
64+
});
65+
}
66+
3867
return {
3968
get: function (dataPersister) {
4069
return new Controller(dataPersister);
Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,52 @@
11
var app = app || {};
22

33
app.UI = (function () {
4-
function UI() {
5-
this.loginControl = new LoginControl();
6-
//this.registerControl = new RegisterControl();
7-
//this.studentsControl = new StudentsControl();
8-
//this.schoolsControl = new SchoolsControl();
9-
}
4+
var loginControl = (function () {
5+
function getUsernameText () {
6+
// return $("#login-username-input").val();
7+
}
8+
9+
function getPasswordText () {
10+
// return $("#login-password-input").val();
11+
}
1012

11-
var LoginControl = (function () {
12-
function LoginControl() {
13-
}
13+
function attachLoginButtonHandler(selector) {
14+
$(selector).on('click', function (e) {
15+
16+
});
17+
}
1418

15-
LoginControl.prototype.getUsernameText = function () {
19+
return {
20+
getUsername: getUsernameText,
21+
getPassword: getPasswordText,
22+
attachButtonHandler: attachLoginButtonHandler
23+
};
24+
}());
25+
26+
var registerControl = (function () {
27+
function getUsernameText () {
1628
// return $("#login-username-input").val();
1729
}
1830

19-
LoginControl.prototype.getPasswordText = function () {
31+
function getPasswordText () {
2032
// return $("#login-password-input").val();
2133
}
2234

23-
return LoginControl;
35+
function attachRegisterHandlers(selector) {
36+
$(selector).on('click', function (e) {
37+
38+
});
39+
}
40+
41+
return {
42+
getUsername: getUsernameText,
43+
getPassword: getPasswordText,
44+
attachButtonHandler: attachRegisterButtonHandler
45+
};
2446
}());
25-
2647

2748
return {
28-
loginControl: LoginControl,
29-
//registerControl: RegisterControl,
49+
loginControl: loginControl,
50+
registerControl: registerControl,
3051
}
3152
}());

7. ExamPreparation-Bookmarks/Vlado/templates/login.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div>
1+
<div id="login-form">
22
<label for="username">Username:</label>
33
<input id="username" type="text" />
44
<br />

7. ExamPreparation-Bookmarks/Vlado/templates/register.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div>
1+
<div id="register-form">
22
<label for="username">Username:</label>
33
<input id="username" type="text" />
44
<br />

0 commit comments

Comments
 (0)