Package com.psddev.cms.db

Examples of com.psddev.cms.db.ContentLock


    protected void doService(ToolPageContext page) throws IOException, ServletException {
        ToolUser user = page.getUser();
        Collection<String> includeFields = Arrays.asList("returnToDashboardOnSave");
        Object object = Query.from(Object.class).where("_id = ?", page.param(UUID.class, "id")).first();
        State state = State.getInstance(object);
        ContentLock contentLock = null;

        if (object != null) {
            contentLock = ContentLock.Static.lock(object, null, user);
        }

        if (page.isFormPost()) {
            if (page.param(String.class, "action-edits") != null) {
                if (state != null) {
                    Date newPublishDate = page.param(Date.class, "publishDate");

                    if (newPublishDate != null) {
                        Content.ObjectModification contentData = state.as(Content.ObjectModification.class);
                        DateTimeZone timeZone = page.getUserDateTimeZone();
                        newPublishDate = new Date(DateTimeFormat.
                                forPattern("yyyy-MM-dd HH:mm:ss").
                                withZone(timeZone).
                                parseMillis(new DateTime(newPublishDate).toString("yyyy-MM-dd HH:mm:ss")));

                        contentData.setPublishUser(page.getUser());
                        contentData.setPublishDate(newPublishDate);
                        state.save();
                    }
                }

            } else if (page.param(String.class, "action-unlock") != null) {
                contentLock.delete();

                page.writeStart("script", "type", "text/javascript");
                    page.writeRaw("window.location.reload();");
                page.writeEnd();

            } else if (page.param(String.class, "action-settings") != null) {
                try {
                    page.include("/WEB-INF/objectPost.jsp", "object", user, "includeFields", includeFields);
                    user.save();

                } catch (Exception error) {
                    page.getErrors().add(error);
                }
            }
        }

        String returnUrl = page.param(String.class, "returnUrl");

        page.writeHeader();
            page.writeStart("style", "type", "text/css");
                page.writeCss(".cms-contentTools th",
                        "width", "25%;");
            page.writeEnd();

            page.writeStart("div", "class", "widget cms-contentTools");
                page.writeStart("h1", "class", "icon icon-wrench");
                    page.writeHtml("Tools");
                page.writeEnd();

                page.writeStart("div", "class", "tabbed");
                    page.writeStart("div",
                            "class", "fixedScrollable",
                            "data-tab", "For Editors");
                        if (object != null) {
                            Content.ObjectModification contentData = state.as(Content.ObjectModification.class);
                            Date publishDate = contentData.getPublishDate();
                            ToolUser publishUser = contentData.getPublishUser();
                            Date updateDate = contentData.getUpdateDate();
                            ToolUser updateUser = contentData.getUpdateUser();

                            page.writeStart("table", "class", "table-striped");
                                page.writeStart("tbody");
                                    if (publishDate != null || publishUser != null) {
                                        page.writeStart("tr");
                                            page.writeStart("th");
                                                page.writeHtml("Published");
                                            page.writeEnd();

                                            page.writeStart("td");
                                                if (publishDate != null) {
                                                    page.writeHtml(page.formatUserDateTime(publishDate));
                                                }
                                            page.writeEnd();

                                            page.writeStart("td");
                                                if (publishUser != null) {
                                                    page.writeObjectLabel(publishUser);
                                                }
                                            page.writeEnd();
                                        page.writeEnd();
                                    }

                                    if (updateDate != null || updateUser != null) {
                                        page.writeStart("tr");
                                            page.writeStart("th");
                                                page.writeHtml("Last Updated");
                                            page.writeEnd();

                                            page.writeStart("td");
                                                if (updateDate != null) {
                                                    page.writeHtml(page.formatUserDateTime(updateDate));
                                                }
                                            page.writeEnd();

                                            page.writeStart("td");
                                                if (updateUser != null) {
                                                    page.writeObjectLabel(updateUser);
                                                }
                                            page.writeEnd();
                                        page.writeEnd();
                                    }
                                page.writeEnd();
                            page.writeEnd();

                            page.writeStart("h2");
                                page.writeHtml("Advanced Edits");
                            page.writeEnd();

                            if (page.isFormPost() &&
                                    page.param(String.class, "action-edits") != null) {
                                if (page.getErrors().isEmpty()) {
                                    page.writeStart("div", "class", "message message-success");
                                        page.writeHtml("Advanced edits successfully saved.");
                                    page.writeEnd();

                                } else {
                                    page.include("/WEB-INF/errors.jsp");
                                }
                            }

                            page.writeStart("form",
                                    "method", "post",
                                    "action", page.url(""));

                                page.writeStart("div", "class", "inputContainer");
                                    page.writeStart("div", "class", "inputLabel");
                                        page.writeStart("label", "for", page.createId());
                                            page.writeHtml("New Publish Date");
                                        page.writeEnd();
                                    page.writeEnd();

                                    page.writeStart("div", "class", "inputSmall");
                                        page.writeElement("input",
                                                "type", "text",
                                                "class", "date",
                                                "name", "publishDate",
                                                "value", page.formatUserDateTime(publishDate));
                                    page.writeEnd();
                                page.writeEnd();

                                page.writeStart("div", "class", "actions");
                                    page.writeStart("button",
                                            "class", "icon icon-action-save",
                                            "name", "action-edits",
                                            "value", true);
                                        page.writeHtml("Save");
                                    page.writeEnd();
                                page.writeEnd();
                            page.writeEnd();

                            if (!user.equals(contentLock.getOwner())) {
                                page.writeStart("h2");
                                    page.writeHtml("Content Lock");
                                page.writeEnd();

                                page.writeStart("div", "class", "message message-warning");
                                    page.writeStart("p");
                                        page.writeHtml("Locked by ");
                                        page.writeObjectLabel(contentLock.getOwner());
                                        page.writeHtml(" since ");
                                        page.writeHtml(page.formatUserDateTime(contentLock.getCreateDate()));
                                        page.writeHtml(".");
                                    page.writeEnd();
                                page.writeEnd();

                                page.writeStart("form",
View Full Code Here

TOP

Related Classes of com.psddev.cms.db.ContentLock

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.