Skip to content

Commit

Permalink
Merge pull request #86 from matteocng/85-feat-primitive-field-link
Browse files Browse the repository at this point in the history
#85: Primitive Field Type Fields.link(name)
  • Loading branch information
paveltiunov committed Jan 7, 2016
2 parents 498bc6a + b6493ef commit ca133f2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/configuring.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ Primitive fields types are:
* `Fields.checkbox(name)`
* `Fields.attachment(name)`
* `Fields.password(name)`
* `Fields.link(name)`

`Fields.text(name)` is used to define text fields.
If you want to define text field `foo` with 'Foo' label you could write:
Expand Down
12 changes: 12 additions & 0 deletions public/assets/js/allcount.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,18 @@ allcountModule.config(["fieldRenderingServiceProvider", function (fieldRendering
});
scope.provider = fieldDescription.fieldType.provider;
return $compile('<div lc-upload="fieldValue" provider="{{provider}}"></div>')(scope);
}],
link: [function (value, fieldDescription) {
var link = $('<a target="_blank"></a>');
link.attr('href', value);
link.text(value);
return link;
}, function (fieldDescription, controller, updateValue, clone, scope) {
scope.linkValue = controller.$viewValue;
scope.$watch('linkValue', function (linkValue) {
controller.$setViewValue(linkValue ? linkValue : undefined);
});
return $compile('<input type="url" ng-model="linkValue" class="form-control">')(scope);
}]
}
}]);
Expand Down
9 changes: 9 additions & 0 deletions services/js/Fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ exports.cloudinaryImage = function (name) {
});
};

exports.link = function (name) {
return new Field({
name: name,
fieldType: {
id: 'link'
}
})
};

function Field(config) {
_.extend(this, config);
}
Expand Down
3 changes: 2 additions & 1 deletion test-fixtures/crud-field-types/crud-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ A.app({
integer: Fields.integer("Integer"),
checkbox: Fields.checkbox("Checkbox"),
checkboxArrayField: Fields.checkbox("Checkbox Array", 'checkboxArray'),
password: Fields.password("Password")
password: Fields.password("Password"),
link: Fields.link("Link")
}
},
Bar: {
Expand Down
3 changes: 2 additions & 1 deletion test/crud-integration-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ exports.crudFieldTest = function (test) {
integer: 123456789,
checkbox: true,
checkboxArrayField: true,
password: '123'
password: '123',
link: 'http://www.example.com'
};
return crud.createEntity(_.clone(entityToCreate)).then(function (id) {
return crud.readEntity(id).then(function (entity) {
Expand Down

0 comments on commit ca133f2

Please sign in to comment.