-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathmaster.js
More file actions
98 lines (79 loc) · 2.48 KB
/
master.js
File metadata and controls
98 lines (79 loc) · 2.48 KB
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
// require the built-in MomentJS library
var moment = require('alloy/moment');
/**
* self-executing function to organize otherwise inline constructor code
* @param {Object} args arguments passed to the controller
*/
(function constructor(args) {
// use strict mode for this function scope
'use strict';
if (OS_WINDOWS) {
$.refreshButton = Ti.UI.Windows.createAppBarButton({ icon: Ti.UI.Windows.SystemIcon.REFRESH });
$.refreshButton.addEventListener('click', function(e) {
refresh();
});
$.commandBar.items = [
$.refreshButton
];
}
// use the refresh callback for the initial load
refresh();
// execute constructor with optional arguments passed to controller
})(arguments[0] || {});
/**
* event listener added via view for the refreshControl (iOS) or button (Android)
* @param {Object} e Event, unless it was called from the constructor
*/
function refresh(e) {
'use strict';
// if we were called from the constructor programmatically show the refresh animation
if (OS_IOS && !e) {
$.refreshControl.beginRefreshing();
}
/**
* callback for fetch, both success and error
* @param {Object} e Event
*/
function afterFetch(col, res) {
// for iOS end the refreshing animation
if (OS_IOS) {
$.refreshControl.endRefreshing();
}
}
// MobileWeb can't load the remote file because we don't have access control set-up
var url = OS_MOBILEWEB ? Ti.Filesystem.resourcesDirectory + 'feed.xml' : Alloy.CFG.url;
// let the collection fetch data from it's data source
Alloy.Collections.feed.fetch({
url: url,
success: afterFetch,
error: afterFetch
});
}
/**
* set via view to be applied on each model before it renders
* @param {Object} model BackBone model
* @return {Object} Transformed properties
*/
function transform(model) {
'use strict';
var transformed = model.toJSON();
// return a formatted version of pubDate
transformed.pubDate = moment(model.get('pubDate'), 'DD MMM YYYY HH:mm:ss ZZ').format('LLL');
return transformed;
}
/**
* event listener set via view for when the user selects a ListView item
* @param {Object} e Event
*/
function select(e) {
'use strict';
// we've stored the guid in the special itemId property of the item
var guid = OS_MOBILEWEB ? e.row.itemId : e.itemId;
// lookup the model
var model = Alloy.Collections.feed.get(guid);
// trigger the select event on this controller, passing the model with it
// the index controller has an event listener for this event
$.trigger('select', {
model: model
});
}