From 8e33e74152de181e6dd4477755c0dd6e975b05b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Maur=C3=ADcio?= Date: Mon, 28 Apr 2014 23:59:34 +0000 Subject: [PATCH] git-svn-id: https://svn.coded.pt/svn/SIPRP@1870 bb69d46d-e84e-40c8-a05a-06db0d633741 --- .../static/html/app/Form1/Form1Controller.js | 9 +- .../static/html/app/Form1/Form1View.html | 70 ++++---- .../html/app/SearchForm/SearchController.js | 12 ++ .../html/app/directives/ModalWindow.html | 25 +++ .../static/html/app/directives/modalWindow.js | 150 ++++++++++++++++++ .../html/app/directives/pagingToolbar.js | 126 +++++++++++++++ .../static/html/app/filters/stringFormat.js | 84 ++++++++++ .../WebContent/static/html/index.html | 1 - .../WebContent/static/html/views-all.html | 2 +- 9 files changed, 444 insertions(+), 35 deletions(-) create mode 100644 trunk/SiprpWebFichasClinicas/WebContent/static/html/app/directives/ModalWindow.html create mode 100644 trunk/SiprpWebFichasClinicas/WebContent/static/html/app/directives/modalWindow.js create mode 100644 trunk/SiprpWebFichasClinicas/WebContent/static/html/app/directives/pagingToolbar.js create mode 100644 trunk/SiprpWebFichasClinicas/WebContent/static/html/app/filters/stringFormat.js diff --git a/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/Form1/Form1Controller.js b/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/Form1/Form1Controller.js index d2cee1ae..8360a6ec 100644 --- a/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/Form1/Form1Controller.js +++ b/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/Form1/Form1Controller.js @@ -109,7 +109,13 @@ } }; - $scope.gridAddItem = function(item, array){ + $scope.gridAddItem = function(item, array, arrayName){ + + if(!angular.isArray(array)) + { + $scope.editing[arrayName] = new Array(); + array = $scope.editing[arrayName]; + } array.push(item); }; @@ -158,5 +164,6 @@ $scope.$on('afterrender', function(event, args){ + }); }); \ No newline at end of file diff --git a/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/Form1/Form1View.html b/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/Form1/Form1View.html index 15d486aa..78ba418f 100644 --- a/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/Form1/Form1View.html +++ b/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/Form1/Form1View.html @@ -593,7 +593,7 @@
- +
@@ -612,7 +612,7 @@ - + @@ -760,23 +760,23 @@ - + - + - + - + - + + - + - + - + - + + + + + diff --git a/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/directives/modalWindow.js b/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/directives/modalWindow.js new file mode 100644 index 00000000..666d294e --- /dev/null +++ b/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/directives/modalWindow.js @@ -0,0 +1,150 @@ + +//https://github.com/jschr/bootstrap-modal + +evoapp.directive('modalWindow', function($rootScope) { + + var modalWindowEl = $rootScope.viewCache.find('#genericModalWindow'), + template = modalWindowEl[0].outerHTML; + + return { + require: '^ngController', + restrict: 'AE', + template: template, + scope: { + itemId: '@', + title: '@', + view: '@' + }, + controller: function($rootScope, $scope, $filter, globals, $timeout) { + + $scope.main = $scope.$parent.$parent;//TODO: this is a crap!!! + + //add reference to this window, in parent controller + if($scope.$parent[$scope.itemId] == undefined) + { + $scope.$parent[$scope.itemId] = $scope; + } + else + { + throw Error('Modal Window ' + $scope.itemId + ' already exists!'); + } + }, + link: function (scope, elem, attrs) { + + $(elem).css('display', 'none'); + + scope.viewController = null; + + scope.resizeIcon = 'icon-resize-full'; + + scope.modalWindow = $(elem.find('.modal')[0]); + + scope.modalBody = $(elem.find('.modal-body')[0]); + + var modalDialog = $(scope.modalWindow.find('.modal-dialog')[0]); + + //$(modalDialog).draggable({ + // handle: ".modal-header" + //}); + + scope.viewEl = null; + + scope.modalWindow.on('show.bs.modal', function () { + + }); + + scope.modalWindow.on('shown.bs.modal', function () { + + }); + + scope.modalWindow.on('hide.bs.modal', function () { + + }); + + scope.modalWindow.on('hidden.bs.modal', function () { + + }); + + modalDialog.removeClass('modal-large'); + modalDialog.removeClass('modal-medium'); + modalDialog.removeClass('modal-small'); + + //apply width + if(attrs.width != null && attrs.width != undefined) + { + modalDialog.addClass(attrs.width); + } + + scope.show = function(config){ + + config = config == undefined ? null : config; + + scope.main.renderModule(scope.modalBody, scope.view, config, false, function(className, mscope){ + + scope.modalWindow.modal('show'); + + scope.$emit('onShow'); + }); + + scope.viewEl = $(scope.modalBody.children()[0]); + scope.viewController = angular.element(scope.viewEl).scope(); + //scope.viewController['$$view-id'] = scope.view; + + //var currentWindowHeight = $(window).height(); + //var newHeight = (currentWindowHeight - (currentWindowHeight * 30 / 100)); + + //TODO: compute height!!! + scope.modalWindow.modal({ + height: 460, + minHeight: 460, + maxHeight: 460, + show: false, + backdrop: false + }); + }; + + scope.hide = function(){ + + //must be here otherwise controller inside modal will be destroyed + scope.$emit('onHide'); + + scope.viewEl.remove(); + + scope.viewController.$destroy(); + + scope.viewController = null; + + scope.modalWindow.modal('hide'); + }; + + scope.maximize = function(){ + + if(scope.resizeIcon == 'icon-resize-full') + { + scope.resizeIcon = 'icon-resize-small'; + } + else + { + scope.resizeIcon = 'icon-resize-full'; + } + + modalDialog.toggleClass(attrs.width); + + modalDialog.toggleClass('modal-large'); + + scope.$emit('onMaximize'); + }; + + //scope.minimize = function(){ + + // scope.modalWindow.animate({ + // height: '40px', + // top: $(window).height() - 50 + // }, 200); + + //}; + + + } + } +}); \ No newline at end of file diff --git a/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/directives/pagingToolbar.js b/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/directives/pagingToolbar.js new file mode 100644 index 00000000..af6b115e --- /dev/null +++ b/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/directives/pagingToolbar.js @@ -0,0 +1,126 @@ +evoapp.directive('pagingToolbar', function ($filter) { + + return { + restrict: 'AE', + template: + + '', + + scope: { + store: '=' + }, + + link: function (scope, elem, attrs) { + + scope.currentPage = 1; + + scope.showPager = attrs.showPager ? attrs.showPager : true; + + scope.numberOfPages = function(){ + + var numberOfPages = 0; + + if(scope.store.total > 0) + { + numberOfPages = Math.ceil(scope.store.total/scope.store.limit); + } + else + { + numberOfPages = 0; + } + + return numberOfPages; + }; + + scope.move = function(direction) { + + if(direction == 'forward') + { + scope.store.start = scope.store.start + scope.store.limit; + + scope.currentPage = scope.currentPage + 1; + } + else + { + scope.store.start = scope.store.start - scope.store.limit; + + scope.currentPage = scope.currentPage - 1; + } + }; + + scope.$watch('store.start', function(newValue, oldValue){ + + if(newValue != oldValue && newValue != undefined) + { + scope.get(); + } + }); + + scope.$watch('store.total', function(newValue, oldValue){ + + if(!isNaN(newValue)) + { + var total = parseInt(newValue); + + if(total == 0) + { + scope.currentPage = 0; + } + else + { + scope.currentPage = scope.currentPage == 0 ? 1 : scope.currentPage; + } + } + }); + + scope.get = function(){ + + scope.store.get(function(response, status, headers, config, items){ + + scope.currentPage = scope.store.start == 0 ? (items.length > 0 ? 1 : 0) : scope.currentPage; + }); + }; + + scope.showingInfo = function(){ + + var from = (scope.store.items.length == 0 ? 0 : (scope.store.start + 1)), + to = (scope.store.start + scope.store.items.length); + + return $filter('stringFormat')('A mostrar {0} - {1} de {2}', [from, to, scope.store.total]); + }; + + scope.pageInfo = function(){ + + var info = 'Página ' + + scope.currentPage + ' de ' + + scope.numberOfPages(); + + return info; + }; + + + } + } +}); \ No newline at end of file diff --git a/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/filters/stringFormat.js b/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/filters/stringFormat.js new file mode 100644 index 00000000..7e91fafb --- /dev/null +++ b/trunk/SiprpWebFichasClinicas/WebContent/static/html/app/filters/stringFormat.js @@ -0,0 +1,84 @@ + evoapp.filter('stringFormat', function () { + + ///usage from HTML: {{template | stringFormat:[competition.name, competition.place, competition.from, competition.to] } + + //usage from Javascript: $filter('stringFormat')('string to format', ['params array']) + + // function _toFormattedString is based on String.js from http://ajaxcontroltoolkit.codeplex.com/SourceControl/latest#Client/MicrosoftAjax/Extensions/String.js + // as seen in http://stackoverflow.com/questions/2534803/string-format-in-javascript + + function toFormattedString(useLocale, format, values) { + var result = ''; + + for (var i = 0; ;) { + // Find the next opening or closing brace + var open = format.indexOf('{', i); + var close = format.indexOf('}', i); + if ((open < 0) && (close < 0)) { + // Not found: copy the end of the string and break + result += format.slice(i); + break; + } + if ((close > 0) && ((close < open) || (open < 0))) { + + if (format.charAt(close + 1) !== '}') { + throw new Error('format stringFormatBraceMismatch'); + } + + result += format.slice(i, close + 1); + i = close + 2; + continue; + } + + // Copy the string before the brace + result += format.slice(i, open); + i = open + 1; + + // Check for double braces (which display as one and are not arguments) + if (format.charAt(i) === '{') { + result += '{'; + i++; + continue; + } + + if (close < 0) throw new Error('format stringFormatBraceMismatch'); + + // Find the closing brace + + // Get the string between the braces, and split it around the ':' (if any) + var brace = format.substring(i, close); + var colonIndex = brace.indexOf(':'); + var argNumber = parseInt((colonIndex < 0) ? brace : brace.substring(0, colonIndex), 10); + + if (isNaN(argNumber)) throw new Error('format stringFormatInvalid'); + + var argFormat = (colonIndex < 0) ? '' : brace.substring(colonIndex + 1); + + var arg = values[argNumber]; + if (typeof (arg) === "undefined" || arg === null) { + arg = ''; + } + + // If it has a toFormattedString method, call it. Otherwise, call toString() + if (arg.toFormattedString) { + result += arg.toFormattedString(argFormat); + } else if (useLocale && arg.localeFormat) { + result += arg.localeFormat(argFormat); + } else if (arg.format) { + result += arg.format(argFormat); + } else + result += arg.toString(); + + i = close + 1; + } + + return result; + }; + + return function (/*string*/template, /*array*/values) { + if (!values || !values.length || !template) { + return template; + } + return toFormattedString(false, template, values); + }; +}); \ No newline at end of file diff --git a/trunk/SiprpWebFichasClinicas/WebContent/static/html/index.html b/trunk/SiprpWebFichasClinicas/WebContent/static/html/index.html index 7078d507..c284f518 100644 --- a/trunk/SiprpWebFichasClinicas/WebContent/static/html/index.html +++ b/trunk/SiprpWebFichasClinicas/WebContent/static/html/index.html @@ -67,7 +67,6 @@ -