Skip to content

Commit

Permalink
mockserver init
Browse files Browse the repository at this point in the history
Change-Id: I92c13e0f150baf7cca5a0b8e1b42f9744da92b91
  • Loading branch information
pmarcely committed Aug 26, 2014
1 parent 14d5e10 commit c328c3d
Show file tree
Hide file tree
Showing 3 changed files with 293 additions and 0 deletions.
234 changes: 234 additions & 0 deletions mockserver.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv='Content-Type' content='text/html;charset=UTF-8'/>
<script src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js"
id="sap-ui-bootstrap"
data-sap-ui-libs="sap.ui.commons, sap.ui.table"
data-sap-ui-theme="sap_bluecrystal"
data-sap-ui-xx-bindingSyntax="complex">
</script>
<!-- only load the mobile lib "sap.m" and the "sap_bluecrystal" theme -->

<script>

jQuery.sap.require("sap.ui.core.util.MockServer");
//create the ApplicationHeader control
var oAppHeader = new sap.ui.commons.ApplicationHeader("appHeader");
oAppHeader.setLogoSrc("http://sap.github.io/openui5/images/icotxt_white_220x72_blue_open.png");
oAppHeader.setDisplayWelcome(false);
oAppHeader.setDisplayLogoff(false);
oAppHeader.placeAt("content");

// Create mockserver
var oMockServer = new sap.ui.core.util.MockServer({
rootUri: "http://mymockserver/",
});
oMockServer.simulate("model/metadata.xml", "model/");
oMockServer.start();

// setting up model
var oModel = new sap.ui.model.odata.ODataModel("http://mymockserver/", true);
//oModel.setCountSupported(false);
sap.ui.getCore().setModel(oModel);


/***** CREATE Operation *****/
function openCreateDialog(){
var oCreateDialog = new sap.ui.commons.Dialog();
oCreateDialog.setTitle("Create user");
var oSimpleForm = new sap.ui.layout.form.SimpleForm({
maxContainerCols: 2,
content:[
new sap.ui.core.Title({text:"Person"}),
new sap.ui.commons.Label({text:"Email"}),
new sap.ui.commons.TextField({value:""}),
new sap.ui.commons.Label({text:"Firstname"}),
new sap.ui.commons.TextField({value:""}),
new sap.ui.commons.Label({text:"Lastname"}),
new sap.ui.commons.TextField({value:""}),
new sap.ui.commons.Label({text:"Age"}),
new sap.ui.commons.TextField({value:""}),
new sap.ui.commons.Label({text:"Address"}),
new sap.ui.commons.TextField({value:""}),
]
});
oCreateDialog.addContent(oSimpleForm);
oCreateDialog.addButton(
new sap.ui.commons.Button({
text: "Submit",
press: function() {
var content = oSimpleForm.getContent();
var oEntry = {};
oEntry.Email = content[2].getValue();
oEntry.Firstname = content[4].getValue();
oEntry.Lastname = content[6].getValue();
oEntry.Age = content[8].getValue();
oEntry.Address = content[10].getValue();
sap.ui.getCore().getModel().create('/UserSet', oEntry, null, function(){
oCreateDialog.close();
sap.ui.getCore().getModel().refresh();
},function(){
oCreateDialog.close();
alert("Create failed");
}
);
}
})
);
oCreateDialog.open();
};

/***** PUT Operation *****/
function openUpdateDialog(user){
var oUpdateDialog = new sap.ui.commons.Dialog();
oUpdateDialog.setTitle("Update user's data");
var oSimpleForm = new sap.ui.layout.form.SimpleForm({
maxContainerCols: 2,
content:[
new sap.ui.core.Title({text:"Person"}),
new sap.ui.commons.Label({text:"Email"}),
new sap.ui.commons.TextField({value: user[0].getValue(), editable: false}),
new sap.ui.commons.Label({text:"Firstname"}),
new sap.ui.commons.TextField({value: user[1].getValue()}),
new sap.ui.commons.Label({text:"Lastname"}),
new sap.ui.commons.TextField({value: user[2].getValue()}),
new sap.ui.commons.Label({text:"Age"}),
new sap.ui.commons.TextField({value: user[3].getValue()}),
new sap.ui.commons.Label({text:"Address"}),
new sap.ui.commons.TextField({value: user[4].getValue()}),
]
});
oUpdateDialog.addContent(oSimpleForm);
oUpdateDialog.addButton(
new sap.ui.commons.Button({
text: "Submit",
press: function() {
var content = oSimpleForm.getContent();
var oEntry = {};
oEntry.Email = content[2].getValue();
oEntry.Firstname = content[4].getValue();
oEntry.Lastname = content[6].getValue();
oEntry.Age = content[8].getValue();
oEntry.Address = content[10].getValue();
sap.ui.getCore().getModel().update("/UserSet('" + oEntry.Email + "')", oEntry, null, function(){
sap.ui.getCore().getModel().refresh();
oUpdateDialog.close();
},function(){
oUpdateDialog.close();
alert("Update failed");
}
);
}
})
);
oUpdateDialog.open();
};

/***** DELETE Operation *****/
function openDeleteDialog(email) {
var oDeleteDialog = new sap.ui.commons.Dialog();
oDeleteDialog.setTitle("Delete user");
var oText = new sap.ui.commons.TextView({text: "Are you sure to delete this user?"});
oDeleteDialog.addContent(oText);
oDeleteDialog.addButton(
new sap.ui.commons.Button({
text: "Confirm",
press:function(){
sap.ui.getCore().getModel().remove("/UserSet('" + email + "')", null, function() {
sap.ui.getCore().getModel().refresh();
oDeleteDialog.close();
},function(){
oDeleteDialog.close();
alert("Delete failed");
});
}
})
);
oDeleteDialog.open();
}

// setting up table
var oTable = new sap.ui.table.Table({
editable: false,
toolbar: new sap.ui.commons.Toolbar({
items: [
new sap.ui.commons.Button({
text: "Create user",
press: function() {
openCreateDialog();
},
}),
new sap.ui.commons.Button({
text: "Update user's data",
press: function() {
var idx = oTable.getSelectedIndex();
if (idx == -1) return;
var rows = oTable.getRows();
var user = rows[idx].getCells();
openUpdateDialog(user);
},
}),
new sap.ui.commons.Button({
text: "Delete user",
press: function() {
var idx = oTable.getSelectedIndex();
if (idx == -1) return;
var rows = oTable.getRows();
var user = rows[idx].getCells();
openDeleteDialog(user[0].getValue());
},
})
]
}),
});

oTable.addColumn(new sap.ui.table.Column({
label: new sap.ui.commons.Label({text: "Email"}),
template: new sap.ui.commons.TextField().bindProperty("value", "Email"),
editable: false,
sortProperty: "Email"
}));

oTable.addColumn(new sap.ui.table.Column({
label: new sap.ui.commons.Label({text: "Firstname"}),
template: new sap.ui.commons.TextField().bindProperty("value", "Firstname"),
sortProperty: "Firstname",
editable: false,
}));

oTable.addColumn(new sap.ui.table.Column({
label: new sap.ui.commons.Label({text: "Lastname"}),
template: new sap.ui.commons.TextField().bindProperty("value", "Lastname"),
sortProperty: "Lastname",
editable: false,
}));

oTable.addColumn(new sap.ui.table.Column({
label: new sap.ui.commons.Label({text: "Age"}),
template: new sap.ui.commons.TextField().bindProperty("value", "Age"),
sortProperty: "Age",
editable: false,
}));

oTable.addColumn(new sap.ui.table.Column({
label: new sap.ui.commons.Label({text: "Address"}),
template: new sap.ui.commons.TextField().bindProperty("value", "Address"),
sortProperty: "Address",
editable: false,
}));


oTable.setModel(oModel);
oTable.bindRows("/UserSet");
oTable.placeAt("content");


</script>

</head>
<body class="sapUiBody" role="application">
<div id="content"></div>
</body>
</html>
23 changes: 23 additions & 0 deletions model/User.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[
{
"Email" : "[email protected]",
"Firstname" : "John",
"Lastname" : "Doe",
"Age" : 45,
"Address" : "New York, USA"
},
{
"Email" : "[email protected]",
"Firstname" : "Peter",
"Lastname" : "Smith",
"Age" : 52,
"Address" : "Paris, France"
},
{
"Email" : "[email protected]",
"Firstname" : "James",
"Lastname" : "Bond",
"Age" : 35,
"Address" : "Liverpool, UK"
}
]
36 changes: 36 additions & 0 deletions model/metadata.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8" ?>
<edmx:Edmx Version="1.0"
xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
xmlns:sap="http://www.sap.com/Protocols/SAPData">
<edmx:DataServices m:DataServiceVersion="2.0">
<Schema Namespace="ZSA_USERS_SRV" xml:lang="en"
sap:schema-version="0000" xmlns="http://schemas.microsoft.com/ado/2008/09/edm">
<EntityType Name="User" sap:content-version="1">
<Key>
<PropertyRef Name="Email" />
</Key>
<Property Name="Email" Type="Edm.String" Nullable="false"
MaxLength="100" sap:label="Character 100" sap:creatable="false"
sap:updatable="false" sap:sortable="false" sap:filterable="false" />
<Property Name="Firstname" Type="Edm.String" Nullable="false"
MaxLength="100" sap:label="Character 100" sap:creatable="false"
sap:updatable="false" sap:sortable="false" sap:filterable="false" />
<Property Name="Lastname" Type="Edm.String" Nullable="false"
MaxLength="100" sap:label="Character 100" sap:creatable="false"
sap:updatable="false" sap:sortable="false" sap:filterable="false" />
<Property Name="Age" Type="Edm.Int32" Nullable="false"
sap:label="AGE" sap:creatable="false" sap:updatable="false"
sap:sortable="false" sap:filterable="false" />
<Property Name="Address" Type="Edm.String" Nullable="false"
MaxLength="100" sap:label="ADDRESS" sap:creatable="false"
sap:updatable="false" sap:sortable="false" sap:filterable="false" />
</EntityType>
<EntityContainer Name="ZSA_USERS_SRV_Entities"
m:IsDefaultEntityContainer="true">
<EntitySet Name="UserSet" EntityType="ZSA_USERS_SRV.User"
sap:pageable="false" sap:content-version="1" />
</EntityContainer>
</Schema>
</edmx:DataServices>
</edmx:Edmx>

0 comments on commit c328c3d

Please sign in to comment.