<core:FragmentDefinition xmlns="sap.m" xmlns:core="sap.ui.core" xmlns:ovp="sap.ovp.ui"
xmlns:template="http://schemas.sap.com/sapui5/extension/sap.ui.core.template/1">
<Toolbar>
<Title text="{ovpCardProperties>/title}" class="sapUiSmallMarginBegin"/>
<ToolbarSpacer/>
<Button icon="sap-icon://add" press="onAddTask"/>
</Toolbar>
<VBox id="tasks"/>
</core:FragmentDefinition>
(function () {
"use strict";
/* controller for custom card */
sap.ui.controller("zzz.ovpdemodw.ext.Task.Task", {
onInit: function () {
},
onAfterRendering: function () {
},
onExit: function () {
}
});
})();
onAfterRendering: function () {
var oView = this.getView(),
oCardPropertiesModel = oView.getModel("ovpCardProperties"),
aTasks = oCardPropertiesModel.getProperty("/tasks"),
i,
oTasksFlexBox = oView.byId("tasks");
oTasksFlexBox.removeAllItems();
for (i = 0; i < aTasks.length; i++) {
oTasksFlexBox.addItem(new sap.m.HBox({
items: [
new sap.m.CheckBox({
text: aTasks[i].text,
selected: aTasks[i].selected,
enabled: aTasks[i].enabled,
select: this.onItemSelected.bind(this)
})
]
}));
}
}
//on selection of items in the list the task will be marked as done
onItemSelected: function (oEvent) {
var oSource = oEvent.getSource();
oSource.setEnabled(false);
var oView = this.getView(),
oTasksFlexBox = oView.byId("tasks"),
oCardPropertiesModel = oView.getModel("ovpCardProperties"),
aTasks = oCardPropertiesModel.getProperty("/tasks");
var iIndex = oTasksFlexBox.indexOfItem(oSource.getParent());
aTasks[iIndex].enabled = false;
aTasks[iIndex].selected = true;
oCardPropertiesModel.setProperty("/tasks", aTasks);
oCardPropertiesModel.refresh(true);
},
onAddTask: function (oEvent) {
var oSaveButton = new sap.m.Button({
text: "Save",
type: "Emphasized"
});
// settings dialog close button
var oCancelButton = new sap.m.Button({
text: "Cancel"
});
var oDialog = new sap.m.Dialog({
title: "Create a Task",
modal: true,
contentWidth: "1em",
buttons: [oSaveButton, oCancelButton],
content: [
new sap.m.Label({
text: "Task Name"
}),
new sap.m.Input({
maxLength: 100
})
]
}).addStyleClass("sapUiContentPadding");
oCancelButton.attachPress(function () {
oDialog.close();
});
oSaveButton.attachPress(function () {
var oView = this.getView(),
oCardPropertiesModel = oView.getModel("ovpCardProperties"),
aTasks = oCardPropertiesModel.getProperty("/tasks");
aTasks.push({
"text": oDialog.getContent()[1].getValue(),
"enabled": true,
"selected": false
});
oCardPropertiesModel.setProperty("/tasks", aTasks);
oCardPropertiesModel.refresh(true);
this.getOwnerComponent().getComponentData().mainComponent.getLayout().rerender();
oDialog.close();
}.bind(this));
oDialog.open();
}
"card03": {
"template": "zzz.ovpdemodw.ext.Task",
"settings": {
"title": "{{card03_title}}"
}
}
"card03": {
"template": "zzz.ovpdemodw.ext.Task",
"settings": {
"title": "{{card03_title}}",
"tasks": []
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
37 | |
25 | |
17 | |
13 | |
7 | |
7 | |
7 | |
6 | |
6 | |
6 |