Created
January 12, 2016 11:44
-
-
Save pedrohugorm/faca232b069369f1f482 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
'use strict'; | |
var module = angular.module('modalHelper', []); | |
module.factory('modalTemplateFath', [ | |
function () { | |
return { | |
module: function (fileName) { | |
return 'Partial/SharedModals-' + fileName; | |
}, | |
partial: function (fileName) { | |
return 'Partial/' + fileName; | |
} | |
}; | |
} | |
]); | |
module.factory('modalFactory', [ | |
'$modal', | |
'$log', | |
'modalTemplateFath', | |
function ($modal, $log, modalTemplateFath) { | |
function constructAndOpenModal(templateFile, controllerName, resolve, callback, windowClass) { | |
windowClass = windowClass || ''; | |
var modalInstance = $modal.open({ | |
templateUrl: templateFile, | |
controller: controllerName, | |
backdrop: 'static', | |
keyboard: false, | |
windowClass: windowClass, | |
resolve: resolve | |
}); | |
modalInstance.result.then(function (selectedItem) { | |
if (callback) callback(selectedItem); | |
}, function () { | |
$log.info('Modal dismissed at: ' + new Date()); | |
}); | |
return modalInstance; | |
} | |
return { | |
createModal: constructAndOpenModal, | |
getPartialPath: modalTemplateFath.partial, | |
getModulePath: modalTemplateFath.module, | |
confirm: function (message, title, callback) { | |
constructAndOpenModal( | |
modalTemplateFath.module('Confirm'), | |
'ModalConfirmController', | |
{ | |
message: function () { return message; }, | |
title: function () { return title; } | |
}, | |
callback, | |
null | |
); | |
}, | |
alert: function (message, title, callback) { | |
constructAndOpenModal( | |
modalTemplateFath.module('Alert'), | |
'ModalConfirmController', | |
{ | |
message: function () { return message; }, | |
title: function () { return title; } | |
}, | |
callback, | |
null | |
); | |
}, | |
form: function (templateFile, controllerName, title, callback) { | |
constructAndOpenModal( | |
templateFile, | |
controllerName, | |
{ | |
title: function () { return title; } | |
}, | |
callback, | |
null | |
); | |
}, | |
loading: function () { | |
constructAndOpenModal( | |
modalTemplateFath.partial('login.html'), | |
null, | |
null, | |
null, | |
null | |
); | |
}, | |
uploadSingle: function () { | |
return constructAndOpenModal( | |
modalTemplateFath.partial('SharedModals-Upload'), | |
'UploadModalController', | |
{}, | |
null, | |
'modal-upload' | |
); | |
}, | |
uploadMultiple: function () { | |
return constructAndOpenModal( | |
modalTemplateFath.partial('SharedModals-UploadMultiple'), | |
'UploadModalController', | |
{}, | |
null, | |
'modal-upload' | |
); | |
}, | |
openPropostaInstituicaoForm: function(formData, item) { | |
return constructAndOpenModal( | |
modalTemplateFath.partial('Proposta-InstituicaoForm'), | |
'PropostaInstituicaoFormModalController', | |
{ | |
form: function() { | |
return formData; | |
}, | |
item : function() { | |
return item; | |
} | |
}, | |
null, | |
'modal-form-lg' | |
); | |
}, | |
openPropostaEntidadeForm: function(formData, item) { | |
return constructAndOpenModal( | |
modalTemplateFath.partial('Proposta-EntidadeForm'), | |
'PropostaEntidadeFormModalController', | |
{ | |
form: function() { | |
return formData; | |
}, | |
item : function() { | |
return item; | |
} | |
}, | |
null, | |
'modal-form-lg' | |
); | |
}, | |
openPropostaPatenteForm: function(formData, item, list) { | |
return constructAndOpenModal( | |
modalTemplateFath.partial('Proposta-PatenteForm'), | |
'PropostaFormPatenteModalController', | |
{ | |
form: function() { | |
return formData; | |
}, | |
item : function() { | |
return item; | |
}, | |
list: function () { | |
return list; | |
} | |
}, | |
null, | |
'modal-form-md' | |
); | |
}, | |
openPropostaParticipantesForm: function(formData, item, list) { | |
return constructAndOpenModal( | |
modalTemplateFath.partial('Proposta-ParticipantesForm'), | |
'PropostaFormParticipantesModalController', | |
{ | |
form: function() { | |
return formData; | |
}, | |
item : function() { | |
return item; | |
}, | |
list: function () { | |
return list; | |
} | |
}, | |
null, | |
'modal-form-md' | |
); | |
}, | |
openPropostaResponsabilidadesForm: function (formData, item, list) { | |
return constructAndOpenModal( | |
modalTemplateFath.partial('Proposta-ResponsabilidadesProjetoModalForm'), | |
'ResponsabilidadesProjetoModalModalController', | |
{ | |
form: function () { | |
return formData; | |
}, | |
item: function () { | |
return item; | |
}, | |
list: function () { | |
return list; | |
} | |
}, | |
null, | |
'modal-form-lg' | |
); | |
}, | |
openAddItemForm: function (template, cssClass, formData, item, list) { | |
return constructAndOpenModal( | |
modalTemplateFath.partial(template), | |
'DefaultAddItemModalController', | |
{ | |
form: function () { | |
return formData; | |
}, | |
item: function () { | |
return item; | |
}, | |
list: function () { | |
return list; | |
} | |
}, | |
null, | |
cssClass | |
); | |
} | |
}; | |
} | |
]); | |
module.controller('ModalConfirmController', [ | |
'$scope', | |
'$modalInstance', | |
'message', | |
'title', | |
function ($scope, $modalInstance, message, title) { | |
$scope.title = title; | |
$scope.message = message; | |
$scope.ok = function () { | |
$modalInstance.close(true); | |
}; | |
$scope.cancel = function () { | |
$modalInstance.close(false); | |
}; | |
} | |
]); | |
/** | |
* https://github.com/nervgh/angular-file-upload | |
* http://nervgh.github.io/pages/angular-file-upload/examples/image-preview/ | |
* https://github.com/nervgh/angular-file-upload/wiki/Introduction | |
*/ | |
module.controller('UploadModalController', [ | |
'$scope', | |
'$modalInstance', | |
'FileUploader', | |
'$timeout', | |
function ($scope, $modalInstance, FileUploader, $timeout) { | |
var uploader = $scope.uploader = new FileUploader({ url: 'Upload/Send' }); | |
$scope.ok = function () { | |
$modalInstance.close(true); | |
}; | |
$scope.cancel = function () { | |
$modalInstance.close(false); | |
}; | |
uploader.onWhenAddingFileFailed = function (item /*{File|FileLikeObject}*/, filter, options) { | |
console.info('onWhenAddingFileFailed', item, filter, options); | |
}; | |
uploader.onAfterAddingFile = function (fileItem) { | |
console.info('onAfterAddingFile', fileItem); | |
}; | |
uploader.onAfterAddingAll = function (addedFileItems) { | |
console.info('onAfterAddingAll', addedFileItems); | |
$scope.isAllCompleted = false; | |
}; | |
uploader.onBeforeUploadItem = function (item) { | |
console.info('onBeforeUploadItem', item); | |
}; | |
uploader.onProgressItem = function (fileItem, progress) { | |
console.info('onProgressItem', fileItem, progress); | |
}; | |
uploader.onProgressAll = function (progress) { | |
console.info('onProgressAll', progress); | |
}; | |
uploader.onSuccessItem = function (fileItem, response, status, headers) { | |
console.info('onSuccessItem', fileItem, response, status, headers); | |
}; | |
uploader.onErrorItem = function (fileItem, response, status, headers) { | |
console.info('onErrorItem', fileItem, response, status, headers); | |
}; | |
uploader.onCancelItem = function (fileItem, response, status, headers) { | |
console.info('onCancelItem', fileItem, response, status, headers); | |
}; | |
uploader.onCompleteItem = function (fileItem, response, status, headers) { | |
console.info('onCompleteItem', fileItem, response, status, headers); | |
}; | |
uploader.onCompleteAll = function () { | |
console.info('onCompleteAll', uploader); | |
$scope.isAllCompleted = true; | |
}; | |
} | |
]); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment