.
304 Create Ionic Sales Book Master-Detail Pages
Building On Codepen Platform
Continue from the previous tutorial, http://basic-steps.blogspot.my/2017/01/303-create-ionic-sales-record-book-with.html
Continue from the previous tutorial, http://basic-steps.blogspot.my/2017/01/303-create-ionic-sales-record-book-with.html
1) Create Page Structure
HOME->Details
SUMMARY->Monthly->Daily->Details
Partial Codes: Opening HTML
<html>
<head>
<meta charset="utf-8">
<title>Diary</title>
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<!-- Internal Library
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<script src="lib/ionic/js/ionic.bundle.js"></script>
-->
<!-- Cloud Library -->
<link href="//code.ionicframework.com/nightly/css/ionic.css" rel="stylesheet">
<script src="//code.ionicframework.com/nightly/js/ionic.bundle.js"></script>
<!-- Needed for Cordova/PhoneGap (will be a 404 during development) -->
<script src="cordova.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/datejs/1.0/date.min.js"></script>
</head>
|
Partial Codes: Body and Nav-Bar/Nav-View
<body ng-app="app">
<div>
<div>
<ion-nav-bar class="bar-stable">
<ion-nav-back-button></ion-nav-back-button>
</ion-nav-bar>
<ion-nav-view></ion-nav-view>
</div>
</div>
|
Partial Codes: HOME
<script id="home.html" type="text/ng-template">
<ion-view title="Home" id="page1">
<ion-content padding="true" class="has-header">
<button class="button button-block button-calm" ui-sref="menu.details">
View Details
</button>
<button class="button button-block button-royal" ui-sref="menu.monthly">
View Summary
</button>
</ion-content>
</ion-view>
</script>
|
Partial Codes: SIDE MENU
<script id="menu.html" type="text/ng-template">
<ion-side-menus enable-menu-with-back-views="false">
<ion-side-menu-content>
<ion-nav-bar class="bar-stable">
<ion-nav-back-button></ion-nav-back-button>
<ion-nav-buttons side="left">
<button class="button button-icon button-clear ion-navicon" menu-toggle="left"></button>
</ion-nav-buttons>
</ion-nav-bar>
<ion-nav-view name="side-menu21"></ion-nav-view>
</ion-side-menu-content>
<ion-side-menu side="left" id="side-menu21">
<ion-header-bar class="bar-stable">
<div class="title">Menu</div>
</ion-header-bar>
<ion-content padding="false" class="side-menu-left has-header ">
<ion-list id="menu-list1">
<ion-item id="menu-list-item1" ui-sref="menu.home" menu-close="">Home</ion-item>
<ion-item id="menu-list-item2" ui-sref="menu.monthly" menu-close="">Summary</ion-item>
</ion-list>
</ion-content>
</ion-side-menu>
</ion-side-menus>
</script>
|
Partial Codes: SUMMARY-Monthly
<script id="monthly.html" type="text/ng-template">
<ion-view title="Monthly" id="page2">
<ion-content padding="true" class="has-header">
<h2>MONTHLY SUMMARY</h2>
<div class="row">
<div class="col"><b>Date</b></div>
<div class="col"><b>Sales</b></div>
</div>
<div ui-sref="menu.daily">test</test>
<div class="row" ng-class-odd="'odd'" ng-class-even="'even'" ng-repeat="(key, value) in summaryMonthly">
<div class="col">{{key}}</div>
<div class="col">{{value}}</div>
</div>
</ion-content>
</ion-view>
</script>
|
Partial Codes: SUMMARY-Daily
<script id="daily.html" type="text/ng-template">
<ion-view title="Daily" id="page3">
<ion-content padding="true" class="has-header">
<h2>DAILY SUMMARY</h2>
<div class="row">
<div class="col"><b>Date</b></div>
<div class="col"><b>Sales</b></div>
</div>
<div ui-sref="menu.details">test</test>
<div class="row" ng-class-odd="'odd'" ng-class-even="'even'" ng-repeat="(key, value) in summaryDaily">
<div class="col">{{key}}</div>
<div class="col">{{value}}</div>
</div>
</ion-content>
</ion-view>
</script>
|
Partial Codes: DETAILS
<script id="details.html" type="text/ng-template">
<ion-view title="Details" id="page4">
<ion-nav-buttons side="right" class="has-header">
<button class="button button-icon" ng-click="insertRecord()">
<i class="icon ion-compose"></i>
</button>
</ion-nav-buttons>
<ion-content padding="true" class="has-header">
<h2>DETAILS</h2>
<div class="row">
<div class="col"><b>Date</b></div>
<div class="col"><b>Sales</b></div>
</div>
<div class="row" ng-class-odd="'odd'" ng-class-even="'even'" ng-repeat="detail in details |orderBy:'-date'">
<div class="col">{{detail.date| date:'yyyy-MM-dd'}}</div>
<div class="col">{{detail.value}}</div>
</div>
</ion-content>
</ion-view>
</script>
|
Partial Codes: Closing HTML
</body>
</html>
|
FULL CODES
HTML
<html>
<head>
<meta charset="utf-8">
<title>Diary</title>
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<!-- Internal Library
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<script src="lib/ionic/js/ionic.bundle.js"></script>
-->
<!-- Cloud Library -->
<link href="//code.ionicframework.com/nightly/css/ionic.css" rel="stylesheet">
<script src="//code.ionicframework.com/nightly/js/ionic.bundle.js"></script>
<!-- Needed for Cordova/PhoneGap (will be a 404 during development) -->
<script src="cordova.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/datejs/1.0/date.min.js"></script>
</head>
<body ng-app="app">
<div>
<div>
<ion-nav-bar class="bar-stable">
<ion-nav-back-button></ion-nav-back-button>
</ion-nav-bar>
<ion-nav-view></ion-nav-view>
</div>
</div>
<script id="home.html" type="text/ng-template">
<ion-view title="Home" id="page1">
<ion-content padding="true" class="has-header">
<button class="button button-block button-calm" ui-sref="menu.details">
View Details
</button>
<button class="button button-block button-royal" ui-sref="menu.monthly">
View Summary
</button>
</ion-content>
</ion-view>
</script>
<script id="menu.html" type="text/ng-template">
<ion-side-menus enable-menu-with-back-views="false">
<ion-side-menu-content>
<ion-nav-bar class="bar-stable">
<ion-nav-back-button></ion-nav-back-button>
<ion-nav-buttons side="left">
<button class="button button-icon button-clear ion-navicon" menu-toggle="left"></button>
</ion-nav-buttons>
</ion-nav-bar>
<ion-nav-view name="side-menu21"></ion-nav-view>
</ion-side-menu-content>
<ion-side-menu side="left" id="side-menu21">
<ion-header-bar class="bar-stable">
<div class="title">Menu</div>
</ion-header-bar>
<ion-content padding="false" class="side-menu-left has-header ">
<ion-list id="menu-list1">
<ion-item id="menu-list-item1" ui-sref="menu.home" menu-close="">Home</ion-item>
<ion-item id="menu-list-item2" ui-sref="menu.monthly" menu-close="">Summary</ion-item>
</ion-list>
</ion-content>
</ion-side-menu>
</ion-side-menus>
</script>
<script id="monthly.html" type="text/ng-template">
<ion-view title="Monthly" id="page2">
<ion-content padding="true" class="has-header">
<h2>MONTHLY SUMMARY</h2>
<div class="row">
<div class="col"><b>Date</b></div>
<div class="col"><b>Sales</b></div>
</div>
<div ui-sref="menu.daily">test</test>
<div class="row" ng-class-odd="'odd'" ng-class-even="'even'" ng-repeat="(key, value) in summaryMonthly">
<div class="col">{{key}}</div>
<div class="col">{{value}}</div>
</div>
</ion-content>
</ion-view>
</script>
<script id="daily.html" type="text/ng-template">
<ion-view title="Daily" id="page3">
<ion-content padding="true" class="has-header">
<h2>DAILY SUMMARY</h2>
<div class="row">
<div class="col"><b>Date</b></div>
<div class="col"><b>Sales</b></div>
</div>
<div ui-sref="menu.details">test</test>
<div class="row" ng-class-odd="'odd'" ng-class-even="'even'" ng-repeat="(key, value) in summaryDaily">
<div class="col">{{key}}</div>
<div class="col">{{value}}</div>
</div>
</ion-content>
</ion-view>
</script>
<script id="details.html" type="text/ng-template">
<ion-view title="Details" id="page4">
<ion-nav-buttons side="right" class="has-header">
<button class="button button-icon" ng-click="insertRecord()">
<i class="icon ion-compose"></i>
</button>
</ion-nav-buttons>
<ion-content padding="true" class="has-header">
<h2>DETAILS</h2>
<div class="row">
<div class="col"><b>Date</b></div>
<div class="col"><b>Sales</b></div>
</div>
<div class="row" ng-class-odd="'odd'" ng-class-even="'even'" ng-repeat="detail in details |orderBy:'-date'">
<div class="col">{{detail.date| date:'yyyy-MM-dd'}}</div>
<div class="col">{{detail.value}}</div>
</div>
</ion-content>
</ion-view>
</script>
</body>
</html>
|
JS
angular.module('app', ['ionic'])
.factory('DataTree', function() {
return {
all: function(trunkName) {
var trunkString = window.localStorage[trunkName];
if (trunkString) {
return angular.fromJson(trunkString);
}
return [];
},
save: function(trunkName, trunkString) {
//console.log(trunkString);
window.localStorage[trunkName] = angular.toJson(trunkString);
}
}
})
.controller('homeCtrl', ['$scope', '$stateParams', 'DataTree',
function($scope, $stateParams, DataTree) {}
])
.controller('menuCtrl', ['$scope', '$stateParams',
function($scope, $stateParams) {}
])
.controller('monthlyCtrl', ['$scope', '$stateParams', 'DataTree',
function($scope, $stateParams, DataTree) {}
])
.controller('dailyCtrl', ['$scope', '$stateParams', 'DataTree',
function($scope, $stateParams, DataTree) {}
])
.controller('detailsCtrl', ['$scope', '$stateParams', '$ionicModal', 'DataTree',
function($scope, $stateParams, $ionicModal, DataTree) {}
])
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('menu.home', {
url: '/page1',
views: {
'side-menu21': {
templateUrl: 'home.html',
controller: 'homeCtrl'
}
}
})
.state('menu', {
url: '/side-menu21',
templateUrl: 'menu.html',
controller: 'menuCtrl'
})
.state('menu.monthly', {
url: '/page2',
views: {
'side-menu21': {
templateUrl: 'monthly.html',
controller: 'monthlyCtrl'
}
}
})
.state('menu.daily', {
url: '/page3',
views: {
'side-menu21': {
templateUrl: 'daily.html',
controller: 'dailyCtrl'
}
}
})
.state('menu.details', {
url: '/page4',
views: {
'side-menu21': {
templateUrl: 'details.html',
controller: 'detailsCtrl'
}
}
})
$urlRouterProvider.otherwise('/side-menu21/page1')
});
|
ADDITIONAL READING:
http://blog.scottlogic.com/2015/10/02/ionic-master-detail.html .
No comments:
Post a Comment