Skip to content

Commit

Permalink
Device creation is possible. Change of active not yet #10
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorwolf committed Oct 4, 2016
1 parent e2e24b1 commit 8959290
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 9 deletions.
60 changes: 58 additions & 2 deletions webapp/controller/Detail.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ sap.ui.define([
this._oViewModel = new JSONModel({
busy: false,
enableCreateCoOrganizer: false,
enableCreateDevice: false,
hasEditAuthorityCoOrganizer: false,
delay: 0
});
Expand Down Expand Up @@ -134,6 +135,31 @@ sap.ui.define([
});
},

/**
* Event handler for the view save device button.
* Create entry in model and save data.
* @function
* @public
*/
onSaveDevice: function(oEvent) {
var oViewModel = this.getModel("detailView"),
sPath = oViewModel.getProperty("/sObjectPath"),
sID = this._oODataModel.getProperty(sPath + "/ID");
var sDeviceID = this.byId("Device_id").getValue();
// create entry properties
var oEntry = {
EventID: sID,
DeviceID: sDeviceID,
Active: "Y"
};
this._oODataModel.createEntry("/Devices", {
properties: oEntry
});
this._oODataModel.submitChanges({
success: this._onSaveDeviceSuccess.bind(this),
error: this._onSaveDeviceError.bind(this)
});
},
/**
* Event handler for the view export partipicants as excel.
* @function
Expand Down Expand Up @@ -179,11 +205,21 @@ sap.ui.define([
MessageToast.show(sMessage);
},
_onSaveCoOrganizerError: function(oError) {
var sMessage = this.getResourceBundle().getText("onSaveCoOrganizerSuccess");
var sMessage = this.getResourceBundle().getText("onSaveCoOrganizerError");
MessageToast.show(sMessage);
},

_onSaveDeviceSuccess: function(oData) {
this.byId("Device_id").setValue(null);
var sMessage = this.getResourceBundle().getText("onSaveDeviceSuccess");
MessageToast.show(sMessage);
},
_onSaveDeviceError: function(oError) {
var sMessage = this.getResourceBundle().getText("onSaveDeviceError");
MessageToast.show(sMessage);
},
/**
* Checks if the save button can be enabled
* Checks if the save button for the CoOrganizer can be enabled
* @private
*/
_validateSaveEnablementCoOrganizer: function() {
Expand All @@ -202,6 +238,26 @@ sap.ui.define([
}
}
},
/**
* Checks if the save button for the Device can be enabled
* @private
*/
_validateSaveEnablementDevice: function() {
var aInputControls = this._getFormFields(this.byId("newDevicesForm"));
var oControl;
for (var m = 0; m < aInputControls.length; m++) {
oControl = aInputControls[m].control;
if (aInputControls[m].required) {
var sValue = oControl.getValue();
if (!sValue) {
this._oViewModel.setProperty("/enableCreateDevice", false);
return;
} else {
this._oViewModel.setProperty("/enableCreateDevice", true);
}
}
}
},
/**
* Binds the view to the object path and expands the aggregated line items.
* @function
Expand Down
31 changes: 24 additions & 7 deletions webapp/view/Detail.view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,37 @@
xmlns:semantic="sap.m.semantic"
xmlns:f="sap.ui.layout.form"
xmlns:footerbar="sap.ushell.ui.footerbar">
<semantic:DetailPage id="page" navButtonPress="onNavBack" showNavButton="{device>/system/phone}" title="{i18n>detailTitle}"
busy="{detailView>/busy}" busyIndicatorDelay="{detailView>/delay}">
<semantic:DetailPage id="page"
navButtonPress="onNavBack"
showNavButton="{device>/system/phone}"
title="{i18n>detailTitle}"
busy="{detailView>/busy}"
busyIndicatorDelay="{detailView>/delay}">
<semantic:content>
<ObjectHeader id="objectHeader" title="{Location}" numberUnit="{i18n>detailEventID}: {ID}"
number="{ path: 'EventDate', type: 'sap.ui.model.type.Date', formatOptions: { style: 'medium' } }"></ObjectHeader>
<ObjectHeader id="objectHeader"
title="{Location}"
numberUnit="{i18n>detailEventID}: {ID}"
number="{ path: 'EventDate', type: 'sap.ui.model.type.Date', formatOptions: { style: 'medium' } }" />
<IconTabBar id="iconTabBar" class="sapUiResponsiveContentPadding">
<items>
<IconTabFilter id="iconTabBarFilter1" icon="sap-icon://hint" tooltip="{i18n>detailIconTabBarInfo}">
<IconTabFilter id="iconTabBarFilter1"
icon="sap-icon://hint"
tooltip="{i18n>detailIconTabBarInfo}">
<core:Fragment fragmentName="com.sap.sapmentors.sitreg.events.view.EventForm" type="XML" />
</IconTabFilter>
<IconTabFilter id="iconTabBarFilter2" icon="sap-icon://employee-approvals" tooltip="{i18n>detailIconTabBarCoOrganizers}">
<IconTabFilter id="iconTabBarFilter2"
icon="sap-icon://employee-approvals"
tooltip="{i18n>detailIconTabBarCoOrganizers}">
<core:Fragment fragmentName="com.sap.sapmentors.sitreg.events.view.CoOrganizerForm" type="XML" />
</IconTabFilter>
<IconTabFilter id="iconTabBarFilter3" icon="sap-icon://group" tooltip="{i18n>deatailIconPartipitants}">
<IconTabFilter id="iconTabBarFilter3"
icon="sap-icon://machine"
tooltip="{i18n>deatailIconDevices}">
<core:Fragment fragmentName="com.sap.sapmentors.sitreg.events.view.DevicesForm" type="XML" />
</IconTabFilter>
<IconTabFilter id="iconTabBarFilter4"
icon="sap-icon://group"
tooltip="{i18n>deatailIconPartipitants}">
<core:Fragment fragmentName="com.sap.sapmentors.sitreg.events.view.PartipicantsTable" type="XML" />
</IconTabFilter>
</items>
Expand Down
54 changes: 54 additions & 0 deletions webapp/view/DevicesForm.fragment.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<core:FragmentDefinition
xmlns:core="sap.ui.core"
xmlns:f="sap.ui.layout.form"
xmlns="sap.m">
<f:SimpleForm id="newDevicesForm"
class="editableForm"
columnsL="1"
columnsM="1"
editable="true"
emptySpanL="4"
emptySpanM="4"
labelSpanL="3"
labelSpanM="3"
layout="ResponsiveGridLayout"
maxContainerCols="2"
minWidth="1024"
visible="{detailView>/hasEditAuthorityCoOrganizer}"
title="{i18n>detailAddDevice}">
<f:content>
<Label text="{i18n>detailDevice}" required="true"/>
<Input id="Device_id"
valueLiveUpdate="true"
liveChange="_validateSaveEnablementDevice"
enabled="true" visible="true" maxLength="36"/>
<Button id="saveDevice" enabled="{detailView>/enableCreateDevice}" text="Save" press="onSaveDevice"/>
</f:content>
</f:SimpleForm>
<Table id="idDeviceTable" items="{ path: 'Devices', sorter: { path: 'DeviceID' } }">
<headerToolbar>
<Toolbar>
<Title text="{i18n>detailIconTabBarDevices}" level="H2"/>
</Toolbar>
</headerToolbar>
<columns>
<Column>
<Text text="{i18n>detailDevice}"/>
</Column>
<Column hAlign="Center" minScreenWidth="Tablet" demandPopin="true">
<Text text="Active"/>
</Column>
</columns>
<items>
<ColumnListItem>
<cells>
<ObjectIdentifier title="{DeviceID}"/>
<Switch state="{= ${Active} === 'Y' ? true : false }"
customTextOn="Yes"
customTextOff="No"
enabled="{= ${History.CreatedBy} === ${currentUser>/name} ? true : false }"/>
</cells>
</ColumnListItem>
</items>
</Table>
</core:FragmentDefinition>

0 comments on commit 8959290

Please sign in to comment.