1 43 package net.jforum.view.admin; 44 45 import net.jforum.dao.BannerDAO; 46 import net.jforum.dao.DataAccessDriver; 47 import net.jforum.entities.Banner; 48 import net.jforum.util.I18n; 49 import net.jforum.util.preferences.TemplateKeys; 50 51 57 public class BannerAction extends AdminCommand 58 { 59 public void list() throws Exception 61 { 62 this.context.put("banners", 63 DataAccessDriver.getInstance().newBannerDAO().selectAll()); 64 this.setTemplateName(TemplateKeys.BANNER_LIST); 65 } 66 67 public void insert() throws Exception 69 { 70 this.context.put("action", "insertSave"); 71 this.setTemplateName(TemplateKeys.BANNER_INSERT); 72 } 73 74 public void insertSave() throws Exception 76 { 77 BannerDAO dao = DataAccessDriver.getInstance().newBannerDAO(); 78 79 dao.addNew(getBanner()); 80 81 this.list(); 82 } 83 84 public void edit() throws Exception 86 { 87 int bannerId = this.request.getIntParameter("banner_id"); 88 BannerDAO dao = DataAccessDriver.getInstance().newBannerDAO(); 89 90 this.context.put("banner", dao.selectById(bannerId)); 91 this.setTemplateName(TemplateKeys.BANNER_EDIT); 92 this.context.put("action", "editSave"); 93 } 94 95 public void editSave() throws Exception 97 { 98 int bannerId = this.request.getIntParameter("banner_id"); 99 100 Banner banner = getBanner(); 101 banner.setId(bannerId); 102 103 DataAccessDriver.getInstance().newBannerDAO().update(banner); 104 105 this.list(); 106 } 107 108 public void delete() throws Exception 110 { 111 String bannerId = this.request.getParameter("banner_id"); 112 if(bannerId == null) 113 { 114 this.list(); 115 return; 116 } 117 118 BannerDAO dao = DataAccessDriver.getInstance().newBannerDAO(); 119 120 int id = Integer.parseInt(bannerId); 121 if(dao.canDelete(id)) 122 { 123 dao.delete(id); 124 } 125 else 126 { 127 this.context.put("errorMessage", 128 I18n.getMessage(I18n.CANNOT_DELETE_BANNER)); 129 } 130 131 this.list(); 132 } 133 134 protected Banner getBanner() 135 { 136 Banner b = new Banner(); 137 b.setComment(request.getParameter("comment")); 138 b.setActive(request.getIntParameter("active") == 1); 139 b.setType(Integer.parseInt(request.getParameter("type"))); 140 b.setName(request.getParameter("name")); 141 b.setDescription(request.getParameter("description")); 142 b.setWidth(Integer.parseInt(request.getParameter("width"))); 143 b.setHeight(Integer.parseInt(request.getParameter("height"))); 144 b.setUrl(request.getParameter("url")); 145 b.setPlacement(Integer.parseInt(request.getParameter( 146 "placement"))); 147 b.setWeight(Integer.parseInt(request.getParameter("weight"))); 148 b.setViews(Integer.parseInt(request.getParameter("views"))); 149 b.setClicks(Integer.parseInt(request.getParameter("clicks"))); 150 151 return b; 152 } 153 } 154 | Popular Tags |