-
Notifications
You must be signed in to change notification settings - Fork 6
/
article_article.js
128 lines (108 loc) · 2.88 KB
/
article_article.js
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
/**
* Controller for the article node screen
*
* @class Controllers.article.article
* @uses Models.article
* @uses core
* @uses social
* @uses Widgets.com.mcongrove.detailNavigation
*/
var APP = require("core");
var SOCIAL = require("social");
var DATE = require("alloy/moment");
var STRING = require("alloy/string");
var MODEL = require("models/article")();
var CONFIG = arguments[0] || {};
var ACTION = {};
/**
* Initializes the controller
*/
$.init = function() {
APP.log("debug", "article_article.init | " + JSON.stringify(CONFIG));
MODEL.init(CONFIG.index);
$.handleData(MODEL.getArticle(CONFIG.id));
};
/**
* Handles the data return
* @param {Object} _data The returned data
*/
$.handleData = function(_data) {
APP.log("debug", _data, "article_article.handleData", true);
$.handleNavigation();
var time = DATE(parseInt(_data.date, 10));
time = time.isBefore() ? time : DATE();
$.heading.text = _data.title;
$.heading.color = APP.Settings.colors.hsb.primary.b > 70 ? "#000" : APP.Settings.colors.primary;
$.text.value = _data.description;
$.date.text = STRING.ucfirst(time.fromNow());
if(_data.image) {
var image = Ti.UI.createImageView({
image: _data.image,
width: APP.Device.width + "dp",
height: Ti.UI.SIZE,
preventDefaultImage: true
});
$.image.add(image);
} else {
$.container.remove($.image);
}
ACTION.url = _data.link;
$.NavigationBar.setBackgroundColor(APP.Settings.colors.primary);
if(APP.Device.isHandheld) {
$.NavigationBar.showBack(function(_event) {
APP.removeAllChildren({
animation: APP.AnimationStyle.NavRight
});
});
}
$.NavigationBar.showAction(function(_event) {
SOCIAL.share(ACTION.url, $.NavigationBar.right);
});
};
/**
* Handles detail navigation
*/
$.handleNavigation = function() {
ACTION.next = MODEL.getNextArticle(CONFIG.id);
ACTION.previous = MODEL.getPreviousArticle(CONFIG.id);
var navigation = Alloy.createWidget("com.mcongrove.detailNavigation", null, {
color: APP.Settings.colors.theme == "dark" ? "white" : "black",
down: function(_event) {
APP.log("debug", "article_article @next");
// APP.addChild("article_article", {
// id: ACTION.next.id,
// index: CONFIG.index
// }, false, true);
APP.addChild({
controller: "article_article",
params: {
id: ACTION.next.id,
index: CONFIG.index
},
model: false,
sibling: true,
animation: APP.AnimationStyle.Fade
});
},
up: function(_event) {
APP.log("debug", "article_article @previous");
// APP.addChild("article_article", {
// id: ACTION.previous.id,
// index: CONFIG.index
// }, false, true);
APP.addChild({
controller: "article_article",
params: {
id: ACTION.next.id,
index: CONFIG.index
},
model: false,
sibling: true,
animation: APP.AnimationStyle.Fade
});
}
}).getView();
$.NavigationBar.addNavigation(navigation);
};
// Kick off the init
$.init();