Skip to content

Commit

Permalink
Fix file field
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromemacias committed Aug 25, 2015
1 parent abf03ef commit f6e6fe6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
24 changes: 12 additions & 12 deletions doc/Configuration-reference.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Configuration API Reference

In ng-admin, you define all the components of an admin application using the configuration API.
In ng-admin, you define all the components of an admin application using the configuration API.

* [NgAdminConfigurationProvider / nga](#ngadminconfigurationprovider--nga)
* [Application Configuration](#application-configuration)
Expand Down Expand Up @@ -176,12 +176,12 @@ Defines the name of the entity, as displayed on screen
A read-only entity doesn't allow access to the mutation views (editionView, creationView, deletionView). In addition, all links to the editionView are replaced by links to the showView.

var tag = nga.entity('tags').readOnly();

* `baseApiUrl()`
Defines the base API endpoint for all views of this entity

var comment = nga.entity('comments').baseApiUrl('http://localhost:3001/');

* `url()`
Defines the API endpoint for all views of this entity. It can be a string or a function.

Expand Down Expand Up @@ -342,7 +342,7 @@ Set the fields for the CSV export function. By default, ng-admin uses the fields

## Fields Configuration

A field is the representation of a property of an entity.
A field is the representation of a property of an entity.

* [General Field Settings](#general-field-settings)
* `string` Field Type
Expand Down Expand Up @@ -453,7 +453,7 @@ Whether the field should always appear. Used in filters (see listView Settings).
### `wysiwyg` Field Type

* `stripTags(boolean)`
Enable removal of all HTML tags - only the text is kept. Useful for displaying rich text in a table, or before truncation. False by default.
Enable removal of all HTML tags - only the text is kept. Useful for displaying rich text in a table, or before truncation. False by default.

* `sanitize(boolean)`
Enable HTML sanitization of WYSIWYG Editor value (removal of script tags, etc). True by default.
Expand Down Expand Up @@ -483,7 +483,7 @@ Format for number to string conversion. Based on [Numeral.js](http://numeraljs.c
### `choice` and `choices` Field Types

* `choices(array|function)`
Define array of choices for `choice` type.
Define array of choices for `choice` type.

When given an array, each choice must be an object litteral with both a value and a label.

Expand Down Expand Up @@ -521,9 +521,9 @@ Define array of choices for `choice` type.
Give upload information for `file` field type
- `url`: url for server side upload
- `accept`: values allowed by the standard HTML file input accept attribute
- `apifilename`: filename assigned by the server and returned by your API.
If the uploaded file is renamed server-side, you can get the new filename from an api return.
- `apifilename`: filename assigned by the server and returned by your API.

If the uploaded file is renamed server-side, you can get the new filename from an api return.

HTTP/1.1 200 OK
Content-Type: application/json
Expand All @@ -533,7 +533,7 @@ you can configure file field as :

nga.field('picture', 'file').uploadInformation({ 'url': 'your_url', 'apifilename': 'picture_name' })

Some other properties are allowed, see https://github.com/danialfarid/angular-file-upload#upload-service for the complete list.
Some other properties are allowed, see https://github.com/danialfarid/ng-file-upload#upload-service for the complete list.

### `reference` Field Type

Expand All @@ -552,7 +552,7 @@ Define the target field name used to retrieve the label of the referenced elemen
.targetEntity(post) // Select a target Entity
.targetField(nga.field('title')) // Select a label Field
]);

* `singleApiCall(function(entityIds) {}`
Define a function that returns parameters for filtering API calls. You can use it if you API support filter for multiple values.

Expand Down Expand Up @@ -669,7 +669,7 @@ Define the field name used to link the referenced entity.
.targetEntity(tag) // Targeted entity
.targetField(nga.field('name')) // Label Field to display in the list
])

* `singleApiCall(function(entityIds) {}`
Define a function that returns parameters for filtering API calls. You can use it if you API support filter for multiple values.

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"mocha": "^2.1.0",
"ng-annotate-loader": "0.0.2",
"ng-annotate-webpack-plugin": "^0.1.2",
"ng-file-upload": "^5.0.3",
"ng-file-upload": "^7.0.12",
"nginflection": "^1.1.10",
"ngtemplate-loader": "^1.3.0",
"node-libs-browser": "^0.5.0",
Expand Down
15 changes: 7 additions & 8 deletions src/javascripts/ng-admin/Crud/field/maFileField.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ define(function (require) {
*
* @example <ma-file-field field="field"></ma-file-field>
*/
function maFileField(Upload, $timeout) {
function maFileField(Upload) {
return {
scope: {
'field': '&',
Expand All @@ -23,9 +23,9 @@ define(function (require) {
}

scope.multiple = uploadInformation.hasOwnProperty('multiple') ? uploadInformation.multiple : false;
scope.accept = "'*'";
scope.accept = "*";
if (uploadInformation.hasOwnProperty('accept')) {
scope.accept = typeof uploadInformation.accept === 'function' ? uploadInformation.accept : "'" + uploadInformation.accept + "'";
scope.accept = uploadInformation.accept;
}
scope.apifilename = uploadInformation.hasOwnProperty('apifilename') ? uploadInformation.apifilename : false;

Expand All @@ -52,6 +52,7 @@ define(function (require) {
}

scope.fileSelected = function(selectedFiles) {
console.log(selectedFiles);
if (!selectedFiles || !selectedFiles.length) {
return;
}
Expand Down Expand Up @@ -93,9 +94,7 @@ define(function (require) {
};

scope.selectFile = function () {
$timeout(function() {
input.click();
}, 0);
input.click();
};
}
},
Expand All @@ -119,12 +118,12 @@ define(function (require) {
'</div>' +
'</div>' +
'</div>' +
'<input type="file" ngf-multiple="multiple" ngf-accept="{{ accept }}" ngf-select ngf-change="fileSelected($files)"' +
'<input type="file" ngf-multiple="multiple" accept="{{ accept }}" ngf-select="fileSelected($files)"' +
'id="{{ name }}" name="{{ name }}" ng-required="v.required" style="display:none" />'
};
}

maFileField.$inject = ['Upload', '$timeout'];
maFileField.$inject = ['Upload'];

return maFileField;
});

0 comments on commit f6e6fe6

Please sign in to comment.