Skip to content

Commit 9719d54

Browse files
Initial commit
0 parents  commit 9719d54

File tree

12 files changed

+596
-0
lines changed

12 files changed

+596
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
bower_components/
2+
node_modules/
3+
package-lock.json

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
= Linked Select with AngularJS Schema-form
2+
3+
A simple way to do linked selects.

app.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
angular.module('selectExample', ['schemaForm'])
2+
.controller('FormController', function($scope, $http, $q) {
3+
var selectLinkedChange = function(key, model) {
4+
$scope[model.childItem].splice(0);
5+
6+
var service = model.option.uri;
7+
8+
if (model.option.params == "contexto") {
9+
service = service + "/" + key;
10+
}
11+
12+
$http.get(service)
13+
.then(function(result) {
14+
result.data.forEach(function(item, index) {
15+
var map = model.option.map;
16+
if (model.option.params == "compare") {
17+
if (item[map.compareField] == key) {
18+
$scope[model.childItem].push({
19+
value: item[map.valueField],
20+
name: item[map.nameField]
21+
});
22+
}
23+
} else {
24+
$scope[model.childItem].push({
25+
value: item[map.valueField],
26+
name: item[map.nameField]
27+
});
28+
}
29+
});
30+
});
31+
};
32+
33+
$scope.addLogic = function(form) {
34+
var formObject = {};
35+
36+
if (typeof form == "string") {
37+
formObject = JSON.parse(form);
38+
} else {
39+
formObject = form;
40+
}
41+
42+
formObject.forEach(function(item, index) {
43+
if (item.type == "select") {
44+
if (item.selectLinked) {
45+
item.onChange = selectLinkedChange;
46+
}
47+
if (item.createTitleMap) {
48+
$scope[item.key] = [];
49+
item.titleMap = $scope[item.key];
50+
}
51+
}
52+
});
53+
54+
return formObject;
55+
}
56+
57+
$http.get('data/form.json').then(function(response) {
58+
$scope.schema = response.data.schema;
59+
$scope.form = $scope.addLogic(response.data.form);
60+
});
61+
62+
$scope.model = {};
63+
});

bower.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "test-linked-list",
3+
"description": "",
4+
"main": "index.js",
5+
"authors": [
6+
"Caio Medeiros Pinto <[email protected]>"
7+
],
8+
"license": "ISC",
9+
"homepage": "",
10+
"ignore": [
11+
"**/.*",
12+
"node_modules",
13+
"bower_components",
14+
"test",
15+
"tests"
16+
],
17+
"dependencies": {
18+
"angular-schema-form": "^0.8.13",
19+
"bootstrap": "^3.3.7"
20+
}
21+
}

data/comunas.json

Lines changed: 349 additions & 0 deletions
Large diffs are not rendered by default.

data/form.json

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"schema": {
3+
"type": "object",
4+
"properties": {
5+
"nombre": {
6+
"type": "string",
7+
"minLength": 6,
8+
"title": "Nombre",
9+
"description": "Nombre Completo del estudiante."
10+
},
11+
"pais": {
12+
"title": "Pais",
13+
"type": "string"
14+
},
15+
"region": {
16+
"title": "Region",
17+
"type": "number"
18+
},
19+
"comuna": {
20+
"title": "Comuna",
21+
"type": "number"
22+
},
23+
"calle": {
24+
"type": "string",
25+
"title": "Calle"
26+
}
27+
}
28+
},
29+
"form": [
30+
"nombre",
31+
{
32+
"key": "pais",
33+
"type": "select",
34+
"selectLinked": true,
35+
"option": {
36+
"uri": "data/regiones.json",
37+
"params": "compare",
38+
"map": {
39+
"valueField": "id",
40+
"nameField": "glosa",
41+
"compareField": "paiseId"
42+
}
43+
},
44+
"childItem": "region",
45+
"titleMap": [
46+
{ "value": "CL", "name": "Chile" }
47+
]
48+
},
49+
{
50+
"key": "region",
51+
"type": "select",
52+
"selectLinked": true,
53+
"option": {
54+
"uri": "data/comunas.json",
55+
"params": "compare",
56+
"map": {
57+
"valueField": "id",
58+
"nameField": "glosa",
59+
"compareField": "comunaId"
60+
}
61+
},
62+
"childItem": "comuna",
63+
"createTitleMap": true,
64+
"titleMap": []
65+
},
66+
{
67+
"key": "comuna",
68+
"type": "select",
69+
"createTitleMap": true,
70+
"titleMap": []
71+
},
72+
{
73+
"type": "submit",
74+
"title": "Enviar"
75+
}
76+
]
77+
}

data/regiones.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[
2+
{ "id": 1, "glosa": "I - Región de Tarapacá", "paiseId": "CL", "estatus": "ACTIVO" },
3+
{ "id": 2, "glosa": "II- Región de Antofagasta", "paiseId": "CL", "estatus": "ACTIVO" },
4+
{ "id": 3, "glosa": "III - Región de Atacama", "paiseId": "CL", "estatus": "ACTIVO" },
5+
{ "id": 4, "glosa": "IV - Región de Coquimbo", "paiseId": "CL", "estatus": "ACTIVO" },
6+
{ "id": 5, "glosa": "V - Región de Valparaíso", "paiseId": "CL", "estatus": "ACTIVO" },
7+
{ "id": 6, "glosa": "VI - Región del Libertador Gral.Bdo.O’Higgins", "paiseId": "CL", "estatus": "ACTIVO" },
8+
{ "id": 7, "glosa": "VII - Región del Maule", "paiseId": "CL", "estatus": "ACTIVO" },
9+
{ "id": 8, "glosa": "VIII - Región del Bío-Bío", "paiseId": "CL", "estatus": "ACTIVO" },
10+
{ "id": 9, "glosa": "IX - Región de La Araucanía", "paiseId": "CL", "estatus": "ACTIVO" },
11+
{ "id": 10, "glosa": "X - Región de Los Lagos", "paiseId": "CL", "estatus": "ACTIVO" },
12+
{ "id": 11, "glosa": "XI - Región de Aisén del General C. Ibañez", "paiseId": "CL", "estatus": "ACTIVO" },
13+
{ "id": 12, "glosa": "XII -Región de Magallanes y Antártica Chilena", "paiseId": "CL", "estatus": "ACTIVO" },
14+
{ "id": 13, "glosa": "Región Metropolitana", "paiseId": "CL", "estatus": "ACTIVO" },
15+
{ "id": 14, "glosa": "XIV - Región de los Rios", "paiseId": "CL", "estatus": "ACTIVO" },
16+
{ "id": 15, "glosa": "XV - Región de Arica y Parinacota", "paiseId": "CL", "estatus": "ACTIVO" }
17+
]

gulp/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
var fs = require('fs'),
2+
tasks = fs.readdirSync('./gulp/tasks'),
3+
gulp = require('gulp');
4+
5+
tasks.forEach(function(task) {
6+
require('./tasks/' + task);
7+
});

gulp/tasks/serve.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
var gulp = require('gulp'),
2+
webserver = require('gulp-webserver');
3+
4+
gulp.task('serve', function() {
5+
gulp.src('.')
6+
.pipe(webserver({
7+
livereload: true,
8+
directoryListing: true,
9+
open: true
10+
}));
11+
});

gulpfile.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
//all of the tasks themselves are contained in the gulp/tasks directory,
3+
//which is accessed through gulp/index.js
4+
5+
require('./gulp');

0 commit comments

Comments
 (0)