-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexample2.html
162 lines (137 loc) · 5.72 KB
/
example2.html
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<!DOCTYPE html>
<html><head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>openui5-cards reddit</title>
<!--Standard sapui5 init-->
<script id="sap-ui-bootstrap"
src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js"
data-sap-ui-theme="sap_bluecrystal"
data-sap-ui-libs="sap.m,sap.ui.commons"></script>
<!--CSS required by open.m.Card
Needs to be after sapui5 init in order to override styles-->
<link href="openui5-cards.css" type="text/css" rel="stylesheet"/>
<script src="openui5-cards.js"></script>
<style>
/*overwriting title size to smaller value*/
h1.cardTitle1 {
font-size:1.5rem;
}
.sapMNav{
overflow:auto;
z-index:0;
}
.sapMPageScroll{
overflow:auto;
z-index:0;
}
</style>
<script>
var redditJsonUrl="http://www.reddit.com/.json";
var oModel = new sap.ui.model.json.JSONModel(redditJsonUrl);
var cardFactory = function(sId, oContext) {
var oCard = new open.m.Card(sId)
.bindProperty("title", oContext.sPath+"/data/title")
.bindProperty("subtitle", oContext.sPath+"/data/subreddit")
/*.bindProperty("image", oContext.sPath+"/data/thumbnail",function(aImage){
//only accept values starting with http
if(aImage!=null && aImage.toLowerCase().substring(0,4) === "http"){
return aImage;
}else {
return null;
}
}
);*/
var imageUrl = oContext.getModel().getProperty(oContext.sPath+"/data/thumbnail");
if(imageUrl!=null && imageUrl.toLowerCase().substring(0,4) != "http"){
imageUrl=null;
}
var bodyContent = new sap.m.HBox({
width:"100%",
items:[
new sap.m.Image({src:imageUrl, height:"140px"}).addStyleClass("cardImage"),
new sap.m.VBox({
width:"100%",
alignItems: sap.m.FlexAlignItems.End,
items:[
new sap.m.Text({text:"Upvotes:" + oContext.getModel().getProperty(oContext.sPath+"/data/ups")}).addStyleClass("cardTitle2"),
new sap.m.Text({text:"Downvotes:" + oContext.getModel().getProperty(oContext.sPath+"/data/downs")}).addStyleClass("cardTitle2"),
new sap.m.Text({text:"Comments:" + oContext.getModel().getProperty(oContext.sPath+"/data/num_comments")}).addStyleClass("cardTitle2"),
new sap.m.Text({text:"By:" + oContext.getModel().getProperty(oContext.sPath+"/data/author")}).addStyleClass("cardTitle2"),
]
})
]
}
);
oCard.setBodyGeneric(bodyContent);
oCard.setShowDividerAfterContent(false);
var redditCommentLink = "http://www.reddit.com"+ oContext.getModel().getProperty(oContext.sPath+"/data/permalink");
var redditViewLink = oContext.getModel().getProperty(oContext.sPath+"/data/url");
//Add a CardAction for viewing the post if it's different than the comment link
//TODO: Make the title clickable instead?
if(!(redditViewLink === redditCommentLink)){
oCard.addAction(new open.m.CardAction(sId+"action2",
{actionText:"View post",
press:function(){
jQuery.sap.require("sap.m.MessageToast");
sap.m.MessageToast.show("View link action clicked");
window.location.href = redditViewLink;
},
icon:"sap-icon://post"}));
}
//Add a CardAction in order to view comments
var redditCommentLink = "http://reddit.com"+ oContext.getModel().getProperty(oContext.sPath+"/data/permalink");
oCard.addAction(new open.m.CardAction(sId+"action1",
{actionText:"View comments",
press:function(){
jQuery.sap.require("sap.m.MessageToast");
sap.m.MessageToast.show("View comments action clicked");
window.location.href = redditCommentLink;
},
icon:"sap-icon://comment"}));
//add menu
oCard.setMenu(new sap.m.ActionSheet(sId+"menu1",{
title: "Options",
showCancelButton: false,
placement: sap.m.PlacementType.Bottom,
buttons: [
new sap.m.Button({
icon: "sap-icon://arrow-top",
text: "Upvote",
press: function(){
jQuery.sap.require("sap.m.MessageToast");
sap.m.MessageToast.show("Not implemented (ie. Left as an exercise for the user)");
}
}),
new sap.m.Button({
icon: "sap-icon://arrow-bottom",
text: "Downvote",
press: function(){
jQuery.sap.require("sap.m.MessageToast");
sap.m.MessageToast.show("Not implemented (ie. Left as an exercise for the user)");
}
}),
]
}));
return oCard;
};
var headerCard = new open.m.Card("initialCard",
{title:"<strong>About</strong>",
subtitle:"Demonstrates binding to a dynamic JSONModel (from Reddit)",})
var cardContainer = new open.m.CardContainer("myCardContainer",
{ showSearchField:false,
headerCard:headerCard,
headerImageUrl:"openui5-cards-header-dawn.png"
});
cardContainer.setModel(oModel);
cardContainer.bindAggregation("cards","/data/children", cardFactory);
var app = new sap.m.App({initialPage:"openui5-cards"});
app.placeAt("content");
var pageContent = new sap.m.Page("openui5-cards",{title:"Reddit OpenUI5-Cards", showHeader:false, showFooter:false, enableScrolling:false});
pageContent.addContent(cardContainer);
app.addPage(pageContent);
</script>
</head>
<body class="sapUiBody">
<div id="content"></div>
</body>
</html>