Search in sources :

Example 1 with Author

use of com.joliciel.jochre.doc.Author in project jochre by urieli.

the class UpdateDocumentController method onClick$btnDeleteAuthor.

@Listen("onClick = #btnDeleteAuthor")
public void onClick$btnDeleteAuthor(Event event) {
    LOG.debug("onClick$btnDeleteAuthor()");
    try {
        if (lstAuthors.getSelectedItem() == null) {
            return;
        }
        Author author = (Author) lstAuthors.getSelectedItem().getValue();
        this.currentDoc.getAuthors().remove(author);
        ListModelList<Author> model = new ListModelList<Author>(this.currentDoc.getAuthors(), true);
        lstAuthors.setModel(model);
    } catch (Exception e) {
        LOG.error("Failure in onClick$btnDeleteAuthor", e);
        throw new RuntimeException(e);
    }
}
Also used : ListModelList(org.zkoss.zul.ListModelList) Author(com.joliciel.jochre.doc.Author) Listen(org.zkoss.zk.ui.select.annotation.Listen)

Example 2 with Author

use of com.joliciel.jochre.doc.Author in project jochre by urieli.

the class UpdateDocumentController method doAfterCompose.

@Override
public void doAfterCompose(Window window) throws Exception {
    super.doAfterCompose(window);
    Session session = Sessions.getCurrent();
    User user = (User) session.getAttribute(LoginController.SESSION_JOCHRE_USER);
    if (user == null)
        Executions.sendRedirect("login.zul");
    DocumentDao documentDao = DocumentDao.getInstance(jochreSession);
    List<Author> authors = documentDao.findAuthors();
    List<Comboitem> authorItems = cmbAuthors.getItems();
    for (Author author : authors) {
        Comboitem item = new Comboitem(author.getFullName());
        item.setValue(author.getId());
        authorItems.add(item);
    }
    lstAuthors.setItemRenderer(new AuthorListItemRenderer());
    winUpdateDocument.addEventListener("onModalOpen", new UpdateDocumentControllerModalListener());
}
Also used : AuthorListItemRenderer(com.joliciel.jochre.web.DocumentController.AuthorListItemRenderer) User(com.joliciel.jochre.security.User) Author(com.joliciel.jochre.doc.Author) Comboitem(org.zkoss.zul.Comboitem) DocumentDao(com.joliciel.jochre.doc.DocumentDao) JochreSession(com.joliciel.jochre.JochreSession) Session(org.zkoss.zk.ui.Session)

Example 3 with Author

use of com.joliciel.jochre.doc.Author in project jochre by urieli.

the class UpdateDocumentController method onClick$btnAddNewAuthor.

@Listen("onClick = #btnAddNewAuthor")
public void onClick$btnAddNewAuthor(Event event) {
    LOG.debug("onClick$btnAddNewAuthor");
    try {
        Author author = currentAuthor;
        boolean isNew = false;
        if (author == null) {
            author = new Author(jochreSession);
            isNew = true;
        }
        author.setFirstName(txtAuthorFirstName.getValue());
        author.setLastName(txtAuthorLastName.getValue());
        author.setFirstNameLocal(txtAuthorFirstNameLocal.getValue());
        author.setLastNameLocal(txtAuthorLastNameLocal.getValue());
        author.save();
        currentAuthor = null;
        txtAuthorFirstName.setValue("");
        txtAuthorLastName.setValue("");
        txtAuthorFirstNameLocal.setValue("");
        txtAuthorLastNameLocal.setValue("");
        btnAddNewAuthor.setLabel(Labels.getLabel("docs.documentDetails.addAuthor"));
        if (isNew) {
            DocumentDao documentDao = DocumentDao.getInstance(jochreSession);
            List<Author> authors = documentDao.findAuthors();
            List<Comboitem> authorItems = cmbAuthors.getItems();
            authorItems.clear();
            for (Author oneAuthor : authors) {
                Comboitem item = new Comboitem(oneAuthor.getFullName());
                item.setValue(oneAuthor.getId());
                authorItems.add(item);
                if (oneAuthor.getId() == author.getId())
                    cmbAuthors.setSelectedItem(item);
            }
        } else {
            ListModelList<Author> model = new ListModelList<Author>(this.currentDoc.getAuthors(), true);
            lstAuthors.setModel(model);
        }
    } catch (Exception e) {
        LOG.error("Failure in onClick$btnAddNewAuthor", e);
        throw new RuntimeException(e);
    }
}
Also used : ListModelList(org.zkoss.zul.ListModelList) Author(com.joliciel.jochre.doc.Author) Comboitem(org.zkoss.zul.Comboitem) DocumentDao(com.joliciel.jochre.doc.DocumentDao) Listen(org.zkoss.zk.ui.select.annotation.Listen)

Example 4 with Author

use of com.joliciel.jochre.doc.Author in project jochre by urieli.

the class DocumentController method doAfterCompose.

@Override
public void doAfterCompose(Window window) throws Exception {
    LOG.debug("doAfterCompose");
    super.doAfterCompose(window);
    String pageTitle = Labels.getLabel("docs.title");
    winJochreHome.getPage().setTitle(pageTitle);
    Session session = Sessions.getCurrent();
    currentUser = (User) session.getAttribute(LoginController.SESSION_JOCHRE_USER);
    if (currentUser == null)
        Executions.sendRedirect("login.zul");
    HttpServletRequest request = (HttpServletRequest) Executions.getCurrent().getNativeRequest();
    String docIdStr = request.getParameter("docId");
    if (docIdStr != null)
        docId = Integer.parseInt(docIdStr);
    String imageIdStr = request.getParameter("imageId");
    if (imageIdStr != null)
        imageId = Integer.parseInt(imageIdStr);
    docTree.setModel(this.getDocumentTree());
    lstAuthors.setModel(new ListModelArray<Author>(new Author[] {}, true));
    lstAuthors.setItemRenderer(new AuthorListItemRenderer());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Author(com.joliciel.jochre.doc.Author) JochreSession(com.joliciel.jochre.JochreSession) Session(org.zkoss.zk.ui.Session)

Example 5 with Author

use of com.joliciel.jochre.doc.Author in project jochre by urieli.

the class UpdateDocumentController method onClick$btnAddAuthor.

@Listen("onClick = #btnAddAuthor")
public void onClick$btnAddAuthor(Event event) {
    LOG.debug("onClick$btnAddAuthor");
    try {
        int authorId = 0;
        Comboitem selectedItem = cmbAuthors.getSelectedItem();
        if (selectedItem != null)
            authorId = (Integer) selectedItem.getValue();
        if (authorId != 0) {
            LOG.debug("authorId: " + authorId);
            DocumentDao documentDao = DocumentDao.getInstance(jochreSession);
            Author author = documentDao.loadAuthor(authorId);
            if (!this.currentDoc.getAuthors().contains(author)) {
                this.currentDoc.getAuthors().add(author);
                ListModelList<Author> model = new ListModelList<Author>(this.currentDoc.getAuthors(), true);
                lstAuthors.setModel(model);
            }
        }
    } catch (Exception e) {
        LOG.error("Failure in onClick$btnAddAuthor", e);
        throw new RuntimeException(e);
    }
}
Also used : ListModelList(org.zkoss.zul.ListModelList) Author(com.joliciel.jochre.doc.Author) Comboitem(org.zkoss.zul.Comboitem) DocumentDao(com.joliciel.jochre.doc.DocumentDao) Listen(org.zkoss.zk.ui.select.annotation.Listen)

Aggregations

Author (com.joliciel.jochre.doc.Author)5 DocumentDao (com.joliciel.jochre.doc.DocumentDao)3 Listen (org.zkoss.zk.ui.select.annotation.Listen)3 Comboitem (org.zkoss.zul.Comboitem)3 ListModelList (org.zkoss.zul.ListModelList)3 JochreSession (com.joliciel.jochre.JochreSession)2 Session (org.zkoss.zk.ui.Session)2 User (com.joliciel.jochre.security.User)1 AuthorListItemRenderer (com.joliciel.jochre.web.DocumentController.AuthorListItemRenderer)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1