Skip to content

Commit 21dc137

Browse files
authored
Merge pull request #75 from jlblcc/enhancement-ember-power-select
Replace select2 ans BS tooltips, fix citation, upgrade docs
2 parents 78ccd82 + ba360e9 commit 21dc137

File tree

55 files changed

+972
-601
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+972
-601
lines changed

app/app.js

+25
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/**
2+
* The mdEditor application instance.
3+
*
4+
* @module mdeditor
5+
* @category docs
6+
*/
7+
18
import Ember from 'ember';
29
import Resolver from './resolver';
310
import loadInitializers from 'ember-load-initializers';
@@ -25,3 +32,21 @@ Ember.Route.reopen({
2532
});
2633

2734
export default App;
35+
36+
/**
37+
* Components used to create objects or arrays of objects.
38+
*
39+
* @module mdeditor
40+
* @submodule components-object
41+
* @main components-object
42+
* @category docs
43+
*/
44+
45+
/**
46+
* Components used to input scalar or arrays of scalar values.
47+
*
48+
* @module mdeditor
49+
* @submodule components-input
50+
* @main components-input
51+
* @category docs
52+
*/

app/pods/components/input/md-boolean/component.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1+
/**
2+
* @module mdeditor
3+
* @submodule components-input
4+
*/
5+
16
import Ember from 'ember';
27

38
export default Ember.Component.extend({
4-
9+
510
/**
611
* Input, edit, display a boolean value
712
*
813
* @class md-boolean
914
* @constructor
1015
*/
11-
16+
1217
/**
1318
* Value of the input.
1419
* The edited value is returned
@@ -34,5 +39,5 @@ export default Ember.Component.extend({
3439
* @default null
3540
*/
3641
label: null
37-
42+
3843
});
Original file line numberDiff line numberDiff line change
@@ -1,158 +1,144 @@
1+
/**
2+
* @module mdeditor
3+
* @submodule components-input
4+
*/
5+
16
import Ember from 'ember';
27
import MdCodelist from '../md-codelist/component';
38

49
export default MdCodelist.extend({
5-
10+
classNames: ['md-codelist-multi'],
611
/**
712
* Specialized select list control for displaying and selecting
813
* options in mdCodes codelists.
914
* Extends md-codelist.
10-
* Allows selection of multiple options.
15+
* Allows selection of multiple options.
1116
*
1217
* @class md-codelist-multi
1318
* @constructor
19+
* @extends md-codelist
1420
*/
15-
21+
1622
/**
17-
* Initial value, returned value.
18-
* Accepts either an Array of strings or JSON formatted array
19-
* of strings. Example: '["foo","bar"]'
23+
* Initial value, returned value.
24+
* Accepts an Array of strings.
25+
*
26+
* Example: `["foo","bar"]`
2027
*
2128
* @property value
2229
* @type Array
2330
* @return Array
2431
* @required
2532
*/
26-
27-
/**
28-
* Indicates whether to allow the user to enter a new option
29-
* not contained in the select list.
30-
*
31-
* @property create
32-
* @type Boolean
33-
* @default false
34-
*/
35-
36-
/**
37-
* Indicates if tooltips should be rendered for the options.
38-
*
39-
* @property tooltip
40-
* @type Boolean
41-
* @default false
42-
*/
43-
33+
4434
/**
45-
* Indicates if icons should be rendered.
35+
* The multiple property for power-select-with-create
4636
*
47-
* @property icon
37+
* @property multiple
38+
* @private
4839
* @type Boolean
49-
* @default false
40+
* @default true
5041
*/
51-
42+
multiple: true,
43+
5244
/**
53-
* Whether to render a button to clear the selection.
45+
* The component to render
5446
*
55-
* @property allowClear
56-
* @type Boolean
57-
* @default false
47+
* @property theComponent
48+
* @type Ember.computed
49+
* @return String
5850
*/
59-
51+
theComponent: Ember.computed('create', function () {
52+
return this.get('create') ? 'power-select-with-create' :
53+
'power-select-multiple';
54+
}),
55+
6056
/**
6157
* Whether to close the selection list after a selection has been made.
6258
*
6359
* @property closeOnSelect
6460
* @type Boolean
65-
* @default true
61+
* @default false
6662
*/
67-
63+
closeOnSelect: false,
64+
6865
/**
6966
* The string to display when no option is selected.
7067
*
7168
* @property placeholder
7269
* @type String
73-
* @default 'Select one option'
70+
* @default 'Select one or more options'
7471
*/
75-
76-
/**
77-
* Form label for select list
78-
*
79-
* @property label
80-
* @type String
81-
* @default null
82-
*/
83-
72+
placeholder: 'Select one or more options',
73+
8474
/**
85-
* Form field width
75+
* The currently selected item in the codelist
8676
*
87-
* @property width
88-
* @type String
89-
* @default 100%
77+
* @property selectedItem
78+
* @type Ember.computed
79+
* @return PromiseObject
9080
*/
91-
81+
selectedItem: Ember.computed('value', function () {
82+
let value = this.get('value');
83+
let codelist = this.get('codelist');
84+
85+
if(value) {
86+
return codelist.filter((item) => {
87+
return value.includes(item['codeName']);
88+
});
89+
}
90+
return null;
91+
}),
92+
9293
/**
93-
* Indicates if input is disabled
94+
* If a value is provided by the user which is not in the codelist and 'create=true'
95+
* the new value will be added into the codelist array
9496
*
95-
* @property disabled
96-
* @type Boolean
97-
* @default false
98-
*/
99-
100-
/*
101-
* codelist is an array of code objects in mdCodelist format
102-
* the initial codelist for 'mdCodeName' is provided by the 'codelist' service;
103-
* if a value is provided by the user which is not in the codelist and 'create=true'
104-
* the new value will be added into the codelist array;
105-
* then a Boolean 'selected' element will be added to each codelist object where the
106-
* selected option will be set to true and all others false.
97+
* @property codelist
98+
* @type Ember.computed
99+
* @return Array
107100
*/
108-
codelist: Ember.computed(function() {
109-
let codelist = [];
110-
let codelistName = this.get('mdCodeName');
111-
let mdCodelist = this.get('mdCodes')
112-
.get(codelistName)
113-
.codelist
114-
.sortBy('codeName');
115-
mdCodelist.forEach(function(item) {
116-
let newObject = {
117-
code: item['code'],
118-
codeName: item['codeName'],
119-
description: item['description'],
120-
selected: false
121-
};
122-
codelist.pushObject(newObject);
123-
});
124-
125-
let val = this.get('value');
126-
let selectedItems = typeof val === 'string' ? JSON.parse(val) : val;
101+
codelist: Ember.computed('value', function () {
102+
let codelist = this.get('mapped');
103+
let value = this.get('value');
127104
let create = this.get('create');
128-
if(selectedItems) {
105+
106+
if(value) {
129107
if(create) {
130-
selectedItems.forEach(function(selectedItem) {
131-
let mdIndex = -1;
132-
codelist.forEach(function(codeObject, cIndex) {
133-
if(selectedItem === codeObject['codeName']) {
134-
mdIndex = cIndex;
135-
}
136-
});
137-
if(mdIndex === -1) {
138-
let newObject = {
139-
code: Math.floor(Math.random() * 100000) + 1,
140-
codeName: selectedItem,
141-
description: 'Undefined',
142-
selected: false
143-
};
108+
value.forEach((val) => {
109+
let found = codelist.findBy('codeName', val);
110+
if(found === undefined) {
111+
let newObject = this.createCode(val);
144112
codelist.pushObject(newObject);
145113
}
146114
});
147115
}
148-
codelist.forEach(function(item) {
149-
let mdIndex = selectedItems.indexOf(item['codeName']);
150-
if(mdIndex > -1) {
151-
item['selected'] = true;
152-
}
153-
});
154116
}
155117

156118
return codelist;
157-
})
119+
}),
120+
121+
/**
122+
* Set the value on the select.
123+
*
124+
* @method setValue
125+
* @param {Array|Object} selected The value to set. Generally, an array of
126+
* selected objects, unless using the create option.
127+
*/
128+
setValue(selected) {
129+
let sel;
130+
131+
//power-select-with-create always sends a single object oncreate
132+
//we need to add that object to the selectedItem array
133+
if(this.get('create') && !Ember.isArray(selected)) {
134+
sel = this.get('selectedItem')
135+
.compact();
136+
sel.pushObject(selected);
137+
} else {
138+
sel = selected;
139+
}
140+
141+
this.set('value', sel.mapBy('codeName'));
142+
this.change();
143+
}
158144
});

app/pods/components/input/md-codelist-multi/template.hbs

-13
This file was deleted.

0 commit comments

Comments
 (0)