#395 feature - Implemented pack section
| .. | .. |
|---|
| 55 | 55 | |
|---|
| 56 | 56 | private int status; |
|---|
| 57 | 57 | |
|---|
| 58 | | - @JoinColumn(name = "full_name") |
|---|
| 58 | + @Column(name = "full_name") |
|---|
| 59 | 59 | private String fullName; |
|---|
| 60 | 60 | |
|---|
| 61 | 61 | private String email; |
|---|
| .. | .. |
|---|
| 57 | 57 | return id; |
|---|
| 58 | 58 | } |
|---|
| 59 | 59 | |
|---|
| 60 | + public void setId(Integer id) { |
|---|
| 61 | + this.id = id; |
|---|
| 62 | + } |
|---|
| 63 | + |
|---|
| 60 | 64 | public String getName() { |
|---|
| 61 | 65 | return name; |
|---|
| 62 | 66 | } |
|---|
| .. | .. |
|---|
| 8 | 8 | import javax.persistence.Column; |
|---|
| 9 | 9 | import javax.persistence.Entity; |
|---|
| 10 | 10 | import javax.persistence.FetchType; |
|---|
| 11 | +import javax.persistence.GeneratedValue; |
|---|
| 11 | 12 | import javax.persistence.Id; |
|---|
| 12 | 13 | import javax.persistence.JoinColumn; |
|---|
| 13 | 14 | import javax.persistence.ManyToOne; |
|---|
| .. | .. |
|---|
| 31 | 32 | @Table(name = "pack") |
|---|
| 32 | 33 | @NamedQueries( |
|---|
| 33 | 34 | { @NamedQuery(name = "list-packs", query = "SELECT pa FROM Pack pa"),// |
|---|
| 34 | | - @NamedQuery(name = "list-packs-by-org", query = "SELECT pa FROM Pack pa where pa.organization = :organization") }) |
|---|
| 35 | + @NamedQuery(name = "list-packs-by-orgs", query = "SELECT pa FROM Pack pa where pa.organization.id in :list_ids") }) |
|---|
| 35 | 36 | public class Pack implements Serializable { |
|---|
| 36 | 37 | |
|---|
| 37 | 38 | private static final long serialVersionUID = 1L; |
|---|
| 38 | 39 | |
|---|
| 39 | 40 | @Id |
|---|
| 41 | + @GeneratedValue |
|---|
| 40 | 42 | private int id; |
|---|
| 41 | 43 | |
|---|
| 42 | 44 | private String code; |
|---|
| 45 | + |
|---|
| 46 | + private String comments; |
|---|
| 43 | 47 | |
|---|
| 44 | 48 | @Column(name = "creation_timestamp") |
|---|
| 45 | 49 | private Date creationTimestamp; |
|---|
| .. | .. |
|---|
| 63 | 67 | @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "pack") |
|---|
| 64 | 68 | private Set<License> licenses; |
|---|
| 65 | 69 | |
|---|
| 66 | | - @JoinColumn(name = "num_licenses") |
|---|
| 70 | + @Column(name = "num_licenses") |
|---|
| 71 | + @JsonProperty("num_licenses") |
|---|
| 67 | 72 | private int numLicenses; |
|---|
| 68 | 73 | |
|---|
| 69 | 74 | public int getId() { |
|---|
| .. | .. |
|---|
| 190 | 195 | } |
|---|
| 191 | 196 | |
|---|
| 192 | 197 | @JsonProperty("license_type_id") |
|---|
| 198 | + public void setLicTypeId(Integer idLT) { |
|---|
| 199 | + if (idLT == null) { |
|---|
| 200 | + licenseType = null; |
|---|
| 201 | + } else { |
|---|
| 202 | + licenseType = new LicenseType(); |
|---|
| 203 | + licenseType.setId(idLT); |
|---|
| 204 | + } |
|---|
| 205 | + } |
|---|
| 206 | + |
|---|
| 207 | + @JsonProperty("license_type_id") |
|---|
| 193 | 208 | public Integer getLicTypeId() { |
|---|
| 194 | 209 | return licenseType == null ? null : licenseType.getId(); |
|---|
| 195 | 210 | } |
|---|
| .. | .. |
|---|
| 205 | 220 | createdBy.setUsername(username); |
|---|
| 206 | 221 | } |
|---|
| 207 | 222 | |
|---|
| 223 | + @JsonProperty("created_by_name") |
|---|
| 224 | + public String getCreatedByname() { |
|---|
| 225 | + return createdBy == null ? null : String.format("%s %s", createdBy.getFirstName(), createdBy.getFirstName()); |
|---|
| 226 | + } |
|---|
| 227 | + |
|---|
| 208 | 228 | @JsonProperty("licensetype_code") |
|---|
| 209 | 229 | public String getLicenseTypcode() { |
|---|
| 210 | 230 | return licenseType == null ? null : licenseType.getCode(); |
|---|
| 211 | 231 | } |
|---|
| 212 | 232 | |
|---|
| 233 | + public String getComments() { |
|---|
| 234 | + return comments; |
|---|
| 235 | + } |
|---|
| 236 | + |
|---|
| 237 | + public void setComments(String comments) { |
|---|
| 238 | + this.comments = comments; |
|---|
| 239 | + } |
|---|
| 240 | + |
|---|
| 213 | 241 | } |
|---|
| .. | .. |
|---|
| 52 | 52 | |
|---|
| 53 | 53 | private int roles; |
|---|
| 54 | 54 | |
|---|
| 55 | | - @JsonProperty(value = "last_login") |
|---|
| 56 | 55 | @Column(name = "last_login") |
|---|
| 57 | 56 | private Date lastLogin; |
|---|
| 58 | 57 | |
|---|
| .. | .. |
|---|
| 1 | 1 | package net.curisit.securis.services; |
|---|
| 2 | 2 | |
|---|
| 3 | +import java.security.Principal; |
|---|
| 3 | 4 | import java.util.Date; |
|---|
| 4 | 5 | import java.util.List; |
|---|
| 5 | 6 | |
|---|
| 7 | +import javax.annotation.security.RolesAllowed; |
|---|
| 6 | 8 | import javax.inject.Inject; |
|---|
| 7 | 9 | import javax.inject.Provider; |
|---|
| 8 | 10 | import javax.persistence.EntityManager; |
|---|
| .. | .. |
|---|
| 23 | 25 | import javax.ws.rs.core.Response.Status; |
|---|
| 24 | 26 | |
|---|
| 25 | 27 | import net.curisit.integrity.commons.Utils; |
|---|
| 26 | | -import net.curisit.integrity.exception.CurisException; |
|---|
| 27 | 28 | import net.curisit.securis.DefaultExceptionHandler; |
|---|
| 28 | 29 | import net.curisit.securis.db.Pack; |
|---|
| 29 | | -import net.curisit.securis.db.User; |
|---|
| 30 | +import net.curisit.securis.security.BasicSecurityContext; |
|---|
| 31 | +import net.curisit.securis.security.Securable; |
|---|
| 30 | 32 | import net.curisit.securis.utils.TokenHelper; |
|---|
| 31 | 33 | |
|---|
| 32 | 34 | import org.slf4j.Logger; |
|---|
| .. | .. |
|---|
| 59 | 61 | */ |
|---|
| 60 | 62 | @GET |
|---|
| 61 | 63 | @Path("/") |
|---|
| 64 | + @Securable |
|---|
| 62 | 65 | @Produces( |
|---|
| 63 | 66 | { MediaType.APPLICATION_JSON }) |
|---|
| 64 | | - public Response index() { |
|---|
| 67 | + public Response index(@Context BasicSecurityContext bsc) { |
|---|
| 65 | 68 | log.info("Getting packs list "); |
|---|
| 66 | 69 | |
|---|
| 67 | 70 | EntityManager em = emProvider.get(); |
|---|
| 68 | | - TypedQuery<Pack> q = em.createNamedQuery("list-packs-by-orgs", Pack.class); |
|---|
| 71 | + // TypedQuery<Pack> q = em.createNamedQuery("list-packs-by-orgs", Pack.class); |
|---|
| 72 | + |
|---|
| 73 | + TypedQuery<Pack> q; |
|---|
| 74 | + if (bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN)) { |
|---|
| 75 | + log.info("Getting all packs for user: " + bsc.getUserPrincipal()); |
|---|
| 76 | + q = em.createNamedQuery("list-packs", Pack.class); |
|---|
| 77 | + } else { |
|---|
| 78 | + q = em.createNamedQuery("list-packs-by-orgs", Pack.class); |
|---|
| 79 | + if (bsc.getOrganizationsIds() == null) |
|---|
| 80 | + Response.ok().build(); |
|---|
| 81 | + // log.info("Getting only {} orgs for user: {}", securityContext.getOrganizationsIds(), securityContext.getUserPrincipal()); |
|---|
| 82 | + q.setParameter("list_ids", bsc.getOrganizationsIds()); |
|---|
| 83 | + } |
|---|
| 69 | 84 | |
|---|
| 70 | 85 | List<Pack> list = q.getResultList(); |
|---|
| 71 | 86 | |
|---|
| 72 | 87 | return Response.ok(list).build(); |
|---|
| 88 | + } |
|---|
| 89 | + |
|---|
| 90 | + private Response generateErrorUnathorizedAccess(Pack pack, Principal user) { |
|---|
| 91 | + log.error("Pack with id {} not accesible by user {}", pack, user); |
|---|
| 92 | + return Response.status(Status.UNAUTHORIZED).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Unathorized access to pack").build(); |
|---|
| 73 | 93 | } |
|---|
| 74 | 94 | |
|---|
| 75 | 95 | /** |
|---|
| .. | .. |
|---|
| 78 | 98 | */ |
|---|
| 79 | 99 | @GET |
|---|
| 80 | 100 | @Path("/{packId}") |
|---|
| 101 | + @Securable |
|---|
| 81 | 102 | @Produces( |
|---|
| 82 | 103 | { MediaType.APPLICATION_JSON }) |
|---|
| 83 | | - public Response get(@PathParam("packId") String packId, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) { |
|---|
| 104 | + public Response get(@PathParam("packId") String packId, @Context BasicSecurityContext bsc) { |
|---|
| 84 | 105 | log.info("Getting pack data for id: {}: ", packId); |
|---|
| 85 | 106 | if (packId == null || packId.equals("")) { |
|---|
| 86 | 107 | log.error("Pack ID is mandatory"); |
|---|
| .. | .. |
|---|
| 88 | 109 | } |
|---|
| 89 | 110 | |
|---|
| 90 | 111 | EntityManager em = emProvider.get(); |
|---|
| 91 | | - Pack lt = em.find(Pack.class, Integer.parseInt(packId)); |
|---|
| 92 | | - if (lt == null) { |
|---|
| 112 | + Pack pack = em.find(Pack.class, Integer.parseInt(packId)); |
|---|
| 113 | + if (pack == null) { |
|---|
| 93 | 114 | log.error("Pack with id {} not found in DB", packId); |
|---|
| 94 | 115 | return Response.status(Status.NOT_FOUND).build(); |
|---|
| 95 | 116 | } |
|---|
| 96 | | - return Response.ok(lt).build(); |
|---|
| 117 | + if (bsc.isUserInRole(BasicSecurityContext.ROL_ADVANCE)) { |
|---|
| 118 | + if (bsc.getOrganizationsIds() == null || !bsc.getOrganizationsIds().contains(pack.getOrgId())) { |
|---|
| 119 | + return generateErrorUnathorizedAccess(pack, bsc.getUserPrincipal()); |
|---|
| 120 | + } |
|---|
| 121 | + } |
|---|
| 122 | + return Response.ok(pack).build(); |
|---|
| 97 | 123 | } |
|---|
| 98 | 124 | |
|---|
| 99 | 125 | @POST |
|---|
| 100 | 126 | @Path("/") |
|---|
| 127 | + @Securable |
|---|
| 128 | + @RolesAllowed(BasicSecurityContext.ROL_ADMIN) |
|---|
| 101 | 129 | @Consumes(MediaType.APPLICATION_JSON) |
|---|
| 102 | 130 | @Produces( |
|---|
| 103 | 131 | { MediaType.APPLICATION_JSON }) |
|---|
| .. | .. |
|---|
| 112 | 140 | return Response.ok(pack).build(); |
|---|
| 113 | 141 | } |
|---|
| 114 | 142 | |
|---|
| 115 | | - private User getUser(String username, EntityManager em) throws CurisException { |
|---|
| 116 | | - User user = null; |
|---|
| 117 | | - if (username != null) { |
|---|
| 118 | | - user = em.find(User.class, username); |
|---|
| 119 | | - if (user == null) { |
|---|
| 120 | | - throw new CurisException("User not found"); |
|---|
| 121 | | - } |
|---|
| 122 | | - } |
|---|
| 123 | | - return user; |
|---|
| 124 | | - } |
|---|
| 125 | | - |
|---|
| 126 | 143 | @PUT |
|---|
| 127 | 144 | @POST |
|---|
| 128 | 145 | @Path("/{packId}") |
|---|
| 129 | 146 | @Transactional |
|---|
| 147 | + @Securable |
|---|
| 148 | + @RolesAllowed(BasicSecurityContext.ROL_ADMIN) |
|---|
| 130 | 149 | @Consumes(MediaType.APPLICATION_JSON) |
|---|
| 131 | 150 | @Produces( |
|---|
| 132 | 151 | { MediaType.APPLICATION_JSON }) |
|---|
| .. | .. |
|---|
| 141 | 160 | |
|---|
| 142 | 161 | @DELETE |
|---|
| 143 | 162 | @Path("/{packId}") |
|---|
| 163 | + @Securable |
|---|
| 164 | + @RolesAllowed(BasicSecurityContext.ROL_ADMIN) |
|---|
| 144 | 165 | @Transactional |
|---|
| 145 | 166 | @Produces( |
|---|
| 146 | 167 | { MediaType.APPLICATION_JSON }) |
|---|
| .. | .. |
|---|
| 55 | 55 | |
|---|
| 56 | 56 | drop table IF EXISTS pack; |
|---|
| 57 | 57 | CREATE TABLE IF NOT EXISTS pack ( |
|---|
| 58 | | - id INT NOT NULL, |
|---|
| 58 | + id INT NOT NULL auto_increment, |
|---|
| 59 | 59 | code VARCHAR(50) NOT NULL , |
|---|
| 60 | 60 | num_licenses INT NOT NULL , |
|---|
| 61 | + comments VARCHAR(1024) NULL , |
|---|
| 61 | 62 | license_type_id INT NOT NULL, |
|---|
| 62 | 63 | organization_id INT NOT NULL, |
|---|
| 63 | 64 | created_by varchar(45) NULL , |
|---|
| .. | .. |
|---|
| 66 | 67 | |
|---|
| 67 | 68 | drop table IF EXISTS license; |
|---|
| 68 | 69 | CREATE TABLE IF NOT EXISTS license ( |
|---|
| 69 | | - id INT NOT NULL, |
|---|
| 70 | + id INT NOT NULL auto_increment, |
|---|
| 70 | 71 | code VARCHAR(100) NOT NULL , |
|---|
| 71 | 72 | request_data VARCHAR(1024) NULL , |
|---|
| 72 | 73 | license_data VARCHAR(1024) NULL , |
|---|
| 73 | 74 | pack_id INT NOT NULL, |
|---|
| 74 | 75 | full_name VARCHAR(150) NULL, |
|---|
| 75 | 76 | email VARCHAR(100) NOT NULL, |
|---|
| 77 | + comments VARCHAR(1024) NULL , |
|---|
| 76 | 78 | creation_timestamp DATETIME NOT NULL , |
|---|
| 77 | 79 | send_timestamp DATETIME NULL , |
|---|
| 78 | 80 | modification_timestamp DATETIME NULL , |
|---|
| .. | .. |
|---|
| 4 | 4 | var app = angular.module('securis'); |
|---|
| 5 | 5 | |
|---|
| 6 | 6 | var HTTP_ERRORS = { |
|---|
| 7 | | - 403: "Forbidden action", |
|---|
| 7 | + 401: "Unathorized action", |
|---|
| 8 | + 403: "Forbidden action", |
|---|
| 8 | 9 | 500: "Server error", |
|---|
| 9 | 10 | 404: "Element not found" |
|---|
| 10 | 11 | } |
|---|
| .. | .. |
|---|
| 99 | 100 | |
|---|
| 100 | 101 | } ]); |
|---|
| 101 | 102 | |
|---|
| 102 | | - app.controller('CatalogFormCtrl', [ '$scope', '$http', 'toaster', 'Catalogs', |
|---|
| 103 | | - function($scope, $http, toaster, Catalogs) { |
|---|
| 103 | + app.controller('CatalogFormCtrl', [ '$scope', '$http', 'toaster', 'Catalogs', '$L', |
|---|
| 104 | + function($scope, $http, toaster, Catalogs, $L) { |
|---|
| 104 | 105 | $scope.scope = $scope; |
|---|
| 105 | 106 | console.log('Form: currentCatalog:' + $scope.cataLogIndex); |
|---|
| 106 | 107 | |
|---|
| .. | .. |
|---|
| 2 | 2 | 'use strict'; |
|---|
| 3 | 3 | |
|---|
| 4 | 4 | /* |
|---|
| 5 | | - * Catalogs module |
|---|
| 6 | | - */ |
|---|
| 5 | + * Catalogs module |
|---|
| 6 | + */ |
|---|
| 7 | 7 | |
|---|
| 8 | 8 | angular |
|---|
| 9 | 9 | .module('catalogs', [ 'ngResource' ]) |
|---|
| .. | .. |
|---|
| 44 | 44 | }) |
|---|
| 45 | 45 | } |
|---|
| 46 | 46 | this.init = function() { |
|---|
| 47 | + if (_metadata) { |
|---|
| 48 | + console.debug('Catalogs already initilizated'); |
|---|
| 49 | + var defer = $q.defer(); |
|---|
| 50 | + defer.resolve(_metadata); |
|---|
| 51 | + return defer.promise; |
|---|
| 52 | + } |
|---|
| 47 | 53 | return _list(); |
|---|
| 48 | 54 | } |
|---|
| 49 | 55 | this.getList = function() { |
|---|
| .. | .. |
|---|
| 59 | 65 | if (res === undefined) |
|---|
| 60 | 66 | return _current ? resources[_current.resource] |
|---|
| 61 | 67 | : null; |
|---|
| 62 | | - return _current ? resources[res] : null; |
|---|
| 68 | + return resources[res]; |
|---|
| 63 | 69 | } |
|---|
| 64 | 70 | this.getPk = function(catalogMetadata) { |
|---|
| 65 | 71 | if (!catalogMetadata) |
|---|
| .. | .. |
|---|
| 72 | 78 | return null; |
|---|
| 73 | 79 | } |
|---|
| 74 | 80 | /** |
|---|
| 75 | | - * Returns catalog metadata |
|---|
| 76 | | - * |
|---|
| 77 | | - * @param index: |
|---|
| 78 | | - * Return current catalog if |
|---|
| 79 | | - * undefined, if string It find the |
|---|
| 80 | | - * catalog by resoource name if |
|---|
| 81 | | - * number it find it by position |
|---|
| 82 | | - */ |
|---|
| 81 | + * Returns catalog metadata |
|---|
| 82 | + * |
|---|
| 83 | + * @param index: |
|---|
| 84 | + * Return current catalog if |
|---|
| 85 | + * undefined, if string It find the |
|---|
| 86 | + * catalog by resoource name if |
|---|
| 87 | + * number it find it by position |
|---|
| 88 | + */ |
|---|
| 83 | 89 | this.getMetadata = function(index) { |
|---|
| 84 | 90 | if (!_metadata) |
|---|
| 85 | 91 | throw new Error( |
|---|
| .. | .. |
|---|
| 105 | 111 | _current = _metadata[index]; |
|---|
| 106 | 112 | } |
|---|
| 107 | 113 | /*********************************************** |
|---|
| 108 | | - * Catalog fields methods * |
|---|
| 109 | | - **********************************************/ |
|---|
| 114 | + * Catalog fields methods * |
|---|
| 115 | + **********************************************/ |
|---|
| 110 | 116 | |
|---|
| 111 | 117 | /** |
|---|
| 112 | | - * Returns the first field in form that should |
|---|
| 113 | | - * get the focus. We find the first field that |
|---|
| 114 | | - * is not read only |
|---|
| 115 | | - */ |
|---|
| 118 | + * Returns the first field in form that should |
|---|
| 119 | + * get the focus. We find the first field that |
|---|
| 120 | + * is not read only |
|---|
| 121 | + */ |
|---|
| 116 | 122 | this.getFFF = this.getFirstFocusableField = function() { |
|---|
| 117 | 123 | if (!_current) |
|---|
| 118 | 124 | throw new Error( |
|---|
| .. | .. |
|---|
| 126 | 132 | } |
|---|
| 127 | 133 | |
|---|
| 128 | 134 | /** |
|---|
| 129 | | - * Find the field by name or position |
|---|
| 130 | | - */ |
|---|
| 131 | | - this.getField = function(key) { |
|---|
| 132 | | - if (!_current) |
|---|
| 135 | + * Find the field by name or position |
|---|
| 136 | + */ |
|---|
| 137 | + this.getField = function(key, catalog) { |
|---|
| 138 | + catalog = catalog || _current; |
|---|
| 139 | + if (!catalog) |
|---|
| 133 | 140 | throw new Error( |
|---|
| 134 | 141 | 'There is no current catalog selected'); |
|---|
| 135 | 142 | var index = -1; |
|---|
| 136 | 143 | if (typeof key === 'string') { |
|---|
| 137 | | - for (var i = _current.fields.length - 1; i >= 0 |
|---|
| 138 | | - && _current.fields[i].name !== key; i--) |
|---|
| 144 | + for (var i = catalog.fields.length - 1; i >= 0 |
|---|
| 145 | + && catalog.fields[i].name !== key; i--) |
|---|
| 139 | 146 | ; |
|---|
| 140 | 147 | index = i; |
|---|
| 141 | 148 | } else { |
|---|
| .. | .. |
|---|
| 144 | 151 | } |
|---|
| 145 | 152 | |
|---|
| 146 | 153 | return index === -1 ? {} |
|---|
| 147 | | - : _current.fields[index]; |
|---|
| 154 | + : catalog.fields[index]; |
|---|
| 148 | 155 | } |
|---|
| 149 | 156 | |
|---|
| 150 | 157 | /*********************************************** |
|---|
| 151 | | - * Catalog resource operations on server * |
|---|
| 152 | | - **********************************************/ |
|---|
| 158 | + * Catalog resource operations on server * |
|---|
| 159 | + **********************************************/ |
|---|
| 153 | 160 | |
|---|
| 154 | 161 | function _success(response) { |
|---|
| 155 | 162 | console.log('$resource') |
|---|
| .. | .. |
|---|
| 214 | 221 | refs[field.name] = comboData; |
|---|
| 215 | 222 | }) |
|---|
| 216 | 223 | } |
|---|
| 217 | | - this.loadRefs = function(refs) { |
|---|
| 218 | | - if (!_current) |
|---|
| 219 | | - throw new Error( |
|---|
| 220 | | - 'There is no current catalog selected'); |
|---|
| 221 | | - var refsFields = []; |
|---|
| 222 | | - _current.fields.forEach(function(f) { |
|---|
| 223 | | - if (f.resource) |
|---|
| 224 | | - refsFields.push(f) |
|---|
| 225 | | - |
|---|
| 226 | | - }); |
|---|
| 224 | + this.loadRefs = function(refs, refsFields) { |
|---|
| 225 | + if (!refsFields || refsFields.length === 0) { |
|---|
| 226 | + if (!_current) |
|---|
| 227 | + throw new Error( |
|---|
| 228 | + 'There is no current catalog selected'); |
|---|
| 229 | + refsFields = []; |
|---|
| 230 | + _current.fields.forEach(function(f) { |
|---|
| 231 | + if (f.resource) |
|---|
| 232 | + refsFields.push(f) |
|---|
| 233 | + |
|---|
| 234 | + }); |
|---|
| 235 | + } |
|---|
| 227 | 236 | |
|---|
| 228 | 237 | var that = this; |
|---|
| 229 | 238 | var promises = [] |
|---|
| .. | .. |
|---|
| 238 | 247 | console.log('promises: ' + promises.length |
|---|
| 239 | 248 | + ' ') |
|---|
| 240 | 249 | console.log(promises) |
|---|
| 241 | | - $q |
|---|
| 242 | | - .all(promises) |
|---|
| 243 | | - .then( |
|---|
| 244 | | - function() { |
|---|
| 245 | | - |
|---|
| 246 | | - for ( var k in refs) { |
|---|
| 247 | | - var field = that |
|---|
| 248 | | - .getField(k); |
|---|
| 249 | | - var pk = that |
|---|
| 250 | | - .getPk(that |
|---|
| 251 | | - .getMetadata(field.resource)) |
|---|
| 252 | | - console |
|---|
| 253 | | - .log('PK field for ' |
|---|
| 254 | | - + k |
|---|
| 255 | | - + ' is ' |
|---|
| 256 | | - + pk) |
|---|
| 257 | | - var comboData = [] |
|---|
| 258 | | - refs[k] |
|---|
| 259 | | - .forEach(function( |
|---|
| 260 | | - row) { |
|---|
| 261 | | - console |
|---|
| 262 | | - .log('field.resource !== _current.resource: ' |
|---|
| 263 | | - + field.resource |
|---|
| 264 | | - + ' ' |
|---|
| 265 | | - + _current.resource) |
|---|
| 266 | | - comboData |
|---|
| 267 | | - .push({ |
|---|
| 268 | | - id : row[pk], |
|---|
| 269 | | - label : row.label |
|---|
| 270 | | - || row.name |
|---|
| 271 | | - || row.code |
|---|
| 272 | | - || row.first_name |
|---|
| 273 | | - + ' ' |
|---|
| 274 | | - + (row.last_name || '') |
|---|
| 275 | | - }); |
|---|
| 276 | | - }) |
|---|
| 277 | | - refs[k] = comboData; |
|---|
| 278 | | - console |
|---|
| 279 | | - .log('Ready for combo for ' |
|---|
| 280 | | - + k) |
|---|
| 281 | | - console |
|---|
| 282 | | - .log(comboData); |
|---|
| 283 | | - } |
|---|
| 284 | | - _current.fields |
|---|
| 285 | | - .forEach(function( |
|---|
| 286 | | - f) { |
|---|
| 287 | | - if (f.values) |
|---|
| 288 | | - refs[f.name] = f.values; |
|---|
| 289 | | - }); |
|---|
| 290 | | - }) |
|---|
| 250 | + $q.all(promises) |
|---|
| 251 | + .then(function() { |
|---|
| 252 | + for(var i in refsFields) { |
|---|
| 253 | + //for ( var k in refs) { |
|---|
| 254 | + var rf = refsFields[i]; |
|---|
| 255 | + var cat = that.getResource(rf.resource); |
|---|
| 256 | + var pk = that.getPk(that.getMetadata(rf.resource)) |
|---|
| 257 | + console.log('PK field for ' |
|---|
| 258 | + + rf.name |
|---|
| 259 | + + ' is ' |
|---|
| 260 | + + pk) |
|---|
| 261 | + var comboData = [] |
|---|
| 262 | + refs[rf.name].forEach(function(row) { |
|---|
| 263 | + comboData.push({ |
|---|
| 264 | + id : row[pk], |
|---|
| 265 | + label : row.label |
|---|
| 266 | + || row.name |
|---|
| 267 | + || row.code |
|---|
| 268 | + || row.first_name |
|---|
| 269 | + + ' ' |
|---|
| 270 | + + (row.last_name || '') |
|---|
| 271 | + }); |
|---|
| 272 | + }) |
|---|
| 273 | + refs[rf.name] = comboData; |
|---|
| 274 | + console.log('Ready for combo for ' + rf.name) |
|---|
| 275 | + console.log(comboData); |
|---|
| 276 | + } |
|---|
| 277 | + _current && _current.fields.forEach(function(f) { |
|---|
| 278 | + if (f.values) |
|---|
| 279 | + refs[f.name] = f.values; |
|---|
| 280 | + }); |
|---|
| 281 | + }) |
|---|
| 291 | 282 | |
|---|
| 292 | 283 | console.log(refs); |
|---|
| 293 | 284 | return refs; |
|---|
| .. | .. |
|---|
| 1 | 1 | (function() { |
|---|
| 2 | 2 | 'use strict'; |
|---|
| 3 | 3 | |
|---|
| 4 | + var HTTP_ERRORS = { |
|---|
| 5 | + 401: "Unathorized action", |
|---|
| 6 | + 403: "Forbidden action", |
|---|
| 7 | + 500: "Server error", |
|---|
| 8 | + 404: "Element not found" |
|---|
| 9 | + } |
|---|
| 10 | + |
|---|
| 4 | 11 | var app = angular.module('securis'); |
|---|
| 12 | + |
|---|
| 13 | + app.controller('PackAndLicensesCtrl', [ |
|---|
| 14 | + '$scope', |
|---|
| 15 | + '$http', |
|---|
| 16 | + 'toaster', |
|---|
| 17 | + '$store', |
|---|
| 18 | + '$L', |
|---|
| 19 | + 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 | + |
|---|
| 53 | + $scope.maxLengthErrorMsg = function(displayname, fieldMaxlength) { |
|---|
| 54 | + return $L.get("{0} length is too long (max: {1}).", $L.get(displayname), fieldMaxlength); |
|---|
| 55 | + } |
|---|
| 56 | + $scope.mandatoryFieldErrorMsg = function(displayname) { |
|---|
| 57 | + return $L.get("'{0}' is required.", $L.get(displayname)); |
|---|
| 58 | + } |
|---|
| 59 | + $scope.ellipsis = function(txt, len) { |
|---|
| 60 | + if (!txt || txt.length <= len) return txt; |
|---|
| 61 | + return txt.substring(0, len) + '...'; |
|---|
| 62 | + } |
|---|
| 63 | + $scope.currentPackId = $store.get('currentPackId'); |
|---|
| 64 | + |
|---|
| 65 | + }]); |
|---|
| 5 | 66 | |
|---|
| 6 | | - app.controller('LicensesCtrl', [ |
|---|
| 67 | + app.controller('PacksCtrl', [ |
|---|
| 7 | 68 | '$scope', |
|---|
| 8 | 69 | '$http', |
|---|
| 70 | + '$resource', |
|---|
| 9 | 71 | 'toaster', |
|---|
| 10 | 72 | 'Catalogs', |
|---|
| 11 | 73 | '$store', |
|---|
| 12 | 74 | '$L', |
|---|
| 13 | | - function($scope, $http, toaster, Catalogs, $store, $L) { |
|---|
| 14 | | - $scope.currentPack = $store.get('currentPack'); |
|---|
| 15 | | - $scope.packs = [ |
|---|
| 16 | | - {id: 1, |
|---|
| 17 | | - "organization_name": "BP-Spain", |
|---|
| 18 | | - "application_name": "CurisIntegrity", |
|---|
| 19 | | - "licensetype_code": "CIBS", |
|---|
| 20 | | - "code": "BP-SA-0001", |
|---|
| 21 | | - "licenses": 50, |
|---|
| 22 | | - "lic_available": 23}, |
|---|
| 23 | | - {id: 2, |
|---|
| 24 | | - "organization_name": "Exxon", |
|---|
| 25 | | - "application_name": "CurisData", |
|---|
| 26 | | - "licensetype_code": "CDL1", |
|---|
| 27 | | - "code": "EX-SA-0001", |
|---|
| 28 | | - "licenses": 1, |
|---|
| 29 | | - "lic_available": 0}, |
|---|
| 30 | | - {id: 3, |
|---|
| 31 | | - "organization_name": "Repsol S.A. empresa con nombre muy largo", |
|---|
| 32 | | - "application_name": "CurisData", |
|---|
| 33 | | - "licensetype_code": "CDL2", |
|---|
| 34 | | - "code": "RE-SA-0001", |
|---|
| 35 | | - "licenses": 5, |
|---|
| 36 | | - "lic_available": 2}, |
|---|
| 37 | | - {id: 4, |
|---|
| 38 | | - "organization_name": "BP-Spain", |
|---|
| 39 | | - "application_name": "CurisIntegrity v3.0", |
|---|
| 40 | | - "code": "BP-SA-0002", |
|---|
| 41 | | - "licensetype_code": "CISA", |
|---|
| 42 | | - "licenses": 150, |
|---|
| 43 | | - "lic_available": 13}, |
|---|
| 44 | | - ]; |
|---|
| 75 | + function($scope, $http, $resource, toaster, Catalogs, $store, $L) { |
|---|
| 76 | + var packResource = $resource('/pack/:packId', { |
|---|
| 77 | + packId : '@id' |
|---|
| 78 | + }); |
|---|
| 79 | + $scope.mandatory = { |
|---|
| 80 | + code: true, |
|---|
| 81 | + num_licenses: true, |
|---|
| 82 | + organization_id: true, |
|---|
| 83 | + license_type_id: true |
|---|
| 84 | + } |
|---|
| 85 | + $scope.maxlength = { |
|---|
| 86 | + code: 50, |
|---|
| 87 | + comments: 1024 |
|---|
| 88 | + } |
|---|
| 89 | + $scope.refs = {}; |
|---|
| 90 | + Catalogs.init().then(function() { |
|---|
| 91 | + Catalogs.loadRefs($scope.refs, [{resource: 'organization', name: 'organization_id'},{resource: 'licensetype', name: 'license_type_id'}]) |
|---|
| 92 | + }); |
|---|
| 45 | 93 | |
|---|
| 46 | | - $scope.licenses = [ |
|---|
| 47 | | - {id: 1, |
|---|
| 48 | | - "code": "BP-SA-001-AKSJMS234", |
|---|
| 49 | | - "user_fullname": "Johnny Belmonte", |
|---|
| 50 | | - "user_email": "jb@curisit.net", |
|---|
| 51 | | - "status": 3}, |
|---|
| 52 | | - {id: 2, |
|---|
| 53 | | - "code": "BP-SA-001-KAJSDHAJS", |
|---|
| 54 | | - "user_fullname": "Walter Simons", |
|---|
| 55 | | - "user_email": "ws@curisit.net", |
|---|
| 56 | | - "status": 1}, |
|---|
| 57 | | - {id: 3, |
|---|
| 58 | | - "code": "BP-SA-001-ASKDGHKA", |
|---|
| 59 | | - "user_fullname": "Frank Belmonte", |
|---|
| 60 | | - "user_email": "fb@curisit.net", |
|---|
| 61 | | - "status": 2}, |
|---|
| 62 | | - {id: 4, |
|---|
| 63 | | - "code": "BP-SA-001-BBBGGGG", |
|---|
| 64 | | - "user_fullname": "John Dalton", |
|---|
| 65 | | - "user_email": "jd@curisit.net", |
|---|
| 66 | | - "status": 3}, |
|---|
| 67 | | - {id: 5, |
|---|
| 68 | | - "code": "BP-SA-001-AKADNAJANA", |
|---|
| 69 | | - "user_fullname": "Walter Martins", |
|---|
| 70 | | - "user_email": "wm@curisit.net", |
|---|
| 71 | | - "status": 3}, |
|---|
| 72 | | - {id: 6, |
|---|
| 73 | | - "code": "BP-SA-001-AKANDAKS", |
|---|
| 74 | | - "user_fullname": "Joe Bolton", |
|---|
| 75 | | - "user_email": "jbol@curisit.net", |
|---|
| 76 | | - "status": 2} |
|---|
| 77 | | - ]; |
|---|
| 78 | | - |
|---|
| 94 | + // Used to create the form with the appropriate data |
|---|
| 95 | + $scope.isNew = undefined; |
|---|
| 79 | 96 | |
|---|
| 97 | + // Selected pack from listing |
|---|
| 98 | + // pack is the edited pack, in creation contains the data for the new pack |
|---|
| 99 | + $scope.pack = null; |
|---|
| 100 | + |
|---|
| 101 | + $scope.packs = packResource.query(); |
|---|
| 80 | 102 | |
|---|
| 81 | | - $scope.ellipsis = function(txt, len) { |
|---|
| 82 | | - if (!txt || txt.length <= len) return txt; |
|---|
| 83 | | - return txt.substring(0, len) + '...'; |
|---|
| 103 | + $scope.save = function() { |
|---|
| 104 | + var _success = function() { |
|---|
| 105 | + $scope.packs = packResource.query(); |
|---|
| 106 | + } |
|---|
| 107 | + packResource.save($scope.pack, _success) |
|---|
| 84 | 108 | } |
|---|
| 85 | 109 | |
|---|
| 86 | | - $scope.selectPack = function(pack) { |
|---|
| 87 | | - console.log('Pack selected: ' + JSON.stringify(pack)); |
|---|
| 88 | | - $scope.currentPack = pack; |
|---|
| 89 | | - $store.put('currentPack', pack); |
|---|
| 110 | + $scope.newPack = function() { |
|---|
| 111 | + $scope.isNew = true; |
|---|
| 112 | + $scope.showForm = true; |
|---|
| 113 | + $scope.pack = { |
|---|
| 114 | + num_licenses: 1, |
|---|
| 115 | + license_type_id: !$scope.refs.license_type_id || !$scope.refs.license_type_id.length ? null : $scope.refs.license_type_id[0].id, |
|---|
| 116 | + organization_id: !$scope.refs.organization_id || !$scope.refs.organization_id.length ? null : $scope.refs.organization_id[0].id |
|---|
| 117 | + } |
|---|
| 118 | + setTimeout(function() { |
|---|
| 119 | + $('#code').focus(); |
|---|
| 120 | + }, 0); |
|---|
| 121 | + } |
|---|
| 122 | + |
|---|
| 123 | + $scope.editPack = function(selectedPack) { |
|---|
| 124 | + $scope.isNew = false; |
|---|
| 125 | + $scope.showForm = true; |
|---|
| 126 | + $scope.pack = selectedPack; |
|---|
| 127 | + setTimeout(function() { |
|---|
| 128 | + $('#code').focus(); |
|---|
| 129 | + }, 0); |
|---|
| 130 | + } |
|---|
| 131 | + |
|---|
| 132 | + $scope.deletePack = function(selectedPack) { |
|---|
| 133 | + $scope.showForm = false; |
|---|
| 134 | + BootstrapDialog.confirm($L.get("The pack '{0}' will be deleted, are you sure?", selectedPack.code), function(result){ |
|---|
| 135 | + if(result) { |
|---|
| 136 | + var promise = packResource.remove({}, {id: selectedPack.id}).$promise; |
|---|
| 137 | + promise.then(function(data) { |
|---|
| 138 | + $scope.selectPack(null); |
|---|
| 139 | + $scope.packs = packResource.query(); |
|---|
| 140 | + toaster.pop('success', Catalogs.getName(), $L.get("Pack '{0}' deleted successfully", selectedPack.code)); |
|---|
| 141 | + },function(error) { |
|---|
| 142 | + console.log(error); |
|---|
| 143 | + toaster.pop('error', Catalogs.getName(), $L.get("Error deleting pack, reason: {0}. Details: {1}", $L.get(HTTP_ERRORS[error.status]), error.headers('X-SECURIS-ERROR')), 10000); |
|---|
| 144 | + }); |
|---|
| 145 | + } |
|---|
| 146 | + }); |
|---|
| 147 | + $scope.isNew = false; |
|---|
| 148 | + } |
|---|
| 149 | + |
|---|
| 150 | + |
|---|
| 151 | + $scope.cancel = function() { |
|---|
| 152 | + $scope.showForm = false; |
|---|
| 153 | + } |
|---|
| 154 | + |
|---|
| 155 | + $scope.selectPack = function(packId) { |
|---|
| 156 | + $scope.$parent.currentPackId = packId; |
|---|
| 157 | + $store.put('currentPackId', packId); |
|---|
| 90 | 158 | } |
|---|
| 91 | 159 | |
|---|
| 92 | 160 | } ]); |
|---|
| .. | .. |
|---|
| 53 | 53 | }); |
|---|
| 54 | 54 | $routeProvider.when('/licenses', { |
|---|
| 55 | 55 | templateUrl: 'licenses.html', |
|---|
| 56 | | - controller: 'LicensesCtrl' |
|---|
| 56 | + controller: 'PackAndLicensesCtrl' |
|---|
| 57 | 57 | }); |
|---|
| 58 | 58 | $routeProvider.when('/admin', { |
|---|
| 59 | 59 | templateUrl: 'admin.html', |
|---|
| .. | .. |
|---|
| 3 | 3 | |
|---|
| 4 | 4 | <div class="container"> |
|---|
| 5 | 5 | <div class="col-md-12"> </div> |
|---|
| 6 | | - <div id="packs_section" class="col-md-6"> |
|---|
| 6 | + <div id="packs_section" class="col-md-6" ng-controller="PacksCtrl"> |
|---|
| 7 | 7 | <nav class="navbar navbar-default navbar-static-top"> |
|---|
| 8 | 8 | <!-- Brand and toggle get grouped for better mobile display --> |
|---|
| 9 | 9 | <div class="navbar-header"> |
|---|
| .. | .. |
|---|
| 14 | 14 | <div class="collapse navbar-collapse" |
|---|
| 15 | 15 | id="bs-example-navbar-collapse-1"> |
|---|
| 16 | 16 | <ul class="nav navbar-nav"> |
|---|
| 17 | | - <li><a i18n ng-click="editNew()"><span class="glyphicon glyphicon-plus"></span> |
|---|
| 17 | + <li><a i18n ng-click="newPack()"><span class="glyphicon glyphicon-plus"></span> |
|---|
| 18 | 18 | New</a></li> |
|---|
| 19 | 19 | <li><a i18n ng-click="cancel()"> <span |
|---|
| 20 | 20 | class="glyphicon glyphicon-ban-circle"></span> Cancel |
|---|
| .. | .. |
|---|
| 23 | 23 | <div class="navbar-form navbar-right"> |
|---|
| 24 | 24 | <div class="input-group input-group-sm"> |
|---|
| 25 | 25 | <span class="input-group-addon glyphicon glyphicon-search" style="top: 0px;"></span> |
|---|
| 26 | | - <input type="text" class="form-control" placeholder="Search" ng-model="$parent.searchText" > |
|---|
| 27 | | - <span class="btn input-group-addon glyphicon glyphicon-remove" ng-click="$parent.searchText = ''" style="top: 0px;"></span> |
|---|
| 26 | + <input type="text" class="form-control" placeholder="Search" ng-model="searchText" > |
|---|
| 27 | + <span class="btn input-group-addon glyphicon glyphicon-remove" ng-click="searchText = ''" style="top: 0px;"></span> |
|---|
| 28 | 28 | </div> |
|---|
| 29 | 29 | </div> |
|---|
| 30 | 30 | </div> |
|---|
| 31 | 31 | </nav> |
|---|
| 32 | + |
|---|
| 33 | + <div class="panel panel-default animate-show ng-hide" ng-show="showForm"> |
|---|
| 34 | + <form role="form" class="form-horizontal " name="packForm" id="packForm" ng-submit="save()" > |
|---|
| 35 | + <div class="form-group" ng-if="!isNew"> |
|---|
| 36 | + <label class="col-md-3 control-label" >ID</label> |
|---|
| 37 | + <div class="col-md-8"> |
|---|
| 38 | + <p class="form-control-static" ng-bind="pack.id"></p> |
|---|
| 39 | + </div> |
|---|
| 40 | + </div> |
|---|
| 41 | + <div class="form-group" > |
|---|
| 42 | + <label class="col-md-3 control-label" for="code" i18n>Code</label> |
|---|
| 43 | + <div class="col-md-8"> |
|---|
| 44 | + <input type="string" id="code" name="code" placeholder="" class="form-control" ng-model="pack.code" ng-required="mandatory.code" ng-maxlength="{{maxlength.code}}" /> |
|---|
| 45 | + <div class="alert inline-alert alert-warning" ng-show="packForm.code.$invalid"> |
|---|
| 46 | + <span class="glyphicon glyphicon-warning-sign"></span> |
|---|
| 47 | + <span ng-show="packForm.code.$error.maxlength" ng-bind="maxlengthErrorMsg('Code', maxlength.code)"></span> |
|---|
| 48 | + <span ng-show="packForm.code.$error.required" ng-bind="mandatoryFieldErrorMsg('Code')"></span> |
|---|
| 49 | + </div> |
|---|
| 50 | + </div> |
|---|
| 51 | + </div> |
|---|
| 52 | + |
|---|
| 53 | + <div class="form-group" > |
|---|
| 54 | + <label class="col-md-3 control-label" for="num_licenses" i18n>Num. Licenses</label> |
|---|
| 55 | + <div class="col-md-8"> |
|---|
| 56 | + <input type="number" id="num_licenses" name="num_licenses" placeholder="" class="form-control" ng-model="pack.num_licenses" ng-required="mandatory.num_licenses" /> |
|---|
| 57 | + <div class="alert inline-alert alert-warning" ng-show="packForm.num_licenses.$invalid"> |
|---|
| 58 | + <span class="glyphicon glyphicon-warning-sign"></span> |
|---|
| 59 | + <span ng-show="packForm.num_licenses.$error.maxlength" ng-bind="maxlengthErrorMsg('Num. Licenses', maxlength.num_licenses)"></span> |
|---|
| 60 | + <span ng-show="packForm.num_licenses.$error.required" ng-bind="mandatoryFieldErrorMsg('Num. Licenses')"></span> |
|---|
| 61 | + </div> |
|---|
| 62 | + </div> |
|---|
| 63 | + </div> |
|---|
| 64 | + |
|---|
| 65 | + <div class="form-group" > |
|---|
| 66 | + <label class="col-md-3 control-label" for="license_type_id" i18n>License type</label> |
|---|
| 67 | + <div class="col-md-8"> |
|---|
| 68 | + <select class="form-control" ng-required="mandatory.license_type_id" ng-model="pack.license_type_id" |
|---|
| 69 | + ng-options="o.id as o.label for o in refs.license_type_id" > |
|---|
| 70 | + <option selected="true" ng-if="!mandatory.license_type_id" value=""></option> |
|---|
| 71 | + </select> |
|---|
| 72 | + <div class="alert inline-alert alert-warning" ng-show="packForm.license_type_id.$invalid"> |
|---|
| 73 | + <span class="glyphicon glyphicon-warning-sign"></span> |
|---|
| 74 | + <span ng-show="packForm.license_type_id.$error.required" ng-bind="mandatoryFieldErrorMsg('License type')"></span> |
|---|
| 75 | + </div> |
|---|
| 76 | + </div> |
|---|
| 77 | + </div> |
|---|
| 78 | + |
|---|
| 79 | + <div class="form-group" > |
|---|
| 80 | + <label class="col-md-3 control-label" for="organization_id" i18n>Organization</label> |
|---|
| 81 | + <div class="col-md-8"> |
|---|
| 82 | + <select class="form-control" ng-required="field.mandatory" ng-model="pack.organization_id" |
|---|
| 83 | + ng-options="o.id as o.label for o in refs.organization_id" > |
|---|
| 84 | + <option selected="true" ng-if="!mandatory.organization_id" value=""></option> |
|---|
| 85 | + </select> |
|---|
| 86 | + <div class="alert inline-alert alert-warning" ng-show="packForm.organization_id.$invalid"> |
|---|
| 87 | + <span class="glyphicon glyphicon-warning-sign"></span> |
|---|
| 88 | + <span ng-show="packForm.organization_id.$error.required" ng-bind="mandatoryFieldErrorMsg('Organization')"></span> |
|---|
| 89 | + </div> |
|---|
| 90 | + </div> |
|---|
| 91 | + </div> |
|---|
| 92 | + |
|---|
| 93 | + |
|---|
| 94 | + <div class="form-group" > |
|---|
| 95 | + <label class="col-md-3 control-label" for="comments" i18n>Comments</label> |
|---|
| 96 | + <div class="col-md-8"> |
|---|
| 97 | + <textarea type="string" id="comments" name="comments" placeholder="" |
|---|
| 98 | + class="form-control" ng-model="pack.comments" rows="2" ng-required="mandatory.comments" ng-maxlength="{{maxlength.comments}}"></textarea> |
|---|
| 99 | + <div class="alert inline-alert alert-warning" ng-show="packForm.comments.$invalid"> |
|---|
| 100 | + <span class="glyphicon glyphicon-warning-sign"></span> |
|---|
| 101 | + <span ng-show="packForm.comments.$error.maxlength" ng-bind="maxlengthErrorMsg('Comments', maxlength.comments)"></span> |
|---|
| 102 | + <span ng-show="packForm.comments.$error.required" ng-bind="mandatoryFieldErrorMsg('comments')"></span> |
|---|
| 103 | + </div> |
|---|
| 104 | + </div> |
|---|
| 105 | + </div> |
|---|
| 106 | + |
|---|
| 107 | + <div class="form-group" ng-if="!isNew"> |
|---|
| 108 | + <label class="col-md-3 control-label" >Created by</label> |
|---|
| 109 | + <div class="col-md-8"> |
|---|
| 110 | + <p class="form-control-static" ng-bind="pack.created_by_name"></p> |
|---|
| 111 | + </div> |
|---|
| 112 | + </div> |
|---|
| 113 | + |
|---|
| 114 | + <div class="form-group" ng-if="!isNew"> |
|---|
| 115 | + <label class="col-md-3 control-label" >Creation date</label> |
|---|
| 116 | + <div class="col-md-8"> |
|---|
| 117 | + <p class="form-control-static" ng-bind="pack.creationTimestamp | date:'medium'"></p> |
|---|
| 118 | + </div> |
|---|
| 119 | + </div> |
|---|
| 120 | + |
|---|
| 121 | + <div class="form-group"> |
|---|
| 122 | + <div class="col-md-offset-3 col-md-10" id="saveContainer"> |
|---|
| 123 | + <button id="save" type="submit" class="btn btn-primary" > |
|---|
| 124 | + <span i18n class="glyphicon glyphicon-floppy-disk"></span> Save |
|---|
| 125 | + </button> |
|---|
| 126 | + </div> |
|---|
| 127 | + </div> |
|---|
| 128 | + </form> |
|---|
| 129 | + </div> |
|---|
| 130 | + |
|---|
| 131 | + |
|---|
| 32 | 132 | <div class="panel panel-default" > |
|---|
| 33 | 133 | <div class="panel-heading"> |
|---|
| 34 | 134 | Packs <span class="badge pull-right" ng-bind="packs.length || 0"></span> |
|---|
| .. | .. |
|---|
| 37 | 137 | <table class="table table-hover table-condensed"> |
|---|
| 38 | 138 | <thead> |
|---|
| 39 | 139 | <tr> |
|---|
| 140 | + <th i18n >Code</th> |
|---|
| 40 | 141 | <th i18n >Organization</th> |
|---|
| 41 | 142 | <th i18n >Application</th> |
|---|
| 42 | | - <th i18n >Code</th> |
|---|
| 43 | 143 | <th i18n >Licenses</th> |
|---|
| 44 | 144 | <th></th> |
|---|
| 45 | 145 | </tr> |
|---|
| 46 | 146 | </thead> |
|---|
| 47 | 147 | <tbody> |
|---|
| 48 | | - <tr ng-repeat="pack in packs | filter:searchText" ng-dblclick="editPack(row)" ng-class="{success: currentPack.id === pack.id}" ng-click="selectPack(pack)"> |
|---|
| 49 | | - <td ng-bind="ellipsis(pack.organization_name, 20)" title="{{pack.organization_name}}" ></td> |
|---|
| 50 | | - <td ng-bind="pack.application_name"></td> |
|---|
| 51 | | - <td style="white-space: nowrap;" ng-bind="pack.code"></td> |
|---|
| 52 | | - <td title="Total: {{pack.licenses}}, avaliable: {{pack.lic_available}}">{{pack.licenses}} ({{pack.lic_available}})</td> |
|---|
| 53 | | - <td><span ng-click="editPack(row)" |
|---|
| 148 | + <tr ng-repeat="p in packs | filter:searchText" ng-dblclick="editPack(p)" ng-class="{success: currentPackId === p.id}" ng-click="selectPack(p.id)"> |
|---|
| 149 | + <td style="white-space: nowrap;" ng-bind="p.code"></td> |
|---|
| 150 | + <td ng-bind="ellipsis(p.organization_name, 20)" title="{{pack.organization_name}}" ></td> |
|---|
| 151 | + <td ng-bind="p.application_name"></td> |
|---|
| 152 | + <td title="Total: {{p.num_licenses}}, available: {{p.num_available}}">{{p.num_licenses}} ({{p.num_available}})</td> |
|---|
| 153 | + <td><span ng-click="editPack(p)" |
|---|
| 54 | 154 | class="glyphicon glyphicon-pencil"></span> |
|---|
| 55 | | - <span ng-click="deletePack(row)" |
|---|
| 155 | + <span ng-click="deletePack(p)" |
|---|
| 56 | 156 | class="glyphicon glyphicon-remove"></span> |
|---|
| 57 | 157 | </td> |
|---|
| 58 | 158 | </tr> |
|---|
| .. | .. |
|---|
| 61 | 161 | </tfoot> |
|---|
| 62 | 162 | </table> |
|---|
| 63 | 163 | </div> |
|---|
| 64 | | - |
|---|
| 164 | + |
|---|
| 65 | 165 | </div> |
|---|
| 66 | 166 | |
|---|
| 67 | 167 | <div id="licenses_section" class="col-md-6" > |
|---|
| 68 | | - <nav class="navbar navbar-default navbar-static-top" ng-disabled="!!currentPack"> |
|---|
| 168 | + <nav class="navbar navbar-default navbar-static-top" ng-disabled="currentPackId === null"> |
|---|
| 69 | 169 | <!-- Brand and toggle get grouped for better mobile display --> |
|---|
| 70 | 170 | <div class="navbar-header success"> |
|---|
| 71 | 171 | <a class="navbar-brand" i18n>Licenses</a> |
|---|
| .. | .. |
|---|
| 91 | 191 | </div> |
|---|
| 92 | 192 | </nav> |
|---|
| 93 | 193 | |
|---|
| 94 | | - <div ng-if="!currentPack" class="well well-lg"> |
|---|
| 194 | + <div ng-if="currentPackId === null" class="well well-lg"> |
|---|
| 95 | 195 | <h4 i18n>No pack selected</h4> |
|---|
| 96 | 196 | <p i18n>Please, select a pack to manage its licenses</p> |
|---|
| 97 | 197 | </div> |
|---|
| 98 | 198 | |
|---|
| 99 | | - <div class="panel panel-default" ng-if="currentPack"> |
|---|
| 199 | + <div class="panel panel-default" ng-if="currentPackId !== null"> |
|---|
| 100 | 200 | <div class="panel-heading"> |
|---|
| 101 | 201 | <span i18n>Licenses for pack: </span>{{currentPack.code}} |
|---|
| 102 | 202 | <span style="color: lightgreen;" class="badge pull-right" ng-bind="currentPack.lic_available || 0"></span> |
|---|