From b88d204fef9df5e9d0bd784c6b7b5f9910bb4334 Mon Sep 17 00:00:00 2001 From: Jakub Redlarski Date: Wed, 27 Jul 2016 15:58:29 +0200 Subject: [PATCH] Added motech-file-upload directive --- bower.json | 9 ++++- .../motech-file-upload.directive.js | 34 +++++++++++++++++++ .../motech-file-upload.html | 10 ++++++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 src/common/motech-file-upload/motech-file-upload.directive.js create mode 100644 src/common/motech-file-upload/motech-file-upload.html diff --git a/bower.json b/bower.json index 6cc9c82..c4e49b0 100644 --- a/bower.json +++ b/bower.json @@ -40,7 +40,8 @@ "angular-breadcrumb": "^0.4.1", "jquery-timepicker-addon": "^1.3.1", "jquery-ui": "^1.11.4", - "messageformat": "^0.3.1" + "messageformat": "^0.3.1", + "jasny-bootstrap": "git://github.com/jasny/bootstrap" }, "overrides": { "angular-bootstrap": { @@ -84,6 +85,12 @@ "main": [ "./messageformat.js" ] + }, + "jasny-bootstrap": { + "main": [ + "./dist/css/jasny-bootstrap.css", + "./js/fileinput.js" + ] } }, "resolutions": { diff --git a/src/common/motech-file-upload/motech-file-upload.directive.js b/src/common/motech-file-upload/motech-file-upload.directive.js new file mode 100644 index 0000000..554b401 --- /dev/null +++ b/src/common/motech-file-upload/motech-file-upload.directive.js @@ -0,0 +1,34 @@ +(function () { + 'use strict'; + + angular.module('motech-common') + .directive('motechFileUpload', ['$compile', '$timeout', '$http', '$templateCache', motechFileUploadDirective]); + + function motechFileUploadDirective($compile, $timeout, $http, $templateCache) { + var templateLoader; + + return { + restrict: 'E', + replace : true, + transclude: false, + compile: function (tElement, tAttrs, scope) { + var url = '../server/resources/partials/motech-file-upload.html', + + templateLoader = $http.get(url, {cache: $templateCache}) + .success(function (html) { + tElement.html(html); + }); + + return function (scope, element, attrs) { + templateLoader.then(function () { + var $input = element.find("#fileInput"); + if (attrs.accept) { + $input.attr('accept', attrs.accept); + } + element.html($compile(tElement.html())(scope)); + }); + }; + } + }; + } +})(); \ No newline at end of file diff --git a/src/common/motech-file-upload/motech-file-upload.html b/src/common/motech-file-upload/motech-file-upload.html new file mode 100644 index 0000000..6e3e7c0 --- /dev/null +++ b/src/common/motech-file-upload/motech-file-upload.html @@ -0,0 +1,10 @@ +
+   + +
+ + {{'server.button.selectFile' | translate}} + {{'server.button.changeFile' | translate}} + + + \ No newline at end of file