Skip to content
Browse files

WIP: Work on Sources

  • Loading branch information...
1 parent 3454201 commit eb299f8d1c884905d127e76ab9471bd381ac7d7b @ilaborie committed Mar 24, 2012
View
23 README.md
@@ -40,6 +40,17 @@ Should return the created/updated shelf
curl -XGET http://localhost:8080/org.ilaborie.pineneedles/rest/shelves
+### Sources
+
+Read on <http://localhost:8080/org.ilaborie.pineneedles/rest/sources>
+Update folder on <http://localhost:8080/org.ilaborie.pineneedles/rest/folders>
+Update links on <http://localhost:8080/org.ilaborie.pineneedles/rest/links>
+
+### Get Source
+### Get all Sources
+### Delete Source
+### Create/Update folder source
+### Create/Update link source
Ideas
-----
@@ -56,14 +67,24 @@ Ideas
### Administration
+* Add Breadcrumb: **Shelves > Shelf > Sources > Source**
+* Add a .label for source type: folder~warn link~info
+* Change source dialog title func(kind)
+* Focus on Source Dialog
+* Focus on Detail Shelf
+* Focus on Detail Source
+* Enter on Source dialog field
+
+* Handle exclude Pattern for Folder Sources
+* Handle Field info for links source textarea
+* Disable 'Update' btw if not changed
* Handle invalid field UI ?
* Allow Markdown as description formatting
### About
* Shiny HTML5 Canvas animation (pine cone fall, + rotating)
-
### Possible Background
<https://secure.flickr.com/photos/24557420@N05/3975359536/sizes/o/in/photostream/>
View
169 org.ilaborie.pineneedles/src/main/java/org/ilaborie/pineneedles/web/model/Folder.java
@@ -0,0 +1,169 @@
+package org.ilaborie.pineneedles.web.model;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlID;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * The Class Folder.
+ */
+@XmlRootElement(name="folder")
+public class Folder {
+
+ /** The id. */
+ @XmlID
+ @XmlAttribute
+ private String id;
+
+ /** The shelf id. */
+ @XmlAttribute
+ private String shelfId;
+
+ /** The name. */
+ @XmlAttribute
+ private String name;
+
+ /** The description. */
+ @XmlElement
+ private String description;
+
+ /** The recursive. */
+ @XmlElement
+ private boolean recursive;
+
+ /** The path. */
+ @XmlElement
+ private String path;
+
+ /**
+ * Instantiates a new folder.
+ */
+ public Folder() {
+ super();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ilaborie.pineneedles.web.model.ISource#getId()
+ */
+ /**
+ * Gets the id.
+ *
+ * @return the id
+ */
+ public String getId() {
+ return id;
+ }
+
+ /**
+ * Sets the id.
+ *
+ * @param id the new id
+ */
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ /**
+ * Gets the shelf id.
+ *
+ * @return the shelf id
+ */
+ public String getShelfId() {
+ return shelfId;
+ }
+
+ /**
+ * Sets the shelf id.
+ *
+ * @param shelfId the new shelf id
+ */
+ public void setShelfId(String shelfId) {
+ this.shelfId = shelfId;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ilaborie.pineneedles.web.model.ISource#getName()
+ */
+ /**
+ * Gets the name.
+ *
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the name.
+ *
+ * @param name the new name
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ilaborie.pineneedles.web.model.ISource#getDescription()
+ */
+ /**
+ * Gets the description.
+ *
+ * @return the description
+ */
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * Sets the description.
+ *
+ * @param description the new description
+ */
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ /**
+ * Checks if is recursive.
+ *
+ * @return true, if is recursive
+ */
+ public boolean isRecursive() {
+ return recursive;
+ }
+
+ /**
+ * Sets the recursive.
+ *
+ * @param recursive the new recursive
+ */
+ public void setRecursive(boolean recursive) {
+ this.recursive = recursive;
+ }
+
+ /**
+ * Gets the path.
+ *
+ * @return the path
+ */
+ public String getPath() {
+ return path;
+ }
+
+ /**
+ * Sets the path.
+ *
+ * @param path the new path
+ */
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+}
View
89 ...aborie.pineneedles/src/main/java/org/ilaborie/pineneedles/web/model/entity/LinkEntry.java
@@ -0,0 +1,89 @@
+package org.ilaborie.pineneedles.web.model.entity;
+
+import java.util.Set;
+
+import javax.persistence.ElementCollection;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlID;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * The Class LinkEntry.
+ */
+@Entity
+@XmlRootElement(name = "link")
+public class LinkEntry {
+
+ /** The id. */
+ @Id
+ @XmlID
+ @XmlAttribute
+ private String id;
+
+ /** The link. */
+ @XmlAttribute
+ private String link;
+
+ /** The tags. */
+ @XmlElement
+ @ElementCollection
+ private Set<String> tags;
+
+ /**
+ * Gets the id.
+ *
+ * @return the id
+ */
+ public String getId() {
+ return id;
+ }
+
+ /**
+ * Sets the id.
+ *
+ * @param id the new id
+ */
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ /**
+ * Gets the link.
+ *
+ * @return the link
+ */
+ public String getLink() {
+ return link;
+ }
+
+ /**
+ * Sets the link.
+ *
+ * @param link the new link
+ */
+ public void setLink(String link) {
+ this.link = link;
+ }
+
+ /**
+ * Gets the tags.
+ *
+ * @return the tags
+ */
+ public Set<String> getTags() {
+ return tags;
+ }
+
+ /**
+ * Sets the tags.
+ *
+ * @param tags the new tags
+ */
+ public void setTags(Set<String> tags) {
+ this.tags = tags;
+ }
+
+}
View
7 org.ilaborie.pineneedles/src/main/java/org/ilaborie/pineneedles/web/model/entity/Source.java
@@ -2,6 +2,8 @@
import javax.persistence.Entity;
import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
@@ -18,12 +20,13 @@
* The Class ShelfEntity.
*/
@Entity
+@Inheritance(strategy = InheritanceType.JOINED)
@XmlRootElement(name = "source")
@NamedQueries(@NamedQuery(name = Source.QUERY_FIND_BY_SHELF, query = "From Source s Where s.shelf = :shelf"))
public class Source implements ISource {
/** The Constant QUERY_FIND_ALL. */
- public static final String QUERY_FIND_BY_SHELF = "Source.bySlef";
+ public static final String QUERY_FIND_BY_SHELF = "Source.byShelf";
/** The id. */
@Id
@@ -43,7 +46,7 @@
@ManyToOne
@XmlIDREF
private Shelf shelf;
-
+
/*
* (non-Javadoc)
*
View
66 ...rie.pineneedles/src/main/java/org/ilaborie/pineneedles/web/model/entity/SourceFolder.java
@@ -0,0 +1,66 @@
+package org.ilaborie.pineneedles.web.model.entity;
+
+import javax.persistence.Entity;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * The Class ShelfEntity.
+ */
+@Entity
+@XmlRootElement(name = "folder")
+public class SourceFolder extends Source {
+
+ /** The recursive. */
+ @XmlAttribute
+ private boolean recursive;
+
+ /** The folder. */
+ @XmlElement
+ private String folder;
+
+ /**
+ * Instantiates a new source folder.
+ */
+ public SourceFolder() {
+ super();
+ }
+
+ /**
+ * Checks if is recursive.
+ *
+ * @return true, if is recursive
+ */
+ public boolean isRecursive() {
+ return recursive;
+ }
+
+ /**
+ * Sets the recursive.
+ *
+ * @param recursive the new recursive
+ */
+ public void setRecursive(boolean recursive) {
+ this.recursive = recursive;
+ }
+
+ /**
+ * Gets the folder.
+ *
+ * @return the folder
+ */
+ public String getFolder() {
+ return folder;
+ }
+
+ /**
+ * Sets the folder.
+ *
+ * @param folder the new folder
+ */
+ public void setFolder(String folder) {
+ this.folder = folder;
+ }
+
+}
View
38 ...orie.pineneedles/src/main/java/org/ilaborie/pineneedles/web/model/entity/SourceLinks.java
@@ -0,0 +1,38 @@
+package org.ilaborie.pineneedles.web.model.entity;
+
+import java.util.List;
+
+import javax.persistence.Entity;
+import javax.persistence.OneToMany;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * The Class ShelfEntity.
+ */
+@Entity
+@XmlRootElement(name = "links")
+public class SourceLinks extends Source {
+
+ /** The links. */
+ @OneToMany
+ private List<LinkEntry> links;
+
+ /**
+ * Gets the links.
+ *
+ * @return the links
+ */
+ public List<LinkEntry> getLinks() {
+ return links;
+ }
+
+ /**
+ * Sets the links.
+ *
+ * @param links the new links
+ */
+ public void setLinks(List<LinkEntry> links) {
+ this.links = links;
+ }
+
+}
View
131 org.ilaborie.pineneedles/src/main/java/org/ilaborie/pineneedles/web/rest/Folders.java
@@ -0,0 +1,131 @@
+package org.ilaborie.pineneedles.web.rest;
+
+import java.io.File;
+import java.util.UUID;
+
+import javax.ejb.Stateless;
+import javax.inject.Inject;
+import javax.persistence.EntityManager;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.core.UriInfo;
+
+import org.ilaborie.pineneedles.web.model.Folder;
+import org.ilaborie.pineneedles.web.model.Message;
+import org.ilaborie.pineneedles.web.model.entity.Shelf;
+import org.ilaborie.pineneedles.web.model.entity.SourceFolder;
+import org.slf4j.Logger;
+
+import com.google.common.base.Strings;
+
+/**
+ * The Class ShelfResource.
+ */
+@Path("folders")
+@Produces(MediaType.APPLICATION_JSON)
+@Consumes(MediaType.APPLICATION_JSON)
+@Stateless
+public class Folders {
+
+ /** The URI info. */
+ @Context
+ private UriInfo uriInfo;
+
+ /** The entity manager. */
+ @Inject
+ private EntityManager em;
+
+ /** The logger. */
+ @Inject
+ private Logger logger;
+
+ /**
+ * Creates the.
+ *
+ * @param entity the entity
+ * @return the shelf
+ */
+ @PUT
+ public Response createOrUpdate(Folder folder) {
+ logger.info("Folders#createOrUpdate() : {}", this.uriInfo.getAbsolutePath());
+
+ String id = folder.getId();
+ String shelfId = folder.getShelfId();
+ String name = folder.getName();
+ String description = folder.getDescription();
+ String path = folder.getPath();
+ boolean recursive = folder.isRecursive();
+
+ if (Strings.isNullOrEmpty(name)) {
+ return Response
+ .status(Response.Status.BAD_REQUEST)
+ .entity(new Message("'name' parameter must not be null"))
+ .build();
+ }
+ if (Strings.isNullOrEmpty(path)) {
+ return Response
+ .status(Response.Status.BAD_REQUEST)
+ .entity(new Message("'path' parameter must not be null"))
+ .build();
+ }
+ File file = new File(path);
+ if (!file.exists() || !file.isDirectory()) {
+ return Response
+ .status(Response.Status.BAD_REQUEST)
+ .entity(new Message("Folder does not exists: " + file))
+ .build();
+ }
+
+ // Clean fields
+ SourceFolder entity = new SourceFolder();
+ entity.setName(name.trim());
+ if (description != null) {
+ entity.setDescription(Strings.nullToEmpty(description.trim()));
+ }
+ entity.setRecursive(recursive);
+ entity.setFolder(file.getAbsolutePath());
+
+ try {
+ Shelf shelf = this.em.find(Shelf.class, shelfId);
+ if (shelf == null) {
+ return Response.status(Status.BAD_REQUEST)
+ .entity(new Message("Could not find the shelf: " + shelfId))
+ .build();
+ }
+
+ entity.setShelf(shelf);
+
+ Response response;
+ if (id == null) {
+ // Create
+ entity.setId(this.createId());
+ this.em.persist(entity);
+ response = Response.status(Status.CREATED).entity(entity).build();
+ } else {
+ // Update
+ entity.setId(id);
+ this.em.merge(entity);
+ response = Response.ok(entity).build();
+ }
+ return response;
+ } catch (Exception e) {
+ return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e).build();
+ }
+ }
+
+ /**
+ * Creates the id.
+ *
+ * @return the string
+ */
+ private String createId() {
+ return UUID.randomUUID().toString();
+ }
+
+}
View
77 org.ilaborie.pineneedles/src/main/java/org/ilaborie/pineneedles/web/rest/Sources.java
@@ -1,7 +1,6 @@
package org.ilaborie.pineneedles.web.rest;
import java.util.List;
-import java.util.UUID;
import javax.ejb.Stateless;
import javax.inject.Inject;
@@ -10,23 +9,20 @@
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
-import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriInfo;
import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.core.UriInfo;
import org.ilaborie.pineneedles.web.model.Message;
import org.ilaborie.pineneedles.web.model.entity.Shelf;
import org.ilaborie.pineneedles.web.model.entity.Source;
import org.slf4j.Logger;
-import com.google.common.base.Strings;
import com.google.common.collect.Lists;
/**
@@ -55,8 +51,9 @@
* @return the list
*/
@GET
- public List<Source> findByShelf(@QueryParam("shelf") String shelfId) {
- logger.info("Sources#FindAll() : {}", this.uriInfo.getAbsolutePath());
+ @Path("shelf/{id}")
+ public List<Source> findByShelf(@PathParam("id") String shelfId) {
+ logger.info("Sources#findByShelf() : {}", this.uriInfo.getAbsolutePath());
TypedQuery<Source> query = this.em.createNamedQuery(Source.QUERY_FIND_BY_SHELF, Source.class);
Shelf shelf = this.em.find(Shelf.class, shelfId);
@@ -105,74 +102,10 @@ public Response deleteById(@PathParam("id") String id) {
.entity(new Message("Could not find the source: " + id)).build();
}
this.em.remove(entity);
- return Response.ok("Source deleted: " + id).build();
+ return Response.ok(new Message("Source deleted: " + id)).build();
} catch (Exception e) {
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e).build();
}
}
- /**
- * Creates the.
- *
- * @param entity the entity
- * @return the shelf
- */
- @PUT
- @Path("{shelfId}")
- public Response createOrUpdate(@PathParam("shelfId") String shelfId, Source entity) {
- logger.info("Sources#createOrUpdate() : {}", this.uriInfo.getAbsolutePath());
-
- String name = entity.getName();
- String description = entity.getDescription();
-
- if (Strings.isNullOrEmpty(name)) {
- return Response
- .status(Response.Status.BAD_REQUEST)
- .entity(new Message("'name' parameter must not be null"))
- .build();
- }
-
- // Clean fields
- entity.setName(name.trim());
- if (description != null) {
- entity.setDescription(Strings.nullToEmpty(description.trim()));
- }
-
- try {
- Shelf shelf = this.em.find(Shelf.class, shelfId);
- if (shelf == null) {
- return Response.status(Status.BAD_REQUEST)
- .entity(new Message("Could not find the shelf: " + shelfId))
- .build();
- }
-
- entity.setShelf(shelf);
-
- Response response;
- if (entity.getId() == null) {
- // Create
- entity.setId(this.createId());
- this.em.persist(entity);
- response = Response.status(Status.CREATED).entity(entity).build();
- } else {
- // Update
- entity.setShelf(shelf);
- this.em.merge(entity);
- response = Response.ok(entity).build();
- }
- return response;
- } catch (Exception e) {
- return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e).build();
- }
- }
-
- /**
- * Creates the id.
- *
- * @return the string
- */
- private String createId() {
- return UUID.randomUUID().toString();
- }
-
}
View
BIN org.ilaborie.pineneedles/src/main/webapp/img/pine-code.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
81 org.ilaborie.pineneedles/src/main/webapp/index.html
@@ -153,21 +153,21 @@ <h4 class="alert-heading">{{title}}</h4>
</form>
<div class="span10 offset1">
<hr />
- <p><a href="#" id="btnAddSource" class="btn btn-primary">Add a new Source</a></p>
+ <p>
+ <div class="btn-group">
+ <button id="btnAddSource" class="btn btn-primary">Add a new Source</button>
+ <button class="btn dropdown-toggle btn-primary" data-toggle="dropdown">
+ <span class="caret"></span>
+ </button>
+ <ul class="dropdown-menu">
+ <li><a id="btnAddFolderSource" href="#">Folder Source</a></li>
+ <li><a id="btnAddLinksSource" href="#">Links Source</a></li>
+ </ul>
+ </div>
+ </p>
</div>
<div id="sources" class="span10 offset1">
- <div id="source-1" class="source">
- <h2>Source One</h2>
- <p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
- <a id="btnShowSource-1" class="btn showSource" href="#">View details &raquo;</a>
- <div class="pull-right"><a id="btnDelSource-1" class="btn btn-danger delSource" href="#"><i class="icon-trash icon-white"></i>&nbsp;Delete</a></div>
- </div>
- <div id="source-2" class="source">
- <h2>Source Two</h2>
- <p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
- <a id="btnShowSource-2" class="btn showSource" href="#">View details &raquo;</a>
- <div class="pull-right"><a id="btnDelSource-2" class="btn btn-danger delSource" href="#"><i class="icon-trash icon-white"></i>&nbsp;Delete</a></div>
- </div>
+ <!-- Fill by Javascript -->
</div>
</div>
</div>
@@ -179,18 +179,36 @@ <h4 class="alert-heading">{{title}}</h4>
<h3>Create a new Source</h3>
</div>
<div class="modal-body max-height">
+ <div id="source-create-type-container">
+ <label for="source-create-type" class="mandatory">Type</label>
+ <select id="source-create-type" name="source-create-type">
+ <option value="folders">Folder</option>
+ <option value="links">Links</option>
+ </select>
+ </div>
+
<label for="source-create-name" class="mandatory">Name</label>
<input type="text" value="" title="Name" name="name" id="source-create-name" required="required" placeholder="Source name"/>
+
<label for="source-create-description" >Description</label>
<textarea title="Description" name="description" id="source-create-description" placeholder="Source description...">
</textarea>
+
<hr />
- <label for="source-create-folder" class="mandatory">Folder</label>
- <input type="text" title="Folder" value="" name="source-create-folder" id="source-create-folder" placeholder="Folder to index"/>
- <br/>
- <label for="source-recursif" class="checkbox" >
- <input type="checkbox" title="Recursif" name="source-recursif" id="source-create-recursif" /> Recursive
- </label>
+ <div id="source-folders-create-detail" class="hidden">
+ <label for="source-create-folder" class="mandatory">Folder</label>
+ <input type="text" title="Folder" value="" name="source-create-folder" id="source-create-folder" placeholder="Folder to index" />
+
+ <br/>
+ <label for="source-recursif" class="checkbox" >
+ <input type="checkbox" title="Recursif" name="source-recursif" id="source-create-recursif" /> Recursive
+ </label>
+ </div>
+ <div id="source-links-create-detail" class="hidden">
+ <label for="source-create-links" class="mandatory">Links</label>
+ <textarea title="Links" name="source-create-links" id="source-create-links" required="required" placeholder="Links...">
+ </textarea>
+ </div>
</div>
<div class="modal-footer">
<a id="btnCreateSource" href="#" class="btn btn-primary">Create</a>
@@ -209,14 +227,21 @@ <h4 class="alert-heading">{{title}}</h4>
<textarea title="Description" name="description" id="source-description" class="span9" placeholder="Source description...">
</textarea>
<hr />
- <!-- Special Folder source -->
- <label for="source-folder" class="mandatory">Folder</label>
- <input type="text" title="Folder" value="" name="source-folder-display" id="source-folder-field" class="span5"/>
-
- <label for="source-recursif" class="checkbox">
- <input type="checkbox" title="Recursif" name="source-recursif" id="source-recursif"/> Recursive
- </label>
- <!-- TODO includes, excludes -->
+ <div id="source-folder-detail" class="hidden">
+ <!-- Special Folder source -->
+ <label for="source-folder" class="mandatory">Folder</label>
+ <input type="text" title="Folder" value="" name="source-folder-display" id="source-folder-field" class="span5"/>
+
+ <label for="source-recursif" class="checkbox">
+ <input type="checkbox" title="Recursif" name="source-recursif" id="source-recursif"/> Recursive
+ </label>
+ <!-- TODO includes, excludes -->
+ </div>
+ <div id="source-folder-detail" class="hidden">
+ <label for="source-links" class="mandatory">Links</label>
+ <textarea title="Links" name="source-links" id="source-links" required="required" placeholder="Links...">
+ </textarea>
+ </div>
<div class="pull-right"><a id="btnSaveSource" class="btn btn-primary" href="#"></a></div>
</div>
</div>
@@ -255,7 +280,7 @@ <h4 class="alert-heading">{{title}}</h4>
</div> <!-- /container -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/libs/jquery-1.7.1.min.js"><\/script>')</script>
-
+
<script src="js/libs/bootstrap/bootstrap.min.js"></script>
<script src="js/libs/ICanHaz.min.js"></script>
View
210 org.ilaborie.pineneedles/src/main/webapp/js/script.js
@@ -30,21 +30,26 @@ $(document).ready(function() {
// Shelves Administration
$("#btnAddShelf").click(LocalGed.addShelf);
$("#btnBackShelves").click(LocalGed.backShelves);
+
$("#btnSaveShelf").click(LocalGed.saveShelf);
+ $("#btnCreateShelf").click(LocalGed.createShelf);
+
$("#shelf-create-name").keypress(LocalGed.handleCreateShelf);
$("#shelf-name").keypress(LocalGed.handleUpdateShelf);
- $("#btnCreateShelf").click(LocalGed.createShelf);
$("#diaNewShelf").on('shown', function() {
$("#shelf-create-name").focus();
});
// Sources Administration
$("#btnBackShelf").click(LocalGed.backShelf);
+
$("#btnAddSource").click(LocalGed.addSource);
- $(".showSource").click(LocalGed.showSource);
- $(".delSource").click(LocalGed.deleteSource);
- $("#btnCreateShelf").click(LocalGed.createSource);
- $("#btnSaveShelf").click(LocalGed.saveSource);
+ $("#btnAddFolderSource").click(LocalGed.addFolders);
+ $("#btnAddLinksSource").click(LocalGed.addLinks);
+ $("#source-create-type").change(LocalGed.changeSource)
+
+ $("#btnCreateSource").click(LocalGed.createSource);
+ $("#btnSaveSource").click(LocalGed.saveSource);
// Utilities
$("#diaConfirm").on('shown', function() {
@@ -116,7 +121,7 @@ LocalGed.handleSearch = function(e) {
* Launch search
*/
LocalGed.doSearch = function() {
- var query = $("#q").attr("value");
+ var query = $("#q").val();
// TODO rest get search/{query}
@@ -134,6 +139,8 @@ LocalGed.showShelf = function () {
var btn = $(this);
var id = btn.attr("id").substring("btnShowShelf-".length);
LocalGed.showDetailShelf(id);
+
+ LocalGed.loadSources(id);
};
/**
* Show Shelf creation dialog
@@ -201,9 +208,9 @@ LocalGed.deleteShelf = function() {
*/
LocalGed.saveShelf = function() {
var shelf = {};
- shelf.id = $("#shelf-update-id").attr("value");
- shelf.name = $("#shelf-name").attr("value");
- shelf.description = $("#shelf-description").attr("value");
+ shelf.id = $("#shelf-update-id").val();
+ shelf.name = $("#shelf-name").val();
+ shelf.description = $("#shelf-description").val();
// REST put shelf
var shelves = new RestServiceJs("rest/shelves");
@@ -232,8 +239,8 @@ LocalGed.handleUpdateShelf = function(e) {
*/
LocalGed.createShelf = function() {
var shelf = {};
- shelf.name = $("#shelf-create-name").attr("value");
- shelf.description = $("#shelf-create-description").attr("value");
+ shelf.name = $("#shelf-create-name").val();
+ shelf.description = $("#shelf-create-description").val();
var shelves = new RestServiceJs("rest/shelves");
shelves.put(shelf, function(json) {
@@ -262,7 +269,6 @@ LocalGed.loadShelves = function() {
shelves.findAll(function(json) {
// Refresh shelves
$("#shelves .row").empty();
- // TODO mustache.js
$.each(json, function(index,s){
var id = s.id;
@@ -282,7 +288,6 @@ LocalGed.loadShelves = function() {
LocalGed.shelf = null;
}
});
-
}
//Handle Sources Administration
@@ -302,12 +307,61 @@ LocalGed.showSource = function () {
LocalGed.showDetailSource(id);
};
/**
-* Create a new Source
-*/
-LocalGed.addSource = function () {
+ * Handle change source
+ */
+LocalGed.changeSource = function(e) {
+ var type = $("#source-create-type").val();
+ if (type=="folders") {
+ $("#source-folders-create-detail").removeClass("hidden");
+ $("#source-links-create-detail").addClass("hidden");
+ } else if (type=="links") {
+ $("#source-folders-create-detail").addClass("hidden");
+ $("#source-links-create-detail").removeClass("hidden");
+ } else {
+ $("#source-folders-create-detail").addClass("hidden");
+ $("#source-links-create-detail").addClass("hidden");
+ }
+}
+/**
+ * Create a new Source
+ */
+LocalGed.addSource = function (type) {
+ var kind = 'folders';
+ if(type=='folders' || type=='links') {
+ kind = type;
+ } else {
+ $("#source-create-type-container").removeClass("hidden");
+ }
+
+ // Update Select
+ $("#source-create-type").val(kind);
+ LocalGed.changeSource();
+
+ $("#source-create-type").removeClass("hidden");
+
+ $("#source-create-name").attr("value","");
+ $("#source-create-description").attr("value","");
+ $("#source-create-folder").attr("value","");
+ $("#source-recursif").attr("checked","checked");
+ $("#source-create-links").attr("value","");
+
$("#diaNewSource").modal('show');
};
/**
+ * Add a Folder Source
+ */
+LocalGed.addFolders = function (event) {
+ $("#source-create-type-container").addClass("hidden");
+ LocalGed.addSource("folders");
+}
+/**
+ * Add a Links Source
+ */
+LocalGed.addLinks = function (event) {
+ $("#source-create-type-container").addClass("hidden");
+ LocalGed.addSource("links");
+}
+/**
* Show source (new or existing)
* @param id the source id of false
*/
@@ -329,41 +383,98 @@ LocalGed.showDetailSource = function (id) {
var descr = $("#source-"+id+" p").text();
$("#source-description").attr("value",descr);
- // TODO REST get source/{id}
-
// Save button
$("#btnSaveSource").text("Update");
+
+ // REST get sources/{id}
+ var sources = new RestServiceJs("rest/sources");
+ sources.find(id, function(json) {
+ $("#source-name").attr("value",json.name);
+ $("#source-description").attr("value",json.description);
+
+ if (json.folder) {
+ $("#source-folder-detail").removeClass("hidden");
+ $("#source-links-detail").addClass("hidden");
+
+ $("#source-folder-display").attr("value",json.folder);
+ if(json.recursive) {
+ $("#source-recursif").attr("checked","checked");
+ } else {
+ $("#source-recursif").removeAttr("checked");
+ }
+ } else if (json.links) {
+ $("#source-folder-detail").addClass("hidden");
+ $("#source-links-detail").removeClass("hidden");
+
+ $("#source-links").attr("value",json.links);
+ }
+ });
};
/**
* Update the selected source
*/
LocalGed.saveSource = function() {
var src = {};
- src.id = $("#source-id").attr("value");
- src.name = $("#source-name").attr("value");
- src.description = $("#source-description").attr("value");
+ src.id = $("#source-id").val();
+ src.name = $("#source-name").val();
+ src.description = $("#source-description").val();
+ var isFolder = !$("#source-folder-detail").hasClass("hidden");
+
+
// Folder attributes
- src.folder = $("#source-folder").attr("value");
+ src.folder = $("#source-folder").val();
src.recursif = ("checked"==$("#source-recursif").attr("checked"));
- // TODO REST put source
- // TODO update field on OK
+ // REST put source
+ var sources;
+ if (isFolder) {
+ sources = new RestServiceJs("rest/folders");
+ } else {
+ sources = new RestServiceJs("rest/links");
+ }
+ sources.put(src, function(json) {
+ // update field on OK
+ $("#source-name").attr("value",json.name);
+ $("#source-description").attr("value",json.description)
+
+ LocalGed.notify("admin","success","Source updated");
+ });
};
/**
* Create a new source
*/
LocalGed.createSource = function() {
var src = {};
- src.name = $("#source-name").attr("value");
- src.description = $("#source-description").attr("value");
+ src.name = $("#source-create-name").val();
+ src.description = $("#source-create-description").val();
+ src.shelfId = LocalGed.shelf;
- // Folder attributes
- src.folder = $("#source-folder").attr("value");
- src.recursif = ("checked"==$("#source-recursif").attr("checked"));
-
- // TODO REST put source
- // TODO update field on OK
+ var type = $("#source-create-type").val();
+
+ var sources;
+ if (type=="folders") {
+ // Folder attributes
+ src.path = $("#source-create-folder").val();
+ if($("#source-create-recursif:checked").val()) {
+ src.recursive=true;
+ } else {
+ src.recursive=false;
+ }
+
+ sources = new RestServiceJs("rest/folders");
+ } else if (type=="links") {
+ src.links = $("#source-folder").val();
+
+ sources = new RestServiceJs("rest/links");
+ }
+
+ // REST put source
+ sources.put(src , function(json) {
+ $('#diaNewSource').modal('hide');
+ LocalGed.source = JSON.parse(json).id;
+ LocalGed.loadSources(LocalGed.shelf);
+ });
};
/**
* Delete a source
@@ -376,9 +487,42 @@ LocalGed.deleteSource = function() {
var msg = "Do you realy want to delete '" + name+"' ?";
LocalGed.doConfirm(msg, function() {
- // TODO REST delete shelf/{id}
+ var sources = new RestServiceJs("rest/sources");
+ sources.remove(id, function() {
+ // Display
+ $("#source-"+id).hide();
+ $("#source-"+id).detach();
+ });
});
};
+/**
+ * Load Shelf Sources
+ */
+LocalGed.loadSources = function(shelfId) {
+ var sources = new RestServiceJs("rest/sources/shelf");
+ sources.find(shelfId, function(json) {
+ // Refresh shelves
+ $("#sources").empty();
+ $.each(json, function(index,s){
+ var id = s.id;
+
+ var html= ich.source(s);
+ $("#sources").append(html);
+
+ // bind actions
+ $("#btnShowSource-"+id).click(LocalGed.showSource);
+ $("#btnDelSource-"+id).click(LocalGed.deleteSource);
+
+ // Display
+ $("#source-"+id).fadeIn();
+ });
+
+ if (LocalGed.source) {
+ $("#btnShowSource-"+LocalGed.source).focus();
+ LocalGed.source = null;
+ }
+ });
+}
// REST
function RestServiceJs(newurl) {

0 comments on commit eb299f8

Please sign in to comment.
Something went wrong with that request. Please try again.