How to edit datepicker/day.html from uib-datepicker - angularjs

In the documentation for uib-datepicker there is an option called template-url
<-- https://angular-ui.github.io/bootstrap/#/datepicker -->
This is the content:
<div ng-switch="datepickerMode" role="application" ng-keydown="keydown($event)">
<uib-daypicker ng-switch-when="day" tabindex="0"></uib-daypicker>
<uib-monthpicker ng-switch-when="month" tabindex="0"></uib-monthpicker>
<uib-yearpicker ng-switch-when="year" tabindex="0"></uib-yearpicker>
</div>
But I need modify the template from "uib-daypicker"; I tried copying the template from datepicker/day.html but it's not working because it's a directive... so, what do I have to do?

----EDITED----
Into the library ui-bootstrap-tpls are all the templates:
datepicker.html
day.html
month.html
year.html
datepicker.html :
<div class="uib-datepicker" ng-switch="datepickerMode" role="application" ng-keydown="keydown($event)">
<uib-daypicker ng-switch-when="day" tabindex="0"></uib-daypicker>
<uib-monthpicker ng-switch-when="month" tabindex="0"></uib-monthpicker>
<uib-yearpicker ng-switch-when="year" tabindex="0"></uib-yearpicker>
</div>
day.html:
<table class="uib-daypicker" role="grid" aria-labelledby="{{::uniqueId}}-title" aria-activedescendant="{{activeDateId}}">
<thead>
<tr>
<th><button type="button" class="btn btn-default btn-sm pull-left uib-left" ng-click="move(-1)" tabindex="-1"><i class="glyphicon glyphicon-chevron-left"></i></button></th>
<th colspan="{{::5 + showWeeks}}"><button id="{{::uniqueId}}-title" role="heading" aria-live="assertive" aria-atomic="true" type="button" class="btn btn-default btn-sm uib-title" ng-click="toggleMode()" ng-disabled="datepickerMode === maxMode" tabindex="-1"><strong>{{title}}</strong></button></th>
<th><button type="button" class="btn btn-default btn-sm pull-right uib-right" ng-click="move(1)" tabindex="-1"><i class="glyphicon glyphicon-chevron-right"></i></button></th>
</tr>
<tr>
<th ng-if="showWeeks" class="text-center"></th>
<th ng-repeat="label in ::labels track by $index" class="text-center"><small aria-label="{{::label.full}}">{{::label.abbr}}</small></th>
</tr>
</thead>
<tbody>
<tr class="uib-weeks" ng-repeat="row in rows track by $index">
<td ng-if="showWeeks" class="text-center h6"><em>{{ weekNumbers[$index] }}</em></td>
<td ng-repeat="dt in row" class="uib-day text-center" role="gridcell"
id="{{::dt.uid}}"
ng-class="::dt.customClass">
<button type="button" class="btn btn-default btn-sm"
uib-is-class="
'btn-info' for selectedDt,
'active' for activeDt
on dt"
ng-click="select(dt.date)"
ng-disabled="::dt.disabled"
tabindex="-1"><span ng-class="::{'text-muted': dt.secondary, 'text-info': dt.current}">{{::dt.label}}</span></button>
</td>
</tr>
</tbody>
moth.html:
<table class="uib-monthpicker" role="grid" aria-labelledby="{{::uniqueId}}-title" aria-activedescendant="{{activeDateId}}">
<thead>
<tr>
<th><button type="button" class="btn btn-default btn-sm pull-left uib-left" ng-click="move(-1)" tabindex="-1"><i class="glyphicon glyphicon-chevron-left"></i></button></th>
<th><button id="{{::uniqueId}}-title" role="heading" aria-live="assertive" aria-atomic="true" type="button" class="btn btn-default btn-sm uib-title" ng-click="toggleMode()" ng-disabled="datepickerMode === maxMode" tabindex="-1"><strong>{{title}}</strong></button></th>
<th><button type="button" class="btn btn-default btn-sm pull-right uib-right" ng-click="move(1)" tabindex="-1"><i class="glyphicon glyphicon-chevron-right"></i></button></th>
</tr>
</thead>
<tbody>
<tr class="uib-months" ng-repeat="row in rows track by $index">
<td ng-repeat="dt in row" class="uib-month text-center" role="gridcell"
id="{{::dt.uid}}"
ng-class="::dt.customClass">
<button type="button" class="btn btn-default"
uib-is-class="
'btn-info' for selectedDt,
'active' for ativeDt
on dt"
ng-click="select(dt.date)"
ng-disabled="::dt.disabled"
tabindex="-1"><span ng-class="::{'text-info': dt.current}">{{::dt.label}}</span></button>
</td>
</tr>
</tbody>
</table>
year.html:
<table class="uib-yearpicker" role="grid" aria-labelledby="{{::uniqueId}}-title" aria-activedescendant="{{activeDateId}}">
<thead>
<tr>
<th><button type="button" class="btn btn-default btn-sm pull-left uib-left" ng-click="move(-1)" tabindex="-1"><i class="glyphicon glyphicon-chevron-left"></i></button></th>
<th colspan="{{::columns - 2}}"><button id="{{::uniqueId}}-title" role="heading" aria-live="assertive" aria-atomic="true" type="button" class="btn btn-default btn-sm uib-title" ng-click="toggleMode()" ng-disabled="datepickerMode === maxMode" tabindex="-1"><strong>{{title}}</strong></button></th>
<th><button type="button" class="btn btn-default btn-sm pull-right uib-right" ng-click="move(1)" tabindex="-1"><i class="glyphicon glyphicon-chevron-right"></i></button></th>
</tr>
</thead>
<tbody>
<tr class="uib-years" ng-repeat="row in rows track by $index">
<td ng-repeat="dt in row" class="uib-year text-center" role="gridcell"
id="{{::dt.uid}}"
ng-class="::dt.customClass">
<button type="button" class="btn btn-default"
uib-is-class="
'btn-info' for selectedDt,
'active' for activeDt
on dt"
ng-click="select(dt.date)"
ng-disabled="::dt.disabled"
tabindex="-1"><span ng-class="::{'text-info': dt.current}">{{::dt.label}}</span></button>
</td>
</tr>
</tbody>
</table>
So if you need change any one of those templates you just use the attribute template-url, for example:
<div class="uib-datepicker" ng-switch="datepickerMode" role="application" ng-keydown="keydown($event)">
<uib-daypicker ng-switch-when="day" template-url="template/route/template-day.html" tabindex="0"></uib-daypicker>
<uib-monthpicker ng-switch-when="month" template-url="template/route/template-moth.html" tabindex="0"></uib-monthpicker>
<uib-yearpicker ng-switch-when="year" template-url="template/route/template-year.html" tabindex="0"></uib-yearpicker>
</div>
Only make your changes on the original templates.
Pd: Sorry about my english isn't my native language.

Related

Ng-show not showing product's detail

I'm making an exercise about the AngularJS, and i created a table that will load the data from database, i have a "Detail" button, when i click on that button, it will assign a new row below the row which contain a button i clicked. It's work fine but the problem is when i click the "Detail" button, it the detail of all, i just want it to show the detail of which product i clicked.
Here is my HTML code:
var app = angular.module("dataApp", []);
app.controller("dataExcuteController", function ($scope, $window,$http) {
$http.get('http://localhost:8080/sachonline/public/administrator/theloai/dstheloai').then(function (response) {
$scope.theloai = response.data.message.ds_theloai;
$scope.isLoading = false;
});
$scope.detailtheloai = function (item) {
$scope.showdetail = true;
};
});
<body ng-app="dataApp" ng-controller="dataExcuteController">
<div class="container">
<table class="table table-bordered">
<thead class="text-center">
<th>STT</th>
<th>Tên thể loại</th>
<th>Trạng thái</th>
<th>
<span><i class="fa fa-cog text-muted"></i></span>
</th>
</thead>
<tbody ng-repeat="item in theloai">
<tr>
<td class="text-center">#{{ item.tl_ma }}</td>
<td>#{{ item.tl_ten }}</td>
<td class="text-center" ng-if="item.tl_trangThai==1">
<span><i class="fa fa-check-circle text-success"></i></span>
</td>
<td class="text-center" ng-if="item.tl_trangThai==0">
<span><i class="fa fa-times-circle text-danger"></i></span>
</td>
<td class="text-center">
<button type="button" class="btn btn-sm btn-warning text-white mr-3 pt-0 pl-2 pr-2" ng-click="detailtheloai(item)"><i class="fa fa-info-circle"></i></button>
<button type="button" class="btn btn-sm btn-success text-white mr-3 pt-0 pl-2 pr-2" data-toggle="modal" data-target="#editForm" ng-click="edittheloai($index)"><i class="fa fa-edit"></i></button>
<button type="button" class="btn btn-sm btn-danger text-white pt-0 pl-2 pr-2" ng-click="removetheloai($index)"><i class="fa fa-trash"></i></button>
</td>
</tr>
<tr ng-show="showdetail">
<td colspan="4">
<table class="table table-info table-bordered">
<tbody>
<tr>
<th class="text-right">Mã thể loại:</th>
<td>#{{ item.tl_ma }}</td>
</tr>
<tr>
<th class="text-right">Tên thể loại:</th>
<td>#{{ item.tl_ten }}</td>
</tr>
<tr>
<th class="text-right">Trạng thái:</th>
<td class="text-center" ng-if="item.tl_trangThai==1">
<span><i class="fa fa-check-circle text-success"></i></span>
</td>
<td class="text-center" ng-if="item.tl_trangThai==0">
<span><i class="fa fa-times-circle text-danger"></i></span>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
<script src="{!!asset('js/showlist.js')!!}"></script>
</body>
You need to store the show value for every item, therefore I propose you this changes:
js:
$scope.detailtheloai = function (item) {
item.showdetail = true;
};
html:
<tr ng-show="item.showdetail">

Angular-xeditable disable rendering the particular element to editable mode

Below is the sample Code availabe in the link I am trying to achieve my use case.
In this table, I will have one more column as first column which is an checkbox. On selecting the "Edit" button, only the selected checkbox rows from the table should show editable mode and other rows should display as static text. Is it possible to achieve it. Can anyone help me in this to meet my requirement.
<h4>Angular-xeditable Editable row (Bootstrap 3)</h4>
<div ng-app="app" ng-controller="Ctrl">
<table class="table table-bordered table-hover table-condensed">
<tr style="font-weight: bold">
<td style="width:35%">Name</td>
<td style="width:20%">Status</td>
<td style="width:20%">Group</td>
<td style="width:25%">Edit</td>
</tr>
<tr ng-repeat="user in users">
<td>
<!-- editable username (text with validation) -->
<span editable-text="user.name" e-name="name" e-form="rowform" e-ng-hide="true" onbeforesave="checkName($data, user.id)" e-required>
<span ng-hide="false">hello</span>
{{ user.name || 'empty' }}
</span>
</td>
<td>
<!-- editable status (select-local) -->
<span editable-select="user.status" e-name="status" e-form="rowform" e-ng-options="s.value as s.text for s in statuses">
{{ showStatus(user) }}
</span>
</td>
<td>
<!-- editable group (select-remote) -->
<span editable-select="user.group" e-name="group" onshow="loadGroups()" e-form="rowform" e-ng-options="g.id as g.text for g in groups">
{{ showGroup(user) }}
</span>
</td>
<td style="white-space: nowrap">
<!-- form -->
<form editable-form name="rowform" onbeforesave="saveUser($data, user.id)" ng-show="rowform.$visible" class="form-buttons form-inline" shown="inserted == user">
<button type="submit" ng-disabled="rowform.$waiting" class="btn btn-primary">
save
</button>
<button type="button" ng-disabled="rowform.$waiting" ng-click="rowform.$cancel()" class="btn btn-default">
cancel
</button>
</form>
<div class="buttons" ng-show="!rowform.$visible">
<button class="btn btn-primary" ng-click="rowform.$show()">edit</button>
<button class="btn btn-danger" ng-click="removeUser($index)">del</button>
</div>
</td>
</tr>
</table>
<button class="btn btn-default" ng-click="addUser()">Add row</button>
</div>

How to place uib-datepicker inside <select>

I use AngularJs and like to display <select> if dates are available, if not I like to put uib-datepicker inside <select>.
Let me explain again, if dates are available clicking <select> makes dates are coming out, if dates are not available, clicking <select> will make uib-datepicker display.
I have html code for multi-datepicker.tpl.html.
<div class="uib-datepicker" ng-switch="datepickerMode" role="application" ng-keydown="keydown($event)">
<uib-daypicker ng-switch-when="day" tabindex="0" template-url="app/travels/views/multi-day.tpl.html"></uib-daypicker>
<uib-monthpicker ng-switch-when="month" tabindex="0"></uib-monthpicker>
<uib-yearpicker ng-switch-when="year" tabindex="0"></uib-yearpicker>
</div>
For that what I did in my html code is
<div class="row travel-reviews">
<select ng-model="selectedSeats" ng-change="totalAmountCal()" ng-options="seat as seat.seat for seat in seats">
<option value="" selected disabled>Select no of seats </option>
</select>
<select ng-show="dateLength" ng-model="selectedDate" ng-options="date as date for date in selectedDates">
<option value="" selected disabled>Select date </option>
</select>
<select ng-show="!dateLength" >
<uib-datepicker ng-model='selectedDate' multi-select='selectedDates' template-url='app/travels/views/multi-datepicker.tpl.html'></uib-datepicker>
</select>
</div>
Now the problem are (1) datepicker is not in the select and (2) second one overwrite the first one.
How to solve the problem? When dates are available $scope.dateLength is true and not available $scope.dateLength is false.
EDIT:
<div class="row travel-reviews">
<select ng-model="selectedSeats" ng-change="totalAmountCal()" ng-options="seat as seat.seat for seat in seats">
<option value="" selected disabled>Select no of seats </option>
</select>
<select ng-show="dateLength" ng-model="selectedDate" ng-options="date as date for date in selectedDates">
<option value="" selected disabled>Select date </option>
</select>
<div ng-show="!dateLength">
<b style="font-size:15px; color:blue">Please select date</b>
<section>
<table>
<tr>
<td>
<uib-datepicker ng-model='selectedDate' multi-select='selectedDates' template-url='app/travels/views/multi-datepicker.tpl.html'></uib-datepicker>
</td>
<td style='width:10px'></td>
</tr>
</table>
</section>
</div>
</div>
multi-day.tpl.html
<table class="uib-daypicker" role="grid" aria-labelledby="{{::uniqueId}}-title" aria-activedescendant="{{activeDateId}}">
<thead>
<tr>
<th>
<button type="button" class="btn btn-default btn-sm pull-left uib-left" ng-click="move(-1)" tabindex="-1">
<i class="glyphicon glyphicon-chevron-left"></i>
</button>
</th>
<th colspan="{{::5 + showWeeks}}">
<button id="{{::uniqueId}}-title" role="heading" aria-live="assertive" aria-atomic="true" type="button" class="btn btn-default btn-sm uib-title" ng-click="toggleMode()" ng-disabled="datepickerMode === maxMode" tabindex="-1">
<strong>{{title}}</strong>
</button>
</th>
<th>
<button type="button" class="btn btn-default btn-sm pull-right uib-right" ng-click="move(1)" tabindex="-1"><i class="glyphicon glyphicon-chevron-right"></i></button>
</th>
</tr>
<tr>
<th ng-if="showWeeks" class="text-center"></th>
<th ng-repeat="label in ::labels track by $index" class="text-center">
<small aria-label="{{::label.full}}">{{::label.abbr}}</small>
</th>
</tr>
</thead>
<tbody>
<tr class="uib-weeks" ng-repeat="row in rows track by $index">
<td ng-if="showWeeks" class="text-center h6">
<em>{{ weekNumbers[$index] }}</em>
</td>
<td ng-repeat="dt in row" class="uib-day text-center" role="gridcell" id="{{::dt.uid}}" ng-class="::dt.customClass">
<button type="button" class="btn btn-default btn-sm" ng-class="{'btn-info': dt.selected, active: isActive(dt)}" ng-click="select(dt.date)" ng-disabled="::dt.disabled" tabindex="-1">
<span ng-class="::{'text-muted': dt.secondary, 'text-info': dt.current}">{{::dt.label}}</span>
</button>
</td>
</tr>
</tbody>
</table>

Datatables + angular.js + xeditable is not working

I am using angular with Datatables and I am trying to edit a row with Xeditable, my issue is that there are no xeditables elements, the span is not turning into editable span.
Here is my code:
<div class="dataTables_wrapper">
<table datatable="ng" class="table table-bordered table-hover dataTable" role="grid">
<thead>
<tr>
<th>{{texts.fullName}}</th>
<th>{{texts.title}}</th>
<th>{{texts.email}}</th>
<th>edit</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="contact in contacts track by $index">
<td>
{{contact.fullName}}
</td>
<td>
{{contact.title}}
</td>
<td>
<span editable-text="contact.email" e-name="email" e-form="rowform">
{{ contact.email || 'empty' }}
</span>
</td>
<td>
<!-- form -->
<form editable-form name="rowform" onbeforesave="saveUser($data, user.id)" ng-show="rowform.$visible" class="form-buttons form-inline">
<button type="submit" ng-disabled="rowform.$waiting" class="btn btn-primary">
save
</button>
<button type="button" ng-disabled="rowform.$waiting" ng-click="rowform.$cancel()" class="btn btn-default">
cancel
</button>
</form>
<div class="buttons" ng-show="!rowform.$visible">
<button class="btn btn-primary" ng-click="rowform.$show()">edit</button>
<button class="btn btn-danger" ng-click="removeUser($index)">del</button>
</div>
</td>
</tr>
</tbody>
</table>
</div>
I can see that the xeditable code can't find the $editables elements, I thought it is related to datatable because if I'm trying to use regular table it works well.
Any idea on how to fix it?
Best,
Omri
Your editable-text isn't in the editable-form, this might be the problem.
I think the following code would fix it.
<form editable-form name="rowform" onbeforesave="saveUser($data, user.id)" ng-show="rowform.$visible" class="form-buttons form-inline">
<span editable-text="contact.email" e-name="email" e-form="rowform">
{{ contact.email || 'empty' }
</span>
<button type="submit" ng-disabled="rowform.$waiting" class="btn btn-primary">
save
</button>
<button type="button" ng-disabled="rowform.$waiting" ng-click="rowform.$cancel()" class="btn btn-default">
cancel
</button>
</form>

How to enable only parent table raw items as editable?

When click on edit button (ng-click="editmode = !editmode") the entire table input showing. is there any solution to show that only show its <input type="text"> as editable ?
var app = angular.module('myapp', []);
app.controller('testController', function($scope) {
$scope.userdetails = {
"id": "1",
"user_id": "2",
"name": "Alycia",
"address": "510 Marks Parkway Suite 221\nLake Karelle, SC 01791",
"post": "Howellmouth",
"district": "Schaeferside",
"state": "New Mexico",
"pin": "61354-9529",
"phone": "(239)009-2861x858",
"mobile1": "+70(1)8058651903",
"mobile2": "+69(3)0049980344",
"file_id": "1",
"email1": "Diana11#Sipes.info",
"email2": "Dietrich.Georgianna#hotmail.com",
"created_at": "2015-08-04 11:41:56",
"updated_at": "2015-08-04 11:41:56"
};
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" />
<div ng-app="myapp" ng-controller="testController" class="container">
<table class="table table-hover table-responsive">
<tbody>
<tr>
<th>Name</th>
<td ng-if="!editmode">{{userdetails.name}}</td>
<td ng-if="editmode">
<input type="text" ng-model="userdetails.name">
</td>
<td>
<button class="btn btn-default btn-xs" ng-click="editmode = !editmode"><span class="glyphicon glyphicon-pencil"></span>
</button>
</td>
</tr>
<tr>
<th>Address</th>
<td ng-if="!editmode">{{userdetails.address}}</td>
<td ng-if="editmode">
<input type="text" ng-model="userdetails.address">
</td>
<td>
<button class="btn btn-default btn-xs" ng-click="editmode = !editmode"><span class="glyphicon glyphicon-pencil"></span>
</button>
</td>
</tr>
<tr>
<th>Post</th>
<td ng-if="!editmode">{{userdetails.post}}</td>
<td ng-if="editmode">
<input type="text" ng-model="userdetails.post">
</td>
<td>
<button class="btn btn-default btn-xs" ng-click="editmode = !editmode"><span class="glyphicon glyphicon-pencil"></span>
</button>
</td>
</tr>
<tr>
<th>District</th>
<td ng-if="!editmode">{{userdetails.district}}</td>
<td ng-if="editmode">
<input type="text" ng-model="userdetails.district">
</td>
<td>
<button class="btn btn-default btn-xs" ng-click="editmode = !editmode"><span class="glyphicon glyphicon-pencil"></span>
</button>
</td>
</tr>
<tr>
<th>State</th>
<td ng-if="!editmode">{{userdetails.state}}</td>
<td ng-if="editmode">
<input type="text" ng-model="userdetails.state">
</td>
<td>
<button class="btn btn-default btn-xs" ng-click="editmode = !editmode"><span class="glyphicon glyphicon-pencil"></span>
</button>
</td>
</tr>
<tr>
<th>Pin</th>
<td ng-if="!editmode">{{userdetails.pin}}</td>
<td ng-if="editmode">
<input type="text" ng-model="userdetails.pin">
</td>
<td>
<button class="btn btn-default btn-xs" ng-click="editmode = !editmode"><span class="glyphicon glyphicon-pencil"></span>
</button>
</td>
</tr>
<tr>
<th>Phone</th>
<td ng-if="!editmode">{{userdetails.phone}}</td>
<td ng-if="editmode">
<input type="text" ng-model="userdetails.phone">
</td>
<td>
<button class="btn btn-default btn-xs" ng-click="editmode = !editmode"><span class="glyphicon glyphicon-pencil"></span>
</button>
</td>
</tr>
<tr>
<th>Mobile 1</th>
<td ng-if="!editmode">{{userdetails.mobile1}}</td>
<td ng-if="editmode">
<input type="text" ng-model="userdetails.mobile1">
</td>
<td>
<button class="btn btn-default btn-xs" ng-click="editmode = !editmode"><span class="glyphicon glyphicon-pencil"></span>
</button>
</td>
</tr>
<tr>
<th>Mobile 2</th>
<td ng-if="!editmode">{{userdetails.mobile2}}</td>
<td ng-if="editmode">
<input type="text" ng-model="userdetails.mobile2">
</td>
<td>
<button class="btn btn-default btn-xs" ng-click="editmode = !editmode"><span class="glyphicon glyphicon-pencil"></span>
</button>
</td>
</tr>
</tbody>
</table>
</div>
You should just give a different name on each part instead of "editmode" on every input :
<tr>
<th>Name</th>
<td ng-if="!editName">{{userdetails.name}}</td>
<td ng-if="editName">
<input type="text" ng-model="userdetails.name">
</td>
<td>
<button class="btn btn-default btn-xs" ng-click="editName = !editName"><span class="glyphicon glyphicon-pencil"></span>
</button>
</td>
</tr>
<tr>
<th>Address</th>
<td ng-if="!editAdress">{{userdetails.address}}</td>
<td ng-if="editAdress">
<input type="text" ng-model="userdetails.address">
</td>
<td>
<button class="btn btn-default btn-xs" ng-click="editAdress = !editAdress"><span class="glyphicon glyphicon-pencil"></span>
</button>
</td>
</tr>
Hope it helped.
EDIT :
Here is an other proposition working in this plunker
If you manage a bit your $scope data you can have a lot less HTML to produce
The data would look like this :
$scope.userdetails = {
"id": {
value : "1",
label: "ID"
},
"user_id": {
value : "2",
label: "User Id"
},
"name": {
value : "Alycia",
label: "Name",
display: true
},
"address": {
value : "510 Marks Parkway Suite 221\nLake Karelle, SC 01791",
label: "Address",
display: true
},
"post": {
value : "Howellmouth",
label: "Post",
display: true
}
};
And the HTML Like this :
<table class="table table-hover table-responsive">
<tbody>
<tr ng-if="property.display" ng-repeat="property in userdetails">
<th>{{property.label}}</th>
<td ng-if="!property.editmode">{{property.value}}</td>
<td ng-if="property.editmode">
<input type="text" ng-model="property.value">
</td>
<td>
<button class="btn btn-default btn-xs" ng-click="property.editmode = !property.editmode"><span class="glyphicon glyphicon-pencil"></span>
</button>
</td>
</tr>
</table>

Resources