diff --git a/src/main/java/haflow/dto/entity/Flow.java b/src/main/java/haflow/dto/entity/Flow.java index 4493eba..1e43d87 100644 --- a/src/main/java/haflow/dto/entity/Flow.java +++ b/src/main/java/haflow/dto/entity/Flow.java @@ -2,7 +2,7 @@ package haflow.dto.entity; import java.util.Set; import java.util.UUID; -import org.hibernate.annotations.Cascade; + import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; @@ -12,7 +12,6 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Table; -import javax.xml.bind.annotation.XmlElement; @Entity @Table(name = "flow") diff --git a/src/main/java/haflow/dto/entity/Portlet.java b/src/main/java/haflow/dto/entity/Portlet.java new file mode 100644 index 0000000..c719568 --- /dev/null +++ b/src/main/java/haflow/dto/entity/Portlet.java @@ -0,0 +1,70 @@ +package haflow.dto.entity; + +import java.util.UUID; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + +@Entity +@Table( name="portlet") +public class Portlet { + + private UUID id; + private String title; + private String type; + private int position; + + private Report report; + + @Id + @Column(name="id", length = 16) + public UUID getId() { + return id; + } + + public void setId(UUID id) { + this.id = id; + } + + @Column(name="title") + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + @Column(name="type") + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + @Column(name="position") + public int getPosition() { + return position; + } + + public void setPosition(int position) { + this.position = position; + } + + @ManyToOne + @JoinColumn(name="reportId",referencedColumnName="id") + public Report getReport() { + return report; + } + + public void setReport(Report report) { + this.report = report; + } + +} diff --git a/src/main/java/haflow/dto/entity/Report.java b/src/main/java/haflow/dto/entity/Report.java new file mode 100644 index 0000000..13cbd65 --- /dev/null +++ b/src/main/java/haflow/dto/entity/Report.java @@ -0,0 +1,79 @@ +package haflow.dto.entity; + +import java.util.Set; +import java.util.UUID; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; +import javax.persistence.Table; + +@Entity +@Table( name="report") +public class Report { + + private UUID id; + private String name; + private Report parent; + private boolean isDirectory; + private Set portlets; + private MainUser user; + + @Id + @Column(name = "id", length = 16) + public UUID getId() { + return id; + } + + public void setId(UUID id) { + this.id = id; + } + + @Column(name = "name") + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + + @ManyToOne + @JoinColumn(name="parentId", referencedColumnName="id") + public Report getParent() { + return parent; + } + public void setParent(Report parent) { + this.parent = parent; + } + + @Column(name="isDirectory") + public boolean isDirectory() { + return isDirectory; + } + public void setDirectory(boolean isDirectory) { + this.isDirectory = isDirectory; + } + + @OneToMany(mappedBy = "report", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER) + public Set getPortlets() { + return portlets; + } + public void setPortlets(Set portlets) { + this.portlets = portlets; + } + + @ManyToOne + @JoinColumn(name="ownerId",referencedColumnName="id") + public MainUser getUser() { + return user; + } + public void setUser(MainUser user) { + this.user = user; + } + +} diff --git a/src/main/java/haflow/service/ReportService.java b/src/main/java/haflow/service/ReportService.java new file mode 100644 index 0000000..5f6be1c --- /dev/null +++ b/src/main/java/haflow/service/ReportService.java @@ -0,0 +1,97 @@ +package haflow.service; + +import haflow.dto.entity.MainUser; +import haflow.dto.entity.Portlet; +import haflow.dto.entity.Report; +import haflow.util.SessionHelper; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.UUID; + +import org.hibernate.Query; +import org.hibernate.Session; +import org.hibernate.Transaction; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class ReportService { + + private SessionHelper sessionHelper; + + private SessionHelper getSessionHelper() { + return sessionHelper; + } + + @Autowired + private void setSessionHelper(SessionHelper sessionHelper) { + this.sessionHelper = sessionHelper; + } + + @SuppressWarnings("unchecked") + public List getReportList(int userid){ + Session session = this.getSessionHelper().openSession(); + Transaction transaction = session.beginTransaction(); + try{ + Query query = session.createQuery("select r from Report r where r.user.id =?"); + query.setInteger(0, userid); + List reports = (List) query.list(); + for(Report report : reports){ + System.out.println(report.getId()); + } + return reports; + }catch (Exception e) { + e.printStackTrace(); + transaction.rollback(); + return null; + } finally { + if (session != null) + session.close(); + } + } + + public boolean saveReport(UUID reportId, String name, boolean isDirectory, UUID parentId, Set portlets, + int userid) { + Session session = this.getSessionHelper().openSession(); + Transaction transaction = session.beginTransaction(); + try { + MainUser user = (MainUser) session.get(MainUser.class, userid); + Report report = (Report) session.get(Report.class, reportId); + Report parentReport = null; + if(parentId != null) + parentReport = (Report) session.get(Report.class, parentId); + if (report == null) { + report = new Report(); + report.setId(reportId); + + report.setPortlets(new HashSet()); + report.setUser(user); + } + + report.setName(name); + report.setDirectory(isDirectory); + report.setParent(parentReport); + report.getPortlets().clear(); + + for( Portlet portlet : portlets ){ + portlet.setReport(report); + session.merge(portlet); + report.getPortlets().add(portlet); + } + + session.merge(report); + + transaction.commit(); + return true; + } catch (Exception e) { + e.printStackTrace(); + transaction.rollback(); + return false; + } finally { + if (session != null) + session.close(); + } + } +} diff --git a/src/main/java/haflow/ui/controller/ReportController.java b/src/main/java/haflow/ui/controller/ReportController.java new file mode 100644 index 0000000..259d6f1 --- /dev/null +++ b/src/main/java/haflow/ui/controller/ReportController.java @@ -0,0 +1,56 @@ +package haflow.ui.controller; + +import haflow.ui.helper.ReportHelper; +import haflow.ui.model.ReportListModel; +import haflow.ui.model.SaveReportModel; +import haflow.ui.model.SaveReportResultModel; + +import java.util.UUID; + +import javax.servlet.http.HttpServletRequest; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; + +@Controller +@RequestMapping("/report") +public class ReportController { + + private ReportHelper reportHelper; + + @Autowired + private void setReportHelper(ReportHelper reportHelper) { + this.reportHelper = reportHelper; + } + + @RequestMapping(value = "/{reportId}", method = RequestMethod.PUT) + @ResponseBody + public SaveReportResultModel put(@PathVariable UUID reportId, + @RequestBody SaveReportModel model,HttpServletRequest request) { + System.out.println("save report"); + return this.reportHelper.saveReport(reportId, model,(Integer)request.getSession().getAttribute("userid")); + } + + @RequestMapping(method = RequestMethod.GET) + @ResponseBody + public ReportListModel get(HttpServletRequest request) { + int userid = (Integer)request.getSession().getAttribute("userid"); + ReportListModel reportListModel = this.reportHelper.getReportList(userid); + if( reportListModel.getReports().size() == 0){ + SaveReportModel model = new SaveReportModel(); + model.setId(UUID.randomUUID()); + model.setIsdirectory(true); + model.setName("Reports"); + model.setParentid(null); + model.setPortlets(null); + this.reportHelper.saveReport(model.getId(), model, userid); + reportListModel = this.reportHelper.getReportList(userid); + } + return reportListModel; + } +} diff --git a/src/main/java/haflow/ui/helper/ReportHelper.java b/src/main/java/haflow/ui/helper/ReportHelper.java new file mode 100644 index 0000000..59ef3e6 --- /dev/null +++ b/src/main/java/haflow/ui/helper/ReportHelper.java @@ -0,0 +1,100 @@ +package haflow.ui.helper; + +import haflow.dto.entity.Portlet; +import haflow.dto.entity.Report; +import haflow.service.ReportService; +import haflow.ui.model.PortletModel; +import haflow.ui.model.ReportListModel; +import haflow.ui.model.SaveReportModel; +import haflow.ui.model.SaveReportResultModel; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.UUID; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class ReportHelper { + + private ReportService reportService; + + public ReportService getReportService() { + return reportService; + } + + @Autowired + public void setReportService(ReportService reportService) { + this.reportService = reportService; + } + + public ReportListModel getReportList(int userid){ + List reports = this.reportService.getReportList(userid); + ReportListModel reportListModel = new ReportListModel(); + List reportModels = new ArrayList(); + for( Report report : reports ){ + SaveReportModel reportModel = new SaveReportModel(); + reportModel.setId(report.getId()); + reportModel.setIsdirectory(report.isDirectory()); + reportModel.setName(report.getName()); + if( report.getParent() != null){ + reportModel.setParentid(report.getParent().getId()); + }else{ + reportModel.setParentid(null); + } + + Set portletModels = new HashSet(); + for(Portlet portlet : report.getPortlets()){ + PortletModel portletModel = new PortletModel(); + portletModel.setId(portlet.getId()); + portletModel.setPosition(portlet.getPosition()); + portletModel.setReportId(portlet.getReport().getId()); + portletModel.setTitle(portlet.getTitle()); + portletModel.setType(portlet.getType()); + } + reportModel.setPortlets(portletModels); + reportModels.add(reportModel); + } + reportListModel.setReports(reportModels); + return reportListModel; + } + + public SaveReportResultModel saveReport(UUID reportId, SaveReportModel model,int userid) { + boolean success = this.doSaveReport(reportId, model, userid); + SaveReportResultModel result = new SaveReportResultModel(); + result.setFlowId(reportId); + result.setSuccess(success); + if (success) { + result.setMessage("success"); + } else { + result.setMessage("fail"); + } + return result; + } + + private boolean doSaveReport(UUID reportId, SaveReportModel model,int userid) { + Set portlets = new HashSet(); + if( model.getPortlets() != null){ + for( PortletModel portletModel : model.getPortlets()){ + if( !portletModel.getReportId().equals(reportId)){ + return false; + } + Portlet portlet = new Portlet(); + portlet.setId(portletModel.getId()); + portlet.setPosition(portletModel.getPosition()); + portlet.setTitle(portletModel.getTitle()); + portlet.setType(portletModel.getType()); + + portlets.add(portlet); + } + } + boolean result = true; + result = result + && this.getReportService().saveReport(reportId, model.getName(), model.getIsdirectory(), model.getParentid(), portlets, userid); + + return result; + } +} diff --git a/src/main/java/haflow/ui/model/PortletModel.java b/src/main/java/haflow/ui/model/PortletModel.java new file mode 100644 index 0000000..61513d6 --- /dev/null +++ b/src/main/java/haflow/ui/model/PortletModel.java @@ -0,0 +1,56 @@ +package haflow.ui.model; + +import java.util.UUID; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name="portlet") +public class PortletModel { + private UUID id; + private String title; + private String type; + private int position; + + private UUID reportId; + + @XmlElement + public UUID getId() { + return id; + } + public void setId(UUID id) { + this.id = id; + } + + @XmlElement + public String getTitle() { + return title; + } + public void setTitle(String title) { + this.title = title; + } + + @XmlElement + public String getType() { + return type; + } + public void setType(String type) { + this.type = type; + } + + @XmlElement + public int getPosition() { + return position; + } + public void setPosition(int position) { + this.position = position; + } + + @XmlElement + public UUID getReportId() { + return reportId; + } + public void setReportId(UUID reportId) { + this.reportId = reportId; + } +} diff --git a/src/main/java/haflow/ui/model/ReportListModel.java b/src/main/java/haflow/ui/model/ReportListModel.java new file mode 100644 index 0000000..78d1e25 --- /dev/null +++ b/src/main/java/haflow/ui/model/ReportListModel.java @@ -0,0 +1,22 @@ +package haflow.ui.model; + +import java.util.List; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement( name = "reportListModel") +public class ReportListModel { + private List reports; + + @XmlElementWrapper(name = "reports") + @XmlElement(name = "report") + public List getReports() { + return reports; + } + + public void setReports(List reports) { + this.reports = reports; + } +} diff --git a/src/main/java/haflow/ui/model/SaveReportModel.java b/src/main/java/haflow/ui/model/SaveReportModel.java new file mode 100644 index 0000000..5fb230f --- /dev/null +++ b/src/main/java/haflow/ui/model/SaveReportModel.java @@ -0,0 +1,60 @@ +package haflow.ui.model; + +import java.util.Set; +import java.util.UUID; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name="saveReport") +public class SaveReportModel { + private UUID id; + private String name; + private boolean isdirectory; + + private UUID parentid; + private Set portlets; + + @XmlElement + public UUID getId() { + return id; + } + public void setId(UUID id) { + this.id = id; + } + + @XmlElement + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + + @XmlElement + public boolean getIsdirectory() { + return isdirectory; + } + public void setIsdirectory(boolean isdirectory) { + this.isdirectory = isdirectory; + } + + @XmlElement + public UUID getParentid() { + return parentid; + } + public void setParentid(UUID parentid) { + this.parentid = parentid; + } + + @XmlElementWrapper(name="portlets") + @XmlElement( name="portlet") + public Set getPortlets() { + return portlets; + } + + public void setPortlets(Set portlets) { + this.portlets = portlets; + } +} diff --git a/src/main/java/haflow/ui/model/SaveReportResultModel.java b/src/main/java/haflow/ui/model/SaveReportResultModel.java new file mode 100644 index 0000000..7f80773 --- /dev/null +++ b/src/main/java/haflow/ui/model/SaveReportResultModel.java @@ -0,0 +1,38 @@ +package haflow.ui.model; + +import java.util.UUID; + +import javax.xml.bind.annotation.XmlRootElement; + +import com.sun.xml.internal.txw2.annotation.XmlElement; + +@XmlRootElement +public class SaveReportResultModel { + private boolean success; + private UUID flowId; + private String message; + + @XmlElement + public boolean isSuccess() { + return success; + } + public void setSuccess(boolean success) { + this.success = success; + } + + @XmlElement + public UUID getFlowId() { + return flowId; + } + public void setFlowId(UUID flowId) { + this.flowId = flowId; + } + + @XmlElement + public String getMessage() { + return message; + } + public void setMessage(String message) { + this.message = message; + } +} diff --git a/src/main/resources/hibernate.cfg.xml b/src/main/resources/hibernate.cfg.xml index 2fdcd58..f8913ee 100644 --- a/src/main/resources/hibernate.cfg.xml +++ b/src/main/resources/hibernate.cfg.xml @@ -21,6 +21,9 @@ + + + diff --git a/src/main/webapp/WEB-INF/views/main.jsp b/src/main/webapp/WEB-INF/views/main.jsp index 82031a9..871ed56 100644 --- a/src/main/webapp/WEB-INF/views/main.jsp +++ b/src/main/webapp/WEB-INF/views/main.jsp @@ -43,8 +43,8 @@ - + diff --git a/src/main/webapp/script/haflow.report.js b/src/main/webapp/script/haflow.report.js index baa6bd4..ad7e9d0 100644 --- a/src/main/webapp/script/haflow.report.js +++ b/src/main/webapp/script/haflow.report.js @@ -6,30 +6,41 @@ dojo.require("dojox.charting.axis2d.Default"); dojo.require("dojox.charting.plot2d.Columns"); dojo.require("dojo/fx/easing"); -HAFlow.Main.prototype.openReport = function(reportId){ - this.loadReport(reportId); -}; +//HAFlow.Main.prototype.openReport = function(reportId){ +// this.loadReport(reportId); +//}; HAFlow.Main.prototype.newReport = function(parentId) { var newReportId = HAFlow.generateUUID(); + this.newReportItem(newReportId, parentId, false); + this.openReport(newReportId); +}; + +HAFlow.Main.prototype.newReportDirectory = function(parentId) { + var newReportId = HAFlow.generateUUID(); + this.newReportItem(newReportId, parentId, true); +}; + +HAFlow.Main.prototype.newReportItem = function(newReportId, parentId, isdirectory){ this.reports[newReportId] = {}; this.reports[newReportId].id = newReportId; - this.reports[newReportId].name = "NewReport"; + this.reports[newReportId].name = "NewReport" + (isdirectory ? "Dir" : ""); + this.reports[newReportId].isdirectory = isdirectory; + this.reports[newReportId].parentid = parentId; this.reports[newReportId].portlets = new Array(); - this.loadReport(newReportId); - this.saveReport(newReportId);//save this.reports[newReportId] - this.reportListStore.put({ id : newReportId, name : this.reports[newReportId].name, - directory : false, + isdirectory : isdirectory, parent : parentId }); + + this.saveReport(newReportId);//save this.reports[newReportId] }; //private -HAFlow.Main.prototype.loadReport = function(reportId){ +HAFlow.Main.prototype.openReport = function(reportId){ var contentPane = dijit.byId("reportContainerPane_" + reportId);//mush be dijit.byId if( contentPane == null){ var currentReport = this.reports[reportId]; @@ -51,9 +62,22 @@ HAFlow.Main.prototype.loadReport = function(reportId){ }; - HAFlow.Main.prototype.saveReport = function(reportId){ - + var _currentInstance = this; + $.ajax({ + url : _currentInstance.basePath + "report/" + reportId, + type : "PUT", + dataType : "json", + contentType : "application/json", + data : JSON.stringify(_currentInstance.reports[reportId]),//reports??? + success : function(data, status) { + HAFlow.showDialog("Save Report", "Report saved."); + }, + error : function(request, status, error) { + HAFlow.showDialog("Error", "An error occurred while saving flow: " + + error + " status : " + status); + } + }); }; // public @@ -154,20 +178,24 @@ HAFlow.Main.prototype.onReportModuleAdded = function(currentInstance, reportId, var newPortletId = HAFlow.generateUUID(); if (reportModuleId == "text") { var currentPortlet = { - id: newPortletId, - title: reportModuleId, - report_id: reportId, - index: 1, - type: "text"}; + id: newPortletId, + title: reportModuleId, + type: "text", + position: 1, + + reportId: reportId, + }; this.reports[reportId].portlets.push(currentPortlet); this.addReport(reportId, currentPortlet); } else if (reportModuleId == "curve") { var currentPortlet = { id: newPortletId, title: reportModuleId, - report_id: reportId, - index: 1, - type: "curve"}; + type: "curve", + position: 1, + + reportId: reportId, + }; this.reports[reportId].portlets.push(currentPortlet); this.addReport(reportId, currentPortlet); } else { diff --git a/src/main/webapp/script/haflow.report_list.js b/src/main/webapp/script/haflow.report_list.js index 26a989b..973382a 100644 --- a/src/main/webapp/script/haflow.report_list.js +++ b/src/main/webapp/script/haflow.report_list.js @@ -5,19 +5,29 @@ HAFlow.Main.prototype.initReportList = function() { title: "Reports" }); this.ui.leadingContainer.addChild(reportListContentPane); - this.initReportListStore(); - this.getReportList(); - this.initReportListTree(); + + var _currentInstance = this; + $.ajax({ + url: this.basePath + "report", + type: "GET", + dataType: "json", + data: {}, + success: function(data, status) { + _currentInstance.initReportListStore(); + _currentInstance.fillReportListStore(data); + _currentInstance.fillReportsData(data); + _currentInstance.initReportListTree(); + }, + error: function(request, status, error) { + HAFlow.showDialog("Error", "An error occurred while loading flow list: " + error); + } + }); }; +//private HAFlow.Main.prototype.initReportListStore = function() { this.reportListStore = new dojo.store.Observable(new dojo.store.Memory({ - data: [{ - id: "reports", - name: "Reports", - directory: true, - parent: null - }], + data: [], getChildren: function(object) { return this.query({ parent: object.id @@ -26,53 +36,70 @@ HAFlow.Main.prototype.initReportListStore = function() { })); }; -HAFlow.Main.prototype.getReportList = function(path) { - var _currentInstance = this; -// $.ajax({ -// url: this.basePath + "report/list", -// type: "GET", -// dataType: "json", -// data: { -// path: path -// }, -// success: function(data, status) { -// _currentInstance.refreshHdfsFileList(data); -// }, -// error: function(request, status, error) { -// HAFlow.showDialog("Error", "An error occurred while loading flow list: " + error); -// } -// }); - var data = []; - data.reports = [{id: '1', name: 'root', parent: 'reports', directory: true}, - {id: '1223', name: '1223', parent: '1', directory: true}, - {id: '1224', name: '1224', parent: '1', directory: false}]; - _currentInstance.refreshReportList(data); -}; - -HAFlow.Main.prototype.refreshReportList = function(data) { - var _currentInstance = this; +HAFlow.Main.prototype.fillReportListStore = function(data) { for (var i = 0; i < data.reports.length; i++) { var dataItem = data.reports[i]; this.reportListStore.put({ id: dataItem.id, name: dataItem.name, - isDirectory: dataItem.directory, - parent: dataItem.parent, + isdirectory: dataItem.isdirectory, + parent: dataItem.parentid, }); -// if (data.files[i].directory) { -// instance.getHdfsFileList(parentPath + "/" + data.files[i].name); -// } } }; +HAFlow.Main.prototype.fillReportsData = function(data) { + for (var i = 0; i < data.reports.length; i++) { + var reportItem = data.reports[i]; + var reportItemId = reportItem.id; + this.reports[reportItemId] = {}; + this.reports[reportItemId].id = reportItemId; + this.reports[reportItemId].name = reportItem.name; + this.reports[reportItemId].isdirectory = reportItem.isdirectory; + this.reports[reportItemId].parentid = reportItem.parentid; + this.reports[reportItemId].portlets = new Array();//TODO + } +}; + +HAFlow.Main.prototype.checkReportItem = function(isDirectory, needsDirectory){ +// if( tn.isdirectory ){ +// _currentInstance.newReport(tn.item.id); +// }else{ +// HAFlow.showDialog("Error", "It's not a flow directory! "); +// } + + if( needsDirectory ){ + if( isDirectory){ + return true; + }else{ + HAFlow.showDialog("Error", "It's not a flow directory! "); + return false; + } + }else{ + if( isDirectory){ + HAFlow.showDialog("Error", "It's not a flow! "); + return false; + }else{ + return true; + } + } +}; + HAFlow.Main.prototype.initReportListTree = function() { + var rootId; + for(var i = 0; i < this.reportListStore.data.length; i++ ){ + if( this.reportListStore.data[i].parent == null){ + rootId = this.reportListStore.data[i].id; + break; + } + } var treeModel = new dijit.tree.ObjectStoreModel({ store: this.reportListStore, query: { - id: "reports" + id: rootId, }, mayHaveChildren: function(item) { - return item.isDirectory; + return item.isdirectory; } }); @@ -108,21 +135,33 @@ HAFlow.Main.prototype.initReportListTree = function() { id: "renameReportMenuItem", label: "Rename" }); + this.menu.reportTreeMenu.saveReportMenuItem = new dijit.MenuItem({ + id: "saveReportMenuItem", + label: "Save" + }); this.menu.reportTreeMenu.addChild(this.menu.reportTreeMenu.newReportMenuItem); this.menu.reportTreeMenu.addChild(this.menu.reportTreeMenu.newReportDirectoryMenuItem); this.menu.reportTreeMenu.addChild(this.menu.reportTreeMenu.deleteReportMenuItem); this.menu.reportTreeMenu.addChild(this.menu.reportTreeMenu.renameReportMenuItem); + this.menu.reportTreeMenu.addChild(this.menu.reportTreeMenu.saveReportMenuItem); dojo.connect(this.menu.reportTreeMenu.newReportMenuItem, "onClick", function() { - var tn = dijit.byNode(this.getParent().currentTarget); + var tn = dijit.byNode(this.getParent().currentTarget); + var checkResult = _currentInstance.checkReportItem(tn.item.isdirectory, true); + if( checkResult ){ _currentInstance.newReport(tn.item.id); - }); + } + }); dojo.connect(this.menu.reportTreeMenu.newReportDirectoryMenuItem, "onClick", function() { - - }); + var tn = dijit.byNode(this.getParent().currentTarget); + var checkResult = _currentInstance.checkReportItem(tn.item.isdirectory, true); + if( checkResult ){ + _currentInstance.newReportDirectory(tn.item.id); + } + }); dojo.connect(this.menu.reportTreeMenu.deleteReportMenuItem, "onClick", function() { @@ -131,25 +170,29 @@ HAFlow.Main.prototype.initReportListTree = function() { function() { }); + dojo.connect(this.menu.reportTreeMenu.saveReportMenuItem, "onClick", + function() { + var tn = dijit.byNode(this.getParent().currentTarget); + var checkResult = _currentInstance.checkReportItem(tn.item.isdirectory, false); + if( checkResult ){ + _currentInstance.saveReport(tn.item.id); + } + }); this.menu.reportTreeMenu.startup(); - tree.on("click", - function(item) { - if (item.directory != "true") { - var information = []; - information.id = item.id; - information.name = item.name; - _currentInstance.onReportClicked(_currentInstance, information); - } - }, - true); + tree.on("click", function(item) { + var information = []; + information.id = item.id; + information.name = item.name; + _currentInstance.onReportClicked(_currentInstance, information); + }, true); var picture = new RegExp("^[A-Za-z0-9_]*\.jpg$"); var text = new RegExp("^[A-Za-z0-9_]*\.(txt|ini)$"); var csv = new RegExp("^[A-Za-z0-9_-]*\.csv$"); tree.on("dblclick", function(reportItem) { - if (reportItem.isDirectory != true) { + if (!reportItem.isdirectory) { _currentInstance.openReport(reportItem.id); } },