Skip to content

Commit a65e549

Browse files
committed
fix(datePicker): fixed maxView & minView
1 parent 3b6d965 commit a65e549

File tree

2 files changed

+87
-45
lines changed

2 files changed

+87
-45
lines changed

app/index.html

Lines changed: 81 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,62 +16,107 @@
1616
<div class="span6">
1717
<h2>Calendar</h2>
1818

19-
<h3>views</h3>
20-
<h5>default</h5>
21-
<pre>&lt;div date-picker="start"&gt;&lt;/div&gt; </pre>
22-
23-
<div date-picker="start" max-view="date" min-view="date"></div>
24-
25-
<h5>year</h5>
26-
<pre>&lt;div date-picker="start" <strong>year</strong>&gt;&lt;/div&gt; </pre>
27-
<div date-picker="start" view="year"></div>
28-
<h5>month</h5>
29-
<pre>&lt;div date-picker="start <strong>month</strong>&gt;&lt;/div&gt; </pre>
30-
<div date-picker="start" view="month"></div>
31-
<h5>date</h5>
32-
<pre>&lt;div date-picker="start" <strong>date</strong>&gt;&lt;/div&gt; </pre>
33-
<div date-picker="start" view="date"></div>
34-
<h5>hours</h5>
35-
<pre>&lt;div date-picker="start" <strong>hours</strong>&gt;&lt;/div&gt; </pre>
36-
<div date-picker="start" view="hours"></div>
37-
<h5>minutes</h5>
38-
<pre>&lt;div date-picker="start" <strong>minutes</strong>&gt;&lt;/div&gt; </pre>
39-
<div date-picker="start" view="minutes"></div>
19+
<div>
20+
<h3>default views</h3>
21+
22+
<h5>year</h5>
23+
<div date-picker="start" view="year"></div>
24+
25+
<h5>month</h5>
26+
<div date-picker="start" view="month"></div>
27+
28+
<h5>date</h5>
29+
<div date-picker="start" view="date"></div>
30+
31+
<h5>hours</h5>
32+
<div date-picker="start" view="hours"></div>
33+
34+
<h5>minutes</h5>
35+
<div date-picker="start" view="minutes"></div>
36+
</div>
37+
38+
39+
40+
<div>
41+
<h3>min views</h3>
42+
43+
<h5>year</h5>
44+
<div date-picker="start" min-view="year"></div>
45+
46+
<h5>month</h5>
47+
<div date-picker="start" min-view="month"></div>
48+
49+
<h5>date</h5>
50+
<div date-picker="start" min-view="date"></div>
51+
52+
<h5>hours</h5>
53+
<div date-picker="start" min-view="hours"></div>
54+
55+
<h5>minutes</h5>
56+
<div date-picker="start" min-view="minutes"></div>
57+
</div>
58+
59+
60+
<div>
61+
<h3>max views</h3>
62+
63+
<h5>year</h5>
64+
<div date-picker="start" max-view="year"></div>
65+
66+
<h5>month</h5>
67+
<div date-picker="start" max-view="month"></div>
68+
69+
<h5>date</h5>
70+
<div date-picker="start" max-view="date"></div>
71+
72+
<h5>hours</h5>
73+
<div date-picker="start" max-view="hours"></div>
74+
75+
<h5>maxutes</h5>
76+
<div date-picker="start" max-view="minutes"></div>
77+
</div>
78+
79+
<div>
80+
<h3>max & min views</h3>
81+
82+
<h5>time</h5>
83+
<div date-picker="start" max-view="hours" min-view="minutes"></div>
84+
85+
<h5>date</h5>
86+
<div date-picker="start" max-view="year" min-view="date"></div>
87+
88+
</div>
89+
90+
4091
</div>
92+
93+
4194
<div class="span6">
4295
<h3>Input</h3>
4396
<h5>default</h5>
4497
<pre></pre>
45-
<input type="text" date-time ng-model="start" required="true" view="hours" position="absolute">
98+
<input type="text" date-time ng-model="start" required="true" view="hours" position="absolute">
4699

47100
<h3>Input with append</h3>
48101
<h5>default</h5>
49-
<pre>&lt;input type="datetime" <strong>ng-model="model" date-time</strong>&gt;&lt;/div&gt; </pre>
102+
50103
<div class="input-append input-prepend" date-time-append>
51104
<span class="add-on"><i class="icon-calendar"></i></span>
52105
<input type="text" date-time ng-model="start" required="true" view="hours">
53106
<span class="add-on"><i class="icon-calendar"></i></span>
54107
</div>
55108
<h3>Input with prepend</h3>
56109
<h5>default</h5>
57-
<pre>&lt;input type="datetime" <strong>ng-model="model" date-time</strong>&gt;&lt;/div&gt; </pre>
110+
58111
<div class="input-prepend" date-time-append>
59112
<span class="add-on"><i class="icon-calendar"></i></span>
60113
<input type="text" date-time ng-model="start" required="true" view="hours" position="absolute">
61114
</div>
62115

63116
<h5>Input format</h5>
64-
<pre>&lt;input type="datetime" ng-model="model" date-time <strong>format="long"</strong>&gt;&lt;/div&gt; </pre>
65117
<!--<input type="datetime" date-time ng-model="end" hours format="short">-->
66118
<h5>A button</h5>
67-
<pre ng-non-bindable>&lt;div class=&quot;dropdown&quot;&gt;
68-
&lt;a class=&quot;dropdown-toggle btn btn-danger&quot;&gt;
69-
pick a date: {{(date|date)}}
70-
&lt;/a&gt;
71-
&lt;div class=&quot;dropdown-menu&quot; ng-click=&quot;$event.preventDefault();$event.stopPropagation()&quot;&gt;
72-
&lt;div date-picker=&quot;date&quot; class=&quot;datetimepicker&quot;&gt;&lt;/div&gt;
73-
&lt;/div&gt;
74-
&lt;/div&gt;</pre>
119+
75120
<div class="dropdown">
76121
<a class="dropdown-toggle btn btn-danger">
77122
pick a date: {{(date|date)}}
@@ -81,6 +126,9 @@ <h5>A button</h5>
81126
<div date-picker="date"></div>
82127
</div>
83128
</div>
129+
130+
131+
84132
<h5>Date range</h5>
85133
<pre>&lt;div date-range start="start" end="end" &gt;&lt;/div&gt; </pre>
86134
<div date-range start="a" end="b" style="position: relative; z-index:0"></div>

app/scripts/datePicker.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -116,20 +116,14 @@ Module.directive('datePicker', function datePickerDirective(datePickerConfig) {
116116
scope.template = attrs.template || datePickerConfig.template;
117117

118118
var step = parseInt(attrs.step || datePickerConfig.step, 10);
119-
var index;
120119

121-
/** @namespace attrs.minView */
122-
if (attrs.minView) {
123-
index = scope.views.indexOf(attrs.minView);
124-
scope.views.splice(0, index);
125-
}
126-
/** @namespace attrs.maxView */
127-
if (attrs.maxView) {
128-
index = scope.views.indexOf(attrs.maxView);
129-
scope.views.splice(index + 1);
130-
}
120+
/** @namespace attrs.minView, attrs.maxView */
121+
scope.views =scope.views.slice(
122+
scope.views.indexOf(attrs.maxView || 'year'),
123+
scope.views.indexOf(attrs.minView || 'minutes')+1
124+
);
131125

132-
if (scope.views.length === 1) {
126+
if (scope.views.length === 1 || scope.views.indexOf(scope.view)==-1) {
133127
scope.view = scope.views[0];
134128
}
135129

0 commit comments

Comments
 (0)