onInit: function() {
this._oViewModel = new JSONModel({
selectedIcon: "",
selectedCategoryId: "",
allIcons: [],
items: [{
"id": 1,
"name": "Flats",
"icon": ""
}, {
"id": 2,
"name": "Hostels",
"icon": "bed"
}, {
"id": 3,
"name": "Apartments",
"icon": "capital-projects"
}, {
"id": 4,
"name": "Cars",
"icon": "car-rental"
}, {
"id": 5,
"name": "Meetings",
"icon": "family-care"
}, {
"id": 6,
"name": "Restaurants",
"icon": ""
}, {
"id": 7,
"name": "Theaters",
"icon": "theater"
}, {
"id": 8,
"name": "Mileage",
"icon": ""
}, {
"id": 9,
"name": "Flights",
"icon": ""
}, {
"id": 10,
"name": "Travels",
"icon": "travel-itinerary"
}, {
"id": 11,
"name": "Customers",
"icon": "customer"
}]
});
this.getView().setModel(this._oViewModel, "details");
var oComponent = this.getOwnerComponent();
this._oResourceBundle = oComponent.getModel("i18n").getResourceBundle();
this.getView().addStyleClass("sapUiSizeCompact");
this._oViewModel.setSizeLimit(999);
this.loadAllIconsIntoJson();
},
this._oViewModel.setSizeLimit(999);
loadAllIconsIntoJson: function() {
var tempArray = [];
for (var i = 0; i < IconPool.getIconNames().length; i++) {
tempArray.push({
iconName: IconPool.getIconNames()[i]
});
}
this._oViewModel.setProperty("/allIcons", tempArray);
},
sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/ui/model/json/JSONModel",
"sap/ui/model/Filter",
"sap/m/MessageToast",
"sap/ui/core/IconPool"
]
<mvc:View controllerName="icons.controller.App" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:mvc="sap.ui.core.mvc"
xmlns:core="sap.ui.core" displayBlock="true" xmlns="sap.m">
<App>
<pages>
<Page title="{i18n>title}">
<content>
<VBox>
<Table items="{details>/items}">
<headerToolbar>
<Toolbar>
<core:Icon src="sap-icon://table-view" tooltip="sap-icon://table-view" size="1.5em"/>
<Title text="{i18n>listHeaderTitle}" level="H1"/>
</Toolbar>
</headerToolbar>
<columns>
<Column hAlign="Center" width="120px">
<Text/>
</Column>
<Column hAlign="Left" width="160px">
<Text text="{i18n>itemNameColumnTitle}"/>
</Column>
<Column hAlign="Center" width="90px">
<Text text="{i18n>itemIconColumnTitle}"/>
</Column>
<Column hAlign="Center" width="90px">
<Text/>
</Column>
<Column></Column>
</columns>
<items>
<ColumnListItem>
<cells>
<Button type="{= ${details>icon} ? 'Accept' : 'Emphasized' }" text="{= ${details>icon} === '' ? ${i18n>iconSelectButtonTitle} : ${i18n>iconChangeButtonTitle} }"
press="showIconSelectDialog"></Button>
<Text text="{details>name}"/>
<core:Icon src="{details>icon}" size="1.5em" tooltip="{details>icon}" visible="{= ${details>icon} === '' ? false : true }"/>
<Button type="Reject" icon="sap-icon://decline" press="deleteIcon" tooltip="{i18n>iconDeleteTooltip}" visible="{= ${details>icon} ? true : false }"></Button>
<Text/>
</cells>
</ColumnListItem>
</items>
</Table>
</VBox>
</content>
</Page>
</pages>
</App>
</mvc:View>
<core:FragmentDefinition xmlns="sap.m" xmlns:core="sap.ui.core" xmlns:f="sap.ui.layout.form" xmlns:l="sap.ui.layout"
xmlns:u="sap.ui.unified">
<Dialog contentWidth="500px" contentHeight="500px" title="{i18n>iconsSelectDialogTitle}">
<subHeader>
<Toolbar>
<SearchField liveChange="onIconSearch" width="100%"/>
</Toolbar>
</subHeader>
<content>
<List id="idList" items="{ path : 'details>/allIcons', sorter : { path : 'iconName', descending: false } }"
selectionChange="onIconSelectionChange" mode="SingleSelect" includeItemInSelection="true">
<items>
<StandardListItem title="{details>iconName}" icon="sap-icon://{details>iconName}" iconDensityAware="false"/>
</items>
</List>
</content>
<beginButton>
<Button text="{i18n>selectButtonText}" press="onSetIcon" enabled="{= ${details>/selectedIcon} ? true : false }"/>
</beginButton>
<endButton>
<Button text="{i18n>closeButtonText}" press="onCloseIconSelectDialog"/>
</endButton>
</Dialog>
</core:FragmentDefinition>
sap.ui.define([
.. libraries ..
], function(Controller, JSONModel, Filter, MessageToast, IconPool) {
"use strict";
return Controller.extend("icons.controller.App", {
onInit: function() {
this._oViewModel = new JSONModel({
selectedIcon: "",
selectedCategoryId: "",
allIcons: [],
items: [.. category items ..]
});
this.getView().setModel(this._oViewModel, "details");
var oComponent = this.getOwnerComponent();
this._oResourceBundle = oComponent.getModel("i18n").getResourceBundle();
this.getView().addStyleClass("sapUiSizeCompact");
this._oViewModel.setSizeLimit(999);
this.loadAllIconsIntoJson();
},
// convert icons array to json format in the model
loadAllIconsIntoJson: function() {
var tempArray = [];
for (var i = 0; i < IconPool.getIconNames().length; i++) {
tempArray.push({
iconName: IconPool.getIconNames()[i]
});
}
this._oViewModel.setProperty("/allIcons", tempArray);
},
// open "select icon" fragment dialog
showIconSelectDialog: function(oEvent) {
var temp = oEvent.getSource().getParent().getId().split("-");
this._oViewModel.setProperty("/selectedCategoryId", temp[temp.length - 1]);
if (!this._oIconSelectDialogDialog) {
this._oIconSelectDialogDialog = sap.ui.xmlfragment("icons.fragment.IconSelectDialog", this);
this.getView().addDependent(this._oIconSelectDialogDialog);
this._oIconSelectDialogDialog.open();
}
},
// dynamic searching among the all icons
onIconSearch: function(oEvt) {
var aFilters = [];
var sQuery = oEvt.getSource().getValue();
if (sQuery && sQuery.length > 0) {
var filter = new Filter("iconName", sap.ui.model.FilterOperator.Contains, sQuery);
aFilters.push(filter);
}
var list = sap.ui.getCore().byId("idList");
var binding = list.getBinding("items");
binding.filter(aFilters, "Application");
},
// if user clicks on the bar with icon name and its graphics icon, it will be set to model property - "selectedIcon"
onIconSelectionChange: function(oEvt) {
var selectedIcon = oEvt.getParameter("listItem").getProperty("icon");
this._oViewModel.setProperty("/selectedIcon", selectedIcon);
},
// run if user clicks the "Select" button on the bottom bar of the dialog
onSetIcon: function() {
var icon = this._oViewModel.getProperty("/selectedIcon");
var categoryId = this._oViewModel.getProperty("/selectedCategoryId");
this._oViewModel.setProperty("/items/" + categoryId + "/icon", icon);
this._oViewModel.setProperty("/selectedIcon", "");
this._oIconSelectDialogDialog.close();
this._oIconSelectDialogDialog.destroy();
this._oIconSelectDialogDialog = null;
MessageToast.show(this._oResourceBundle.getText("iconSelectedMessage"));
},
// run if user clicks the "Close" button on the bottom bar of the dialog
onCloseIconSelectDialog: function() {
this._oViewModel.setProperty("/selectedIcon", "");
this._oIconSelectDialogDialog.close();
this._oIconSelectDialogDialog.destroy();
this._oIconSelectDialogDialog = null;
},
deleteIcon: function(oEvent) {
var temp = oEvent.getSource().getParent().getId().split("-");
var categoryId = temp[temp.length - 1];
this._oViewModel.setProperty("/items/" + categoryId + "/icon", "");
MessageToast.show(this._oResourceBundle.getText("iconDeletedMessage"));
}
});
});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
12 | |
11 | |
7 | |
5 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 |