SHARE
TWEET

Untitled

a guest Dec 16th, 2014 175 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. angularApp.factory('ChunkFactoryUI', function(ChunksFactory, ImageFactoryUI, PatientIdRequestService) {
  2.  
  3.     var chunks = {};
  4.  
  5.     function Chunk(json) {
  6.         this.init(json);
  7.     }    
  8.  
  9.     Chunk.prototype.buildAssociations = function() {
  10.  
  11.         var imagesObject = [];
  12.         angular.forEach(this.images, function(value, key){
  13.             imagesObject.push(new ImageFactoryUI(value));
  14.         });
  15.  
  16.         delete this.images;
  17.         this.images = imagesObject;
  18.     }
  19.  
  20.     Chunk.prototype.init = function(json) {
  21.  
  22.         angular.extend(this, json);
  23.         this.buildAssociations();        
  24.  
  25.         chunks[self.id] = self;
  26.     }
  27.  
  28.     Chunk.getById = function(id) {
  29.         return chunks[id];
  30.     }
  31.  
  32.     Chunk.getAllChunks = function(id) {
  33.         return chunks;
  34.     }
  35.  
  36.     Chunk.prototype.delete = function() {
  37.        
  38.         if (confirm("Desea borrar todas las imagenes!!!!!!!!!! OMFGGG?")) {
  39.             var self = this;
  40.            
  41.             ChunksFactory.delete({id: this.id}, function(){
  42.                 self.reload();
  43.             });
  44.         }        
  45.     }
  46.  
  47.     Chunk.prototype.reload = function() {
  48.  
  49.         var self = this;
  50.         ChunksFactory.get({id:this.id},function(data){
  51.             self.init(data);
  52.         })
  53.     }
  54.  
  55.     Chunk.prototype.reset = function () {
  56.  
  57.         var self = this;
  58.         ChunksFactory.reset({id: this.id}, function(){
  59.             self.reload();
  60.         });
  61.  
  62.     }
  63.  
  64.     Chunk.prototype.unassign = function() {
  65.  
  66.         var self = this;
  67.         if (confirm("Este lote ya esta asociado a uno o varios pacientes\nDesea desasignar las imagenes?")) {
  68.             ChunksFactory.unassign({id: this.id}, function(){
  69.                 self.reload();
  70.             });
  71.         }        
  72.     };    
  73.  
  74.     Chunk.prototype.assignToPatient = function(patient) {
  75.         var self = this;
  76.  
  77.         if (angular.isUndefined(patient)) {
  78.             PatientIdRequestService.open().then(function(patient) {
  79.  
  80.                 ChunksFactory.assignToPatient({id: self.id, patient: patient}, function(){
  81.                     self.reload();
  82.                     //$scope.chunks = ChunksFactory.getAll();
  83.                 });
  84.             });
  85.         }
  86.         else {
  87.  
  88.             ChunksFactory.assignToPatient({id: self.id, patient: patient}, function(){
  89.                 self.reload();
  90.                 //$scope.chunks = ChunksFactory.getAll();
  91.             });
  92.         }  
  93.     };    
  94.  
  95.  
  96.     Chunk.loadAll = function() {
  97.        
  98.         return ChunksFactory.getAll().$promise
  99.             .then(function(res){
  100.                 return res.map(function(result){
  101.                     return new Chunk(result)
  102.                 })
  103.             });
  104.     }
  105.  
  106.     return Chunk;
  107. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top