1 13 package info.magnolia.module.workflow.inbox; 14 15 import info.magnolia.cms.beans.config.MIMEMapping; 16 import info.magnolia.cms.gui.control.ContextMenu; 17 import info.magnolia.cms.gui.control.ContextMenuItem; 18 import info.magnolia.cms.gui.control.FunctionBar; 19 import info.magnolia.cms.gui.control.FunctionBarItem; 20 import info.magnolia.cms.gui.controlx.list.ListColumn; 21 import info.magnolia.cms.gui.controlx.list.ListControl; 22 import info.magnolia.cms.gui.controlx.list.ListModel; 23 import info.magnolia.cms.i18n.Messages; 24 import info.magnolia.cms.i18n.MessagesManager; 25 import info.magnolia.cms.util.AlertUtil; 26 import info.magnolia.cms.util.DateUtil; 27 import info.magnolia.cms.util.FreeMarkerUtil; 28 import info.magnolia.cms.util.NodeDataUtil; 29 import info.magnolia.context.MgnlContext; 30 import info.magnolia.module.admininterface.lists.AbstractList; 31 import info.magnolia.module.admininterface.lists.AdminListControlRenderer; 32 import info.magnolia.module.workflow.WorkflowConstants; 33 import info.magnolia.module.workflow.WorkflowUtil; 34 35 import java.text.ParseException ; 36 import java.text.SimpleDateFormat ; 37 import java.util.Date ; 38 39 import javax.servlet.http.HttpServletRequest ; 40 import javax.servlet.http.HttpServletResponse ; 41 42 import org.apache.commons.lang.ObjectUtils; 43 import org.apache.commons.lang.StringUtils; 44 45 46 50 public class Inbox extends AbstractList { 51 52 55 private String flowItemId; 56 57 60 private String comment; 61 62 65 private boolean debug = false; 66 67 protected Messages msgs = MessagesManager.getMessages("info.magnolia.module.workflow.messages"); 68 69 74 public Inbox(String name, HttpServletRequest request, HttpServletResponse response) { 75 super(name, request, response); 76 } 77 78 81 public ListModel getModel() { 82 return new InboxListModel(MgnlContext.getUser().getName()); 83 } 84 85 88 public void configureList(ListControl list) { 89 90 list.setRenderer(new AdminListControlRenderer() { 92 93 public String onSelect(ListControl list, Integer index) { 94 95 String customEditDialog = ObjectUtils.toString(list 96 .getIteratorValue(WorkflowConstants.ATTRIBUTE_EDIT_DIALOG)); 97 98 String editDialog = StringUtils.defaultIfEmpty(customEditDialog, WorkflowConstants.DEFAULT_EDIT_DIALOG); 99 String repository = ObjectUtils.toString(list.getIteratorValue("repository")); 100 String path = ObjectUtils.toString(list.getIteratorValue("path")); 101 102 StringBuffer js = new StringBuffer (); 103 js.append("mgnl.owfe.Inbox.current = {"); 104 js.append("id : '").append(list.getIteratorValue("id")).append("',"); 105 js.append("path : '").append(path).append("',"); 106 js.append("version : '").append(list.getIteratorValue("version")).append("',"); 107 js.append("repository : '").append(repository).append("',"); 108 js.append("workItemPath : '").append(list.getIteratorValue("workItemPath")).append("',"); 109 js.append("editDialog : '").append(editDialog).append("'"); 110 js.append("};"); 111 js.append("mgnl.owfe.Inbox.show = ").append(getShowJSFunction(repository, path)).append(";"); 112 js.append(super.onSelect(list, index)); 113 return js.toString(); 114 } 115 116 public String onDblClick(ListControl list, Integer index) { 117 return "mgnl.owfe.Inbox.edit();"; 118 } 119 }); 120 121 list.addSortableField("lastModified"); 122 list.addGroupableField("repository"); 123 list.addGroupableField("workflow"); 124 125 list.addColumn(new ListColumn() { 126 127 { 128 setName("icon"); 129 setLabel(""); 130 setWidth("25px"); 131 setSeparator(false); 132 } 133 134 public Object getValue() { 135 String path = "" + this.getListControl().getIteratorValue("path"); 136 String repository = "" + this.getListControl().getIteratorValue("repository"); 137 return "<img SRC=\"" 138 + MgnlContext.getContextPath() 139 + "/" 140 + getIcon(repository, path) 141 + "\" alt=\"\" border=\"0\" />"; 142 } 143 }); 144 list.addColumn(new ListColumn("name", msgs.get("inbox.item"), "100px", true)); 145 list.addColumn(new ListColumn("repository", msgs.get("inbox.repository"), "100", true)); 146 list.addColumn(new ListColumn("workflow", msgs.get("inbox.workflow"), "100", true)); 147 list.addColumn(new ListColumn("comment", msgs.get("inbox.comment"), "200", true)); 148 list.addColumn(new ListColumn() { 149 150 { 151 setName("lastModified"); 152 setLabel(msgs.get("inbox.date")); 153 setWidth("100"); 154 } 155 156 public Object getValue() { 157 String str = (String ) super.getValue(); 158 Date date = null; 159 try { 160 date = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ssZ").parse(str); 161 return DateUtil.formatDateTime(date); 162 163 } 164 catch (ParseException e) { 165 return StringUtils.EMPTY; 166 } 167 } 168 }); 169 170 } 171 172 protected String getIcon(String repository, String path) { 173 if (StringUtils.equals(repository, "website")) { 174 return ".resources/icons/16/document_plain_earth.gif"; 175 } 176 if (StringUtils.equals(repository, "dms")) { 177 String type = NodeDataUtil.getString(repository, path + "/type"); 178 return MIMEMapping.getMIMETypeIcon(type); 179 } 180 181 return ".resources/icons/16/mail.gif"; 182 } 183 184 protected String getShowJSFunction(String repository, String path) { 185 return "mgnl.owfe.Inbox.showFunctions." + repository; 186 } 187 188 191 public void configureContextMenu(ContextMenu menu) { 192 ContextMenuItem edit = new ContextMenuItem("edit"); 193 edit.setLabel(msgs.get("inbox.edit")); 194 edit.setOnclick("mgnl.owfe.Inbox.edit();"); 195 edit.setIcon(MgnlContext.getContextPath() + "/.resources/icons/16/mail_write.gif"); 196 edit.addJavascriptCondition("{test: function(){return mgnl.owfe.Inbox.current.id!=null}}"); 197 198 ContextMenuItem show = new ContextMenuItem("show"); 199 show.setLabel(msgs.get("inbox.show")); 200 show.setOnclick("mgnl.owfe.Inbox.show();"); 201 show.setIcon(MgnlContext.getContextPath() + "/.resources/icons/16/note_view.gif"); 202 show.addJavascriptCondition("{test: function(){return mgnl.owfe.Inbox.current.id!=null}}"); 203 204 ContextMenuItem proceed = new ContextMenuItem("proceed"); 205 proceed.setLabel(msgs.get("inbox.proceed")); 206 proceed.setOnclick("mgnl.owfe.Inbox.proceed();"); 207 proceed.setIcon(MgnlContext.getContextPath() + "/.resources/icons/16/navigate_right2_green.gif"); 208 proceed.addJavascriptCondition("{test: function(){return mgnl.owfe.Inbox.current.id!=null}}"); 209 210 ContextMenuItem reject = new ContextMenuItem("reject"); 211 reject.setLabel(msgs.get("inbox.reject")); 212 reject.setOnclick("mgnl.owfe.Inbox.reject();"); 213 reject.setIcon(MgnlContext.getContextPath() + "/.resources/icons/16/navigate_left2_red.gif"); 214 reject.addJavascriptCondition("{test: function(){return mgnl.owfe.Inbox.current.id!=null}}"); 215 216 ContextMenuItem cancel = new ContextMenuItem("cancel"); 217 cancel.setLabel(msgs.get("inbox.cancel")); 218 cancel.setOnclick("mgnl.owfe.Inbox.cancel();"); 219 cancel.setIcon(MgnlContext.getContextPath() + "/.resources/icons/16/delete2.gif"); 220 cancel.addJavascriptCondition("{test: function(){return mgnl.owfe.Inbox.current.id!=null}}"); 221 222 menu.addMenuItem(edit); 223 menu.addMenuItem(null); 224 menu.addMenuItem(show); 225 menu.addMenuItem(null); 226 menu.addMenuItem(proceed); 227 menu.addMenuItem(reject); 228 menu.addMenuItem(null); 229 menu.addMenuItem(cancel); 230 } 231 232 235 public void configureFunctionBar(FunctionBar bar) { 236 ContextMenu menu = this.getContextMenu(); 237 bar.addMenuItem(new FunctionBarItem(menu.getMenuItemByName("edit"))); 238 bar.addMenuItem(null); 239 bar.addMenuItem(new FunctionBarItem(menu.getMenuItemByName("show"))); 240 bar.addMenuItem(null); 241 bar.addMenuItem(new FunctionBarItem(menu.getMenuItemByName("reject"))); 242 bar.addMenuItem(new FunctionBarItem(menu.getMenuItemByName("proceed"))); 243 bar.addMenuItem(null); 244 bar.addMenuItem(new FunctionBarItem(menu.getMenuItemByName("cancel"))); 245 } 246 247 250 public String onRender() { 251 return FreeMarkerUtil.process(this); 252 } 253 254 257 public String proceed() { 258 try { 259 WorkflowUtil.proceed(this.getFlowItemId(), WorkflowConstants.ACTION_PROCEED); 260 } 261 catch (Exception e) { 262 AlertUtil.setMessage("can't proceed:", e); 263 } 264 return this.show(); 265 } 266 267 270 public String reject() { 271 try { 272 WorkflowUtil.proceed(this.getFlowItemId(), WorkflowConstants.ACTION_REJECT, this.getComment()); 273 } 274 catch (Exception e) { 275 AlertUtil.setMessage("can't reject:", e); 276 } 277 return this.show(); 278 } 279 280 283 public String cancel() { 284 try { 285 WorkflowUtil.proceed(this.getFlowItemId(), WorkflowConstants.ACTION_CANCEL); 286 } 287 catch (Exception e) { 288 AlertUtil.setMessage("can't cancel:", e); 289 } 290 return this.show(); 291 } 292 293 296 public String getFlowItemId() { 297 return this.flowItemId; 298 } 299 300 303 public void setFlowItemId(String flowItemId) { 304 this.flowItemId = flowItemId; 305 } 306 307 310 public String getComment() { 311 return this.comment; 312 } 313 314 317 public void setComment(String comment) { 318 this.comment = comment; 319 } 320 321 324 public boolean isDebug() { 325 return this.debug; 326 } 327 328 331 public void setDebug(boolean debug) { 332 this.debug = debug; 333 } 334 335 } 336 | Popular Tags |