#395 feature - Added license history entity and new angular directive to
load file content
1 files added
8 files modified
| .. | .. |
|---|
| 2 | 2 | |
|---|
| 3 | 3 | import java.io.Serializable; |
|---|
| 4 | 4 | import java.util.Date; |
|---|
| 5 | +import java.util.List; |
|---|
| 5 | 6 | |
|---|
| 6 | 7 | import javax.persistence.Column; |
|---|
| 7 | 8 | import javax.persistence.Entity; |
|---|
| 9 | +import javax.persistence.FetchType; |
|---|
| 8 | 10 | import javax.persistence.GeneratedValue; |
|---|
| 9 | 11 | import javax.persistence.Id; |
|---|
| 10 | 12 | import javax.persistence.JoinColumn; |
|---|
| 11 | 13 | import javax.persistence.ManyToOne; |
|---|
| 12 | 14 | import javax.persistence.NamedQueries; |
|---|
| 13 | 15 | import javax.persistence.NamedQuery; |
|---|
| 16 | +import javax.persistence.OneToMany; |
|---|
| 14 | 17 | import javax.persistence.Table; |
|---|
| 15 | 18 | |
|---|
| 16 | 19 | import org.codehaus.jackson.annotate.JsonAutoDetect; |
|---|
| .. | .. |
|---|
| 77 | 80 | @Column(name = "modification_timestamp") |
|---|
| 78 | 81 | private Date modificationTimestamp; |
|---|
| 79 | 82 | |
|---|
| 80 | | - @Column(name = "activation_timestamp") |
|---|
| 81 | | - private Date activationTimestamp; |
|---|
| 82 | | - |
|---|
| 83 | | - @Column(name = "cancelation_timestamp") |
|---|
| 84 | | - private Date cancelationTimestamp; |
|---|
| 85 | | - |
|---|
| 86 | | - @Column(name = "send_timestamp") |
|---|
| 87 | | - private Date sendTimestamp; |
|---|
| 88 | | - |
|---|
| 89 | 83 | @Column(name = "last_access_timestamp") |
|---|
| 90 | 84 | private Date lastAccessTimestamp; |
|---|
| 91 | 85 | |
|---|
| 92 | 86 | private String comments; |
|---|
| 87 | + |
|---|
| 88 | + @OneToMany(fetch = FetchType.LAZY, mappedBy = "license") |
|---|
| 89 | + private List<LicenseHistory> history; |
|---|
| 93 | 90 | |
|---|
| 94 | 91 | public int getId() { |
|---|
| 95 | 92 | return id; |
|---|
| .. | .. |
|---|
| 209 | 206 | this.email = email; |
|---|
| 210 | 207 | } |
|---|
| 211 | 208 | |
|---|
| 212 | | - public Date getActivationTimestamp() { |
|---|
| 213 | | - return activationTimestamp; |
|---|
| 214 | | - } |
|---|
| 215 | | - |
|---|
| 216 | | - public void setActivationTimestamp(Date activationTimestamp) { |
|---|
| 217 | | - this.activationTimestamp = activationTimestamp; |
|---|
| 218 | | - } |
|---|
| 219 | | - |
|---|
| 220 | | - public Date getSendTimestamp() { |
|---|
| 221 | | - return sendTimestamp; |
|---|
| 222 | | - } |
|---|
| 223 | | - |
|---|
| 224 | | - public void setSendTimestamp(Date sendTimestamp) { |
|---|
| 225 | | - this.sendTimestamp = sendTimestamp; |
|---|
| 226 | | - } |
|---|
| 227 | | - |
|---|
| 228 | 209 | public void setId(int id) { |
|---|
| 229 | 210 | this.id = id; |
|---|
| 230 | 211 | } |
|---|
| .. | .. |
|---|
| 235 | 216 | |
|---|
| 236 | 217 | public void setCanceledBy(User canceledBy) { |
|---|
| 237 | 218 | this.canceledBy = canceledBy; |
|---|
| 238 | | - } |
|---|
| 239 | | - |
|---|
| 240 | | - public Date getCancelationTimestamp() { |
|---|
| 241 | | - return cancelationTimestamp; |
|---|
| 242 | | - } |
|---|
| 243 | | - |
|---|
| 244 | | - public void setCancelationTimestamp(Date cancelationTimestamp) { |
|---|
| 245 | | - this.cancelationTimestamp = cancelationTimestamp; |
|---|
| 246 | 219 | } |
|---|
| 247 | 220 | |
|---|
| 248 | 221 | public Date getLastAccessTimestamp() { |
|---|
| .. | .. |
|---|
| 277 | 250 | this.comments = comments; |
|---|
| 278 | 251 | } |
|---|
| 279 | 252 | |
|---|
| 253 | + public List<LicenseHistory> getHistory() { |
|---|
| 254 | + return history; |
|---|
| 255 | + } |
|---|
| 256 | + |
|---|
| 257 | + public void setHistory(List<LicenseHistory> history) { |
|---|
| 258 | + this.history = history; |
|---|
| 259 | + } |
|---|
| 260 | + |
|---|
| 280 | 261 | public static class Status { |
|---|
| 281 | 262 | public static final int CREATED = 0; |
|---|
| 282 | 263 | public static final int SENT = 1; |
|---|
| .. | .. |
|---|
| 1 | +package net.curisit.securis.db; |
|---|
| 2 | + |
|---|
| 3 | +import java.io.Serializable; |
|---|
| 4 | +import java.util.Date; |
|---|
| 5 | + |
|---|
| 6 | +import javax.persistence.Entity; |
|---|
| 7 | +import javax.persistence.GeneratedValue; |
|---|
| 8 | +import javax.persistence.Id; |
|---|
| 9 | +import javax.persistence.JoinColumn; |
|---|
| 10 | +import javax.persistence.ManyToOne; |
|---|
| 11 | +import javax.persistence.NamedQueries; |
|---|
| 12 | +import javax.persistence.NamedQuery; |
|---|
| 13 | +import javax.persistence.Table; |
|---|
| 14 | + |
|---|
| 15 | +import org.codehaus.jackson.annotate.JsonAutoDetect; |
|---|
| 16 | +import org.codehaus.jackson.annotate.JsonIgnore; |
|---|
| 17 | +import org.codehaus.jackson.annotate.JsonIgnoreProperties; |
|---|
| 18 | +import org.codehaus.jackson.annotate.JsonProperty; |
|---|
| 19 | +import org.codehaus.jackson.map.annotate.JsonSerialize; |
|---|
| 20 | + |
|---|
| 21 | +/** |
|---|
| 22 | + * Entity implementation class for Entity: license |
|---|
| 23 | + * |
|---|
| 24 | + */ |
|---|
| 25 | +@JsonAutoDetect |
|---|
| 26 | +@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) |
|---|
| 27 | +@Entity |
|---|
| 28 | +@Table(name = "license_history") |
|---|
| 29 | +@JsonIgnoreProperties(ignoreUnknown = true) |
|---|
| 30 | +@NamedQueries( |
|---|
| 31 | + { @NamedQuery(name = "list-license-history", query = "SELECT lh FROM LicenseHistory lh where lh.license.id = :licId") }) |
|---|
| 32 | +public class LicenseHistory implements Serializable { |
|---|
| 33 | + |
|---|
| 34 | + private static final long serialVersionUID = 1L; |
|---|
| 35 | + |
|---|
| 36 | + @Id |
|---|
| 37 | + @GeneratedValue |
|---|
| 38 | + private int id; |
|---|
| 39 | + |
|---|
| 40 | + @JsonIgnore |
|---|
| 41 | + @ManyToOne |
|---|
| 42 | + @JoinColumn(name = "license_id") |
|---|
| 43 | + private License license; |
|---|
| 44 | + |
|---|
| 45 | + @JsonIgnore |
|---|
| 46 | + @ManyToOne |
|---|
| 47 | + @JoinColumn(name = "username") |
|---|
| 48 | + private User user; |
|---|
| 49 | + |
|---|
| 50 | + private String action; |
|---|
| 51 | + private String comments; |
|---|
| 52 | + |
|---|
| 53 | + private Date timestamp; |
|---|
| 54 | + |
|---|
| 55 | + public int getId() { |
|---|
| 56 | + return id; |
|---|
| 57 | + } |
|---|
| 58 | + |
|---|
| 59 | + public License getLicense() { |
|---|
| 60 | + return license; |
|---|
| 61 | + } |
|---|
| 62 | + |
|---|
| 63 | + public void setLicense(License license) { |
|---|
| 64 | + this.license = license; |
|---|
| 65 | + } |
|---|
| 66 | + |
|---|
| 67 | + public User getUser() { |
|---|
| 68 | + return user; |
|---|
| 69 | + } |
|---|
| 70 | + |
|---|
| 71 | + @JsonProperty("username") |
|---|
| 72 | + public String getUsername() { |
|---|
| 73 | + return user == null ? null : user.getUsername(); |
|---|
| 74 | + } |
|---|
| 75 | + |
|---|
| 76 | + public void setUser(User user) { |
|---|
| 77 | + this.user = user; |
|---|
| 78 | + } |
|---|
| 79 | + |
|---|
| 80 | + public String getAction() { |
|---|
| 81 | + return action; |
|---|
| 82 | + } |
|---|
| 83 | + |
|---|
| 84 | + public void setAction(String action) { |
|---|
| 85 | + this.action = action; |
|---|
| 86 | + } |
|---|
| 87 | + |
|---|
| 88 | + public String getComments() { |
|---|
| 89 | + return comments; |
|---|
| 90 | + } |
|---|
| 91 | + |
|---|
| 92 | + public void setComments(String comments) { |
|---|
| 93 | + this.comments = comments; |
|---|
| 94 | + } |
|---|
| 95 | + |
|---|
| 96 | + public Date getTimestamp() { |
|---|
| 97 | + return timestamp; |
|---|
| 98 | + } |
|---|
| 99 | + |
|---|
| 100 | + public void setTimestamp(Date timestamp) { |
|---|
| 101 | + this.timestamp = timestamp; |
|---|
| 102 | + } |
|---|
| 103 | + |
|---|
| 104 | + public void setId(int id) { |
|---|
| 105 | + this.id = id; |
|---|
| 106 | + } |
|---|
| 107 | + |
|---|
| 108 | + public static class Actions { |
|---|
| 109 | + public static final String CREATE = "creation"; |
|---|
| 110 | + public static final String ADD_REQUEST = "request"; |
|---|
| 111 | + public static final String SEND = "send"; |
|---|
| 112 | + public static final String MODIFY = "modify"; |
|---|
| 113 | + public static final String ACTIVATE = "activate"; |
|---|
| 114 | + public static final String CANCEL = "cancel"; |
|---|
| 115 | + public static final String DELETE = "delete"; |
|---|
| 116 | + } |
|---|
| 117 | +} |
|---|
| .. | .. |
|---|
| 52 | 52 | com.google.inject.Provider<EntityManager> emProvider; |
|---|
| 53 | 53 | |
|---|
| 54 | 54 | public void filter(ContainerRequestContext containerRequestContext) throws IOException { |
|---|
| 55 | | - // log.info("scw {}, {}", scw, scw.getClass()); |
|---|
| 56 | | - log.info("MACHED res: {}", containerRequestContext.getUriInfo().getMatchedResources()); |
|---|
| 57 | | - // dispatcher.getDefaultContextObjects().remove(SecurityContextWrapper.class); |
|---|
| 58 | 55 | ResourceMethodInvoker methodInvoker = (ResourceMethodInvoker) containerRequestContext.getProperty("org.jboss.resteasy.core.ResourceMethodInvoker"); |
|---|
| 59 | 56 | Method method = methodInvoker.getMethod(); |
|---|
| 60 | 57 | |
|---|
| .. | .. |
|---|
| 82 | 79 | scw.setOrganizationsIds(orgs); |
|---|
| 83 | 80 | containerRequestContext.setSecurityContext(scw); |
|---|
| 84 | 81 | // Next line provide injection in resource methods |
|---|
| 85 | | - log.info("TEST context {}", ResteasyProviderFactory.getContextData(BasicSecurityContext.class)); |
|---|
| 86 | 82 | ResteasyProviderFactory.pushContext(BasicSecurityContext.class, scw); |
|---|
| 87 | | - // log.info("{}", dispatcher.getDefaultContextObjects()); |
|---|
| 88 | | - // dispatcher.getDefaultContextObjects().put(SecurityContextWrapper.class, secContext); |
|---|
| 89 | | - log.info("Added custom SecurityContext for user {}", username); |
|---|
| 83 | + log.debug("Added custom SecurityContext for user {}, orgs: {}", username, orgs); |
|---|
| 90 | 84 | } |
|---|
| 91 | 85 | } |
|---|
| 92 | 86 | |
|---|
| .. | .. |
|---|
| 1 | 1 | package net.curisit.securis.services; |
|---|
| 2 | 2 | |
|---|
| 3 | +import java.io.IOException; |
|---|
| 3 | 4 | import java.util.Date; |
|---|
| 4 | 5 | import java.util.List; |
|---|
| 5 | 6 | |
|---|
| .. | .. |
|---|
| 21 | 22 | import javax.ws.rs.core.Response; |
|---|
| 22 | 23 | import javax.ws.rs.core.Response.Status; |
|---|
| 23 | 24 | |
|---|
| 25 | +import net.curisit.integrity.commons.JsonUtils; |
|---|
| 24 | 26 | import net.curisit.integrity.commons.Utils; |
|---|
| 25 | 27 | import net.curisit.integrity.exception.CurisException; |
|---|
| 26 | 28 | import net.curisit.securis.DefaultExceptionHandler; |
|---|
| .. | .. |
|---|
| 31 | 33 | import net.curisit.securis.security.Securable; |
|---|
| 32 | 34 | import net.curisit.securis.utils.TokenHelper; |
|---|
| 33 | 35 | |
|---|
| 36 | +import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput; |
|---|
| 34 | 37 | import org.slf4j.Logger; |
|---|
| 35 | 38 | import org.slf4j.LoggerFactory; |
|---|
| 36 | 39 | |
|---|
| .. | .. |
|---|
| 124 | 127 | { MediaType.APPLICATION_JSON }) |
|---|
| 125 | 128 | @Transactional |
|---|
| 126 | 129 | public Response create(License lic, @Context BasicSecurityContext bsc) { |
|---|
| 127 | | - log.info("Creating new organization"); |
|---|
| 130 | + log.info("Creating new license from create()"); |
|---|
| 128 | 131 | EntityManager em = emProvider.get(); |
|---|
| 129 | 132 | Pack pack = null; |
|---|
| 130 | 133 | if (lic.getPackId() != null) { |
|---|
| .. | .. |
|---|
| 143 | 146 | } |
|---|
| 144 | 147 | |
|---|
| 145 | 148 | try { |
|---|
| 146 | | - User createdBy = getUser(lic.getCreatedById(), em); |
|---|
| 149 | + User createdBy = getUser(bsc.getUserPrincipal().getName(), em); |
|---|
| 147 | 150 | lic.setCreatedBy(createdBy); |
|---|
| 148 | 151 | } catch (CurisException ex) { |
|---|
| 149 | 152 | String createdByUsername = lic.getCreatedById(); |
|---|
| .. | .. |
|---|
| 161 | 164 | return Response.ok(lic).build(); |
|---|
| 162 | 165 | } |
|---|
| 163 | 166 | |
|---|
| 167 | + @POST |
|---|
| 168 | + @Path("/") |
|---|
| 169 | + @Consumes(MediaType.MULTIPART_FORM_DATA) |
|---|
| 170 | + @Securable |
|---|
| 171 | + @Produces( |
|---|
| 172 | + { MediaType.APPLICATION_JSON }) |
|---|
| 173 | + @Transactional |
|---|
| 174 | + public Response createWithFile(MultipartFormDataInput mpfdi, @Context BasicSecurityContext bsc) throws IOException { |
|---|
| 175 | + License lic = new License(); |
|---|
| 176 | + lic.setCode(mpfdi.getFormDataPart("code", String.class, null)); |
|---|
| 177 | + lic.setRequestData(mpfdi.getFormDataPart("request_data", String.class, null)); |
|---|
| 178 | + lic.setPackId(mpfdi.getFormDataPart("pack_id", Integer.class, null)); |
|---|
| 179 | + lic.setFullName(mpfdi.getFormDataPart("full_name", String.class, null)); |
|---|
| 180 | + lic.setEmail(mpfdi.getFormDataPart("email", String.class, null)); |
|---|
| 181 | + lic.setComments(mpfdi.getFormDataPart("comments", String.class, null)); |
|---|
| 182 | + try { |
|---|
| 183 | + log.info("File content: {}", lic.getRequestData()); |
|---|
| 184 | + log.info("License read from multipart: {}", JsonUtils.toJSON(lic)); |
|---|
| 185 | + } catch (CurisException e) { |
|---|
| 186 | + // TODO Auto-generated catch block |
|---|
| 187 | + e.printStackTrace(); |
|---|
| 188 | + } |
|---|
| 189 | + return create(lic, bsc); |
|---|
| 190 | + } |
|---|
| 191 | + |
|---|
| 164 | 192 | private User getUser(String username, EntityManager em) throws CurisException { |
|---|
| 165 | 193 | User user = null; |
|---|
| 166 | 194 | if (username != null) { |
|---|
| .. | .. |
|---|
| 76 | 76 | email VARCHAR(100) NOT NULL, |
|---|
| 77 | 77 | comments VARCHAR(1024) NULL , |
|---|
| 78 | 78 | creation_timestamp DATETIME NOT NULL , |
|---|
| 79 | | - send_timestamp DATETIME NULL , |
|---|
| 80 | 79 | modification_timestamp DATETIME NULL , |
|---|
| 81 | | - activation_timestamp DATETIME NULL , |
|---|
| 82 | | - cancelation_timestamp DATETIME NULL , |
|---|
| 83 | 80 | last_access_timestamp DATETIME NULL , |
|---|
| 84 | 81 | canceled_by varchar(45) NULL , |
|---|
| 85 | 82 | created_by varchar(45) NULL , |
|---|
| 86 | | - status VARCHAR(3) NOT NULL default 0, |
|---|
| 83 | + status INT NOT NULL default 0, |
|---|
| 84 | + PRIMARY KEY (id)); |
|---|
| 85 | + |
|---|
| 86 | + |
|---|
| 87 | +drop table IF EXISTS license_history; |
|---|
| 88 | +CREATE TABLE IF NOT EXISTS license_history ( |
|---|
| 89 | + id INT NOT NULL auto_increment, |
|---|
| 90 | + license_id INT NOT NULL, |
|---|
| 91 | + username VARCHAR(45) NOT NULL, |
|---|
| 92 | + timestamp DATETIME NOT NULL , |
|---|
| 93 | + action VARCHAR(40) , |
|---|
| 94 | + comments VARCHAR(512) , |
|---|
| 87 | 95 | PRIMARY KEY (id)); |
|---|
| 88 | 96 | |
|---|
| 89 | 97 | |
|---|
| .. | .. |
|---|
| 159 | 159 | **********************************************/ |
|---|
| 160 | 160 | |
|---|
| 161 | 161 | function _success(response) { |
|---|
| 162 | | - console.log('$resource') |
|---|
| 163 | | - console.log(response) |
|---|
| 162 | + console.debug('$resource action success') |
|---|
| 164 | 163 | } |
|---|
| 165 | 164 | function _fail(response) { |
|---|
| 166 | 165 | console |
|---|
| .. | .. |
|---|
| 244 | 243 | promises.push(refs[f.name].$promise); |
|---|
| 245 | 244 | }); |
|---|
| 246 | 245 | |
|---|
| 247 | | - console.log('promises: ' + promises.length |
|---|
| 248 | | - + ' ') |
|---|
| 249 | | - console.log(promises) |
|---|
| 250 | 246 | $q.all(promises) |
|---|
| 251 | 247 | .then(function() { |
|---|
| 252 | 248 | for(var i in refsFields) { |
|---|
| .. | .. |
|---|
| 254 | 250 | var rf = refsFields[i]; |
|---|
| 255 | 251 | var cat = that.getResource(rf.resource); |
|---|
| 256 | 252 | var pk = that.getPk(that.getMetadata(rf.resource)) |
|---|
| 257 | | - console.log('PK field for ' |
|---|
| 258 | | - + rf.name |
|---|
| 259 | | - + ' is ' |
|---|
| 260 | | - + pk) |
|---|
| 253 | + //console.log('PK field for ' + rf.name + ' is ' + pk) |
|---|
| 261 | 254 | var comboData = [] |
|---|
| 262 | 255 | refs[rf.name].forEach(function(row) { |
|---|
| 263 | 256 | comboData.push({ |
|---|
| .. | .. |
|---|
| 271 | 264 | }); |
|---|
| 272 | 265 | }) |
|---|
| 273 | 266 | refs[rf.name] = comboData; |
|---|
| 274 | | - console.log('Ready for combo for ' + rf.name) |
|---|
| 275 | | - console.log(comboData); |
|---|
| 276 | 267 | } |
|---|
| 277 | 268 | _current && _current.fields.forEach(function(f) { |
|---|
| 278 | 269 | if (f.values) |
|---|
| .. | .. |
|---|
| 280 | 271 | }); |
|---|
| 281 | 272 | }) |
|---|
| 282 | 273 | |
|---|
| 283 | | - console.log(refs); |
|---|
| 284 | 274 | return refs; |
|---|
| 285 | 275 | } |
|---|
| 286 | 276 | |
|---|
| .. | .. |
|---|
| 9 | 9 | } |
|---|
| 10 | 10 | |
|---|
| 11 | 11 | var app = angular.module('securis'); |
|---|
| 12 | + |
|---|
| 13 | + app.directive('fileLoader', |
|---|
| 14 | + function($timeout, $parse) { |
|---|
| 15 | + return { |
|---|
| 16 | + restrict : 'A', // only activate on element attribute |
|---|
| 17 | + require : '', |
|---|
| 18 | + link : function(scope, element, attrs) { |
|---|
| 19 | + console.log('scope.license: ' + scope.$parent.license); |
|---|
| 20 | + var setter = $parse(attrs.fileLoader).assign; |
|---|
| 21 | + element.bind('change', function(evt) { |
|---|
| 22 | + console.log('scope.license: ' + scope.$parent.license); |
|---|
| 23 | + var field = $parse(attrs.fileLoader); |
|---|
| 24 | + console.log('field: ' + field); |
|---|
| 25 | + var fileList = evt.target.files; |
|---|
| 26 | + if (fileList != null && fileList[0]) { |
|---|
| 27 | + var reader = new FileReader(); |
|---|
| 28 | + reader.onerror = function(data) { |
|---|
| 29 | + setter(scope.$parent, 'ERROR'); |
|---|
| 30 | + scope.$apply(); |
|---|
| 31 | + } |
|---|
| 32 | + reader.onload = function(data) { |
|---|
| 33 | + setter(scope.$parent, reader.result); |
|---|
| 34 | + scope.$apply(); |
|---|
| 35 | + } |
|---|
| 36 | + |
|---|
| 37 | + reader.readAsText(fileList[0]); |
|---|
| 38 | + } else { |
|---|
| 39 | + console.log('NO FILE: '); |
|---|
| 40 | + field = ''; |
|---|
| 41 | + scope.$apply(); |
|---|
| 42 | + } |
|---|
| 43 | + }); |
|---|
| 44 | + |
|---|
| 45 | + } |
|---|
| 46 | + }; |
|---|
| 47 | + }); |
|---|
| 48 | + |
|---|
| 49 | + console.log(' OK ????? '); |
|---|
| 12 | 50 | |
|---|
| 13 | 51 | app.controller('PackAndLicensesCtrl', [ |
|---|
| 14 | 52 | '$scope', |
|---|
| .. | .. |
|---|
| 17 | 55 | '$store', |
|---|
| 18 | 56 | '$L', |
|---|
| 19 | 57 | function($scope, $http, toaster, $store, $L) { |
|---|
| 20 | | - $scope.licenses = [ |
|---|
| 21 | | - {id: 1, |
|---|
| 22 | | - "code": "BP-SA-001-AKSJMS234", |
|---|
| 23 | | - "user_fullname": "Johnny Belmonte", |
|---|
| 24 | | - "user_email": "jb@curisit.net", |
|---|
| 25 | | - "status": 3}, |
|---|
| 26 | | - {id: 2, |
|---|
| 27 | | - "code": "BP-SA-001-KAJSDHAJS", |
|---|
| 28 | | - "user_fullname": "Walter Simons", |
|---|
| 29 | | - "user_email": "ws@curisit.net", |
|---|
| 30 | | - "status": 1}, |
|---|
| 31 | | - {id: 3, |
|---|
| 32 | | - "code": "BP-SA-001-ASKDGHKA", |
|---|
| 33 | | - "user_fullname": "Frank Belmonte", |
|---|
| 34 | | - "user_email": "fb@curisit.net", |
|---|
| 35 | | - "status": 2}, |
|---|
| 36 | | - {id: 4, |
|---|
| 37 | | - "code": "BP-SA-001-BBBGGGG", |
|---|
| 38 | | - "user_fullname": "John Dalton", |
|---|
| 39 | | - "user_email": "jd@curisit.net", |
|---|
| 40 | | - "status": 3}, |
|---|
| 41 | | - {id: 5, |
|---|
| 42 | | - "code": "BP-SA-001-AKADNAJANA", |
|---|
| 43 | | - "user_fullname": "Walter Martins", |
|---|
| 44 | | - "user_email": "wm@curisit.net", |
|---|
| 45 | | - "status": 3}, |
|---|
| 46 | | - {id: 6, |
|---|
| 47 | | - "code": "BP-SA-001-AKANDAKS", |
|---|
| 48 | | - "user_fullname": "Joe Bolton", |
|---|
| 49 | | - "user_email": "jbol@curisit.net", |
|---|
| 50 | | - "status": 2} |
|---|
| 51 | | - ]; |
|---|
| 52 | 58 | |
|---|
| 53 | 59 | $scope.maxLengthErrorMsg = function(displayname, fieldMaxlength) { |
|---|
| 54 | 60 | return $L.get("{0} length is too long (max: {1}).", $L.get(displayname), fieldMaxlength); |
|---|
| .. | .. |
|---|
| 171 | 177 | function($scope, $http, $resource, toaster, $store, $L) { |
|---|
| 172 | 178 | $scope.$on('pack_changed', function(evt, message) { |
|---|
| 173 | 179 | $scope.licenses = licenseResource.query({packId: $scope.currentPack.id}); |
|---|
| 174 | | - console.log('on pack_changed'); |
|---|
| 175 | 180 | if ($scope.showForm) { |
|---|
| 176 | 181 | if ($scope.isNew) { |
|---|
| 177 | 182 | $scope.license.pack_id = $scope.currentPack.id |
|---|
| .. | .. |
|---|
| 183 | 188 | |
|---|
| 184 | 189 | var licenseResource = $resource('/license/:licenseId', { |
|---|
| 185 | 190 | licenseId : '@id' |
|---|
| 191 | + }, { |
|---|
| 192 | + save_w_upload: { |
|---|
| 193 | + method: "POST", |
|---|
| 194 | + transformRequest: function(data, headersGetter) { |
|---|
| 195 | + // To use an object without FormData, follow: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest?redirectlocale=en-US&redirectslug=DOM%2FXMLHttpRequest%2FUsing_XMLHttpRequest#Submitting_forms_and_uploading_files |
|---|
| 196 | + var formData = new FormData(); |
|---|
| 197 | + angular.forEach(data, function(value, key) { |
|---|
| 198 | + if (key !== 'request_data') |
|---|
| 199 | + formData.append(key, value) |
|---|
| 200 | + else |
|---|
| 201 | + formData.append(key, $('input#request_data_file').get(0).files[0]); |
|---|
| 202 | + }) |
|---|
| 203 | + |
|---|
| 204 | + return formData; |
|---|
| 205 | + }, |
|---|
| 206 | + headers: { |
|---|
| 207 | + 'Content-Type': undefined |
|---|
| 208 | + } |
|---|
| 209 | + } |
|---|
| 186 | 210 | }); |
|---|
| 187 | 211 | $scope.mandatory = { |
|---|
| 188 | 212 | code: true |
|---|
| .. | .. |
|---|
| 202 | 226 | if ($scope.currentPack) |
|---|
| 203 | 227 | $scope.licenses = licenseResource.query({packId: $scope.currentPack.id}); |
|---|
| 204 | 228 | |
|---|
| 229 | +// $(document).on('change', '#request_data_file', function(newValue, oldValue) { |
|---|
| 230 | +// console.log('File changed!!!!'); |
|---|
| 231 | +// var reader = new FileReader(); |
|---|
| 232 | +// reader.onload = function(data) { |
|---|
| 233 | +// console.log('LOAD complete: ' + data); |
|---|
| 234 | +// console.log('LOAD reader.result: ' + reader.result); |
|---|
| 235 | +// $('input#request_data').val(reader.result) |
|---|
| 236 | +// } |
|---|
| 237 | +// console.log('file: ' + $('input#request_data_file').get(0).files[0]); |
|---|
| 238 | +// console.log('file2: ' + $scope.request_data_file); |
|---|
| 239 | +// reader.readAsText($('input#request_data_file').get(0).files[0]); |
|---|
| 240 | +// }); |
|---|
| 241 | + |
|---|
| 205 | 242 | $scope.save = function() { |
|---|
| 243 | + $( "form#licenseForm" ) |
|---|
| 244 | + .attr( "enctype", "multipart/form-data" ) |
|---|
| 245 | + .attr( "encoding", "multipart/form-data" ); |
|---|
| 206 | 246 | var _success = function() { |
|---|
| 207 | 247 | if (!$scope.isNew) $scope.showForm = false; |
|---|
| 208 | 248 | $scope.licenses = licenseResource.query({packId: $scope.currentPack.id}); |
|---|
| 209 | 249 | } |
|---|
| 210 | | - licenseResource.save($scope.license, _success) |
|---|
| 250 | + licenseResource.save_w_upload($scope.license, _success) |
|---|
| 211 | 251 | } |
|---|
| 212 | 252 | |
|---|
| 213 | 253 | $scope.newLicense = function() { |
|---|
| .. | .. |
|---|
| 37 | 37 | $location.path('/login'); |
|---|
| 38 | 38 | toaster.pop('warning', 'Session has expired', null, 4000); |
|---|
| 39 | 39 | } else { |
|---|
| 40 | | - console.log('Last access recent'); |
|---|
| 40 | + console.debug('Last access recent'); |
|---|
| 41 | 41 | } |
|---|
| 42 | 42 | } |
|---|
| 43 | 43 | $store.set('last_access', now); |
|---|
| .. | .. |
|---|
| 61 | 61 | }); |
|---|
| 62 | 62 | |
|---|
| 63 | 63 | m.config(function($routeProvider, $locationProvider, $httpProvider) { |
|---|
| 64 | | - console.log('Configuring routes...'); |
|---|
| 64 | + console.debug('Configuring routes...'); |
|---|
| 65 | 65 | $routeProvider.when('/login', { |
|---|
| 66 | 66 | templateUrl: 'login.html', |
|---|
| 67 | 67 | controller: 'LoginCtrl' |
|---|
| .. | .. |
|---|
| 163 | 163 | </div> |
|---|
| 164 | 164 | |
|---|
| 165 | 165 | </div> |
|---|
| 166 | | - |
|---|
| 166 | +{{license | json}} |
|---|
| 167 | 167 | <div id="licenses_section" class="col-md-6" ng-controller="LicensesCtrl"> |
|---|
| 168 | 168 | <nav class="navbar navbar-default navbar-static-top" ng-disabled="!currentPack"> |
|---|
| 169 | 169 | <!-- Brand and toggle get grouped for better mobile display --> |
|---|
| .. | .. |
|---|
| 253 | 253 | </div> |
|---|
| 254 | 254 | </div> |
|---|
| 255 | 255 | </div> |
|---|
| 256 | | - |
|---|
| 256 | +{{request_data}} |
|---|
| 257 | 257 | <div class="form-group" ng-if="isNew || !license.request_data" > |
|---|
| 258 | 258 | <label class="col-md-3 control-label" for="request_data" i18n>Request data</label> |
|---|
| 259 | 259 | <div class="col-md-8"> |
|---|
| 260 | | - <textarea type="string" id="request_data" name="request_data" placeholder="" |
|---|
| 260 | + <textarea id="request_data" name="request_data" placeholder="" |
|---|
| 261 | 261 | class="form-control" ng-model="license.request_data" rows="2" ng-required="mandatory.request_data" ng-maxlength="{{maxlength.request_data}}"></textarea> |
|---|
| 262 | + <input file-loader="license.request_data" type="file" title="" > |
|---|
| 262 | 263 | <div class="alert inline-alert alert-warning" ng-show="licenseForm.request_data.$invalid"> |
|---|
| 263 | 264 | <span class="glyphicon glyphicon-warning-sign"></span> |
|---|
| 264 | 265 | <span ng-show="licenseForm.request_data.$error.maxlength" ng-bind="maxlengthErrorMsg('Request data', maxlength.request_data)"></span> |
|---|
| .. | .. |
|---|
| 272 | 273 | <div class="col-md-8"> |
|---|
| 273 | 274 | <textarea type="string" id="comments" name="comments" placeholder="" |
|---|
| 274 | 275 | class="form-control" ng-model="license.comments" rows="2" ng-required="mandatory.comments" ng-maxlength="{{maxlength.comments}}"></textarea> |
|---|
| 276 | + |
|---|
| 275 | 277 | <div class="alert inline-alert alert-warning" ng-show="licenseForm.comments.$invalid"> |
|---|
| 276 | 278 | <span class="glyphicon glyphicon-warning-sign"></span> |
|---|
| 277 | 279 | <span ng-show="licenseForm.comments.$error.maxlength" ng-bind="maxlengthErrorMsg('Comments', maxlength.comments)"></span> |
|---|