Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add delete buttons and set up two way binding for file list
  • Loading branch information
gashcrumb committed Jun 25, 2013
1 parent 7589670 commit 45e891b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 13 deletions.
4 changes: 2 additions & 2 deletions hawtio-web/src/main/webapp/app/ui/html/fileUpload.html
@@ -1,6 +1,6 @@
<div>
<div class="file-upload">
<ul>
<li ng-repeat="file in files">{{file.fileName}}</li>
<li ng-repeat="file in files">{{file.fileName}}<span class="clickable red"><i class="icon-remove" title="Delete {{file.filename}}" ng-click="delete(file.fileName)"></i></span></li>
</ul>
<form name="file-upload" action="upload" method="post" enctype="multipart/form-data">
<fieldset>
Expand Down
2 changes: 1 addition & 1 deletion hawtio-web/src/main/webapp/app/ui/html/test.html
Expand Up @@ -15,7 +15,7 @@
</div>

<div class="row-fluid">
<div hawtio-file-upload="test"></div>
<div hawtio-file-upload="files" target="test"></div>
</div>

</div>
Expand Down
42 changes: 32 additions & 10 deletions hawtio-web/src/main/webapp/app/ui/js/fileUpload.ts
Expand Up @@ -10,32 +10,54 @@ module UI {
public templateUrl = UI.templatePath + "fileUpload.html";

public scope = {
target: '@hawtioFilePlugin'
files: '=hawtioFileUpload',
target: '@'
};


public controller = ($scope, $element, $attrs, jolokia) => {

$scope.files = [];
$scope.target = '';

observe($scope, $attrs, 'target', '');

$scope.update = (response) => {
$scope.files = response.value;
$scope.$apply();
}

Core.register(jolokia, $scope, {
type: 'exec', mbean: fileUploadMBean,
operation: 'list(java.lang.String)',
arguments: [null]
}, onSuccess($scope.update));
$scope.delete = (fileName) => {
jolokia.request({
type: 'exec', mbean: fileUploadMBean,
operation: 'delete(java.lang.String, java.lang.String)',
arguments: [$scope.target, fileName],
success: () => {
$scope.$apply();
},
error: (response) => {
notification('error', "Failed to delete " + fileName + " due to: " + response.error);
$scope.$apply();
}
});
}


$scope.$watch('target', (newValue, oldValue) => {
if (oldValue !== newValue) {
Core.unregister(jolokia, $scope);
}
Core.register(jolokia, $scope, {
type: 'exec', mbean: fileUploadMBean,
operation: 'list(java.lang.String)',
arguments: [$scope.target]
}, onSuccess($scope.update));

});


$scope.onFileChange = () => {
console.log("File changed!");
var form:any = $('form[name=file-upload]');

form.ajaxSubmit({});

return false;
}

Expand Down
8 changes: 8 additions & 0 deletions hawtio-web/src/main/webapp/app/ui/js/testController.ts
Expand Up @@ -30,6 +30,14 @@ module UI {
$scope.myColor = "#FF887C";
$scope.showColorDialog = false;

$scope.files = [];

$scope.$watch('files', (newValue, oldValue) => {
if (newValue !== oldValue) {
console.log("Files: ", $scope.files);
}
}, true);


}

Expand Down

0 comments on commit 45e891b

Please sign in to comment.