MWF.xDesktop.requireApp("Meeting", "MeetingView", null, false); MWF.xApplication.Meeting.RoomView = new Class({ Extends: MWF.widget.Common, Implements: [Options, Events], options: { "style": "default" }, initialize: function(node, app, options){ this.setOptions(options); this.path = "/x_component_Meeting/$RoomView/"; this.cssPath = "/x_component_Meeting/$RoomView/"+this.options.style+"/css.wcss"; this._loadCss(); this.app = app; this.container = $(node); this.buildings = []; this.date = new Date(); this.hours = 1; this.load(); }, load: function(){ this.node = new Element("div", {"styles": this.css.node}).inject(this.container); this.roomArea = new Element("div", {"styles": this.css.roomArea}).inject(this.node); this.infoArea = new Element("div", {"styles": this.css.infoArea}).inject(this.node); this.roomDateArea = new Element("div", {"styles": this.css.roomDateArea}).inject(this.roomArea); this.roomBuildingsArea = new Element("div", {"styles": this.css.roomBuildingsArea}).inject(this.roomArea); this.resetNodeSize(); this.app.addEvent("resize", this.resetNodeSize.bind(this)); this.loadDate(); this.loadRooms(); }, loadDate: function(){ var dateText = this.date.format(this.app.lp.dateFormatAll); this.roomDateNode = new Element("div", {"styles": this.css.roomDateNode}).inject(this.roomDateArea); this.roomDateTextNode = new Element("div", {"styles": this.css.roomDateTextNode}).inject(this.roomDateNode); this.roomDateIconNode = new Element("div", {"styles": this.css.roomDateIconNode}).inject(this.roomDateNode); this.roomHourRangeNode = new Element("div", {"styles": this.css.roomHourRangeNode}).inject(this.roomDateArea); var html = this.app.lp.persist+" "+this.app.lp.hour; this.roomDateTextNode.set("text", dateText); this.roomHourRangeNode.set("html", html); this.roomHourRangeSelect = this.roomHourRangeNode.getElement("select").setStyles(this.css.roomHourRangeSelectNode); this.roomHourRangeSelect.addEvent("change", function(){ var h = this.roomHourRangeSelect.options[this.roomHourRangeSelect.selectedIndex].get("value"); debugger; this.reload(this.date, h); }.bind(this)); this.roomDateNode.addEvents({ "mouseover": function(){ this.roomDateNode.setStyles(this.css.roomDateNode_over); this.roomDateIconNode.setStyles(this.css.roomDateIconNode_over); }.bind(this), "mouseout": function(){ this.roomDateNode.setStyles(this.css.roomDateNode); this.roomDateIconNode.setStyles(this.css.roomDateIconNode); }.bind(this), "mousedown": function(){ this.roomDateNode.setStyles(this.css.roomDateNode_down); this.roomDateIconNode.setStyles(this.css.roomDateIconNode_down); }.bind(this), "mouseup": function(){ this.roomDateNode.setStyles(this.css.roomDateNode_over); this.roomDateIconNode.setStyles(this.css.roomDateIconNode_over); }.bind(this) }); MWF.require("MWF.widget.Calendar", function(){ new MWF.widget.Calendar(this.roomDateNode, { "style":"meeting", "isTime": true, "target": this.node, "onQueryComplate": function(e, dv, date){ var selectedDate = new Date.parse(dv); var h = this.roomHourRangeSelect.options[this.roomHourRangeSelect.selectedIndex].get("value"); this.reload(selectedDate, h); }.bind(this) }); }.bind(this)); }, resetNodeSize: function(){ var size = this.container.getSize(); if (this.app.meetingConfig.hideMenu=="static"){ var y = size.y-120; this.node.setStyle("height", ""+y+"px"); this.node.setStyle("margin-top", "60px"); }else{ var y = size.y-20; this.node.setStyle("height", ""+y+"px"); } //var size = this.container.getSize(); //var y = size.y-20; //this.node.setStyle("height", ""+y+"px"); var dateSize = this.roomDateArea.getSize(); y = y-dateSize.y; this.roomBuildingsArea.setStyle("height", ""+y+"px"); }, loadRooms: function(){ var startTime = this.date.clone(); startTime.set("sec", 0); var start = startTime.format("%Y-%m-%d %H:%M"); startTime.increment("hour", this.hours); var complete = startTime.format("%Y-%m-%d %H:%M"); this.app.actions.listBuildingByRange((start), (complete), function(json){ this.roomJson =json.data; //this.roomBuildingsArea; this.roomJson.each(function(building){ this.buildings.push(new MWF.xApplication.Meeting.RoomView.Building(this, building)); }.bind(this)); this.checkWidth(); this.checkWidthFun = this.checkWidth.bind(this); this.app.addEvent("resize", this.checkWidthFun); this.buildings.each(function(building){ building.loadRooms(); }.bind(this)); }.bind(this)); }, checkWidth: function(){ var count = this.buildings.length; if (count){ var min = this.buildings[0].node.getStyle("min-width").toInt(); var size = this.roomArea.getSize(); while ((count>0) && (size.x/count)0) && ((size.x-10)/count)-12"+this.app.lp.subject+""+this.app.lp.applyPerson+"" this.meetingNode.set("html", html); var table = this.meetingNode.getElement("table"); var _self = this; json.data.meetingList.each(function(meeting){ var tr = new Element("tr").inject(table); var td = new Element("td", {"text": Date.parse(meeting.startTime).format(this.app.lp.dateFormatMonthDay+" %H:%M")}).inject(tr); var td = new Element("td", {"text": meeting.subject}).inject(tr); var td = new Element("td", {"text": meeting.applicant}).inject(tr); tr.store("meeting", meeting); tr.addEvent("click", function(){ var mt = this.retrieve("meeting"); if (mt){ if (!_self.document){ if (_self.view.currentMeetingDocument) _self.view.currentMeetingDocument.closeDocument(); _self.data = mt _self.document = new MWF.xApplication.Meeting.RoomView.Building.Room.Meeting.Document(_self); _self.view.currentMeetingDocument = _self.document; } } }); }.bind(this)); table.setStyles(this.css.roomDocMeetingListTable); table.getElements("th").setStyles(this.css.roomDocMeetingListTh); table.getElements("td").setStyles(this.css.roomDocMeetingListTd); }.bind(this)); }, editDocument: function(){ this.saveAction.setStyle("display", "block"); this.editAction.setStyle("display", "none"); var name = this.titleNode.get("text"); this.titleNode.empty(); this.titleInput = new Element("input", { "styles": this.css.buildingDocTitleInputNode, "type": "text", "value": name }).inject(this.titleNode); var node = this.floorNode.getLast().empty(); var selectNode = new Element("select", {"styles": this.css.roomDocItemSelectNode}).inject(node); for (var i=-2; i<=50; i++){ var option = new Element("option", { "value": i, "text": i+this.app.lp.floor, "selected": (i==this.json.floor) }).inject(selectNode); } node = this.roomNumberNode.getLast().empty(); var input = new Element("input", { "styles": this.css.roomDocItemInputNode, "type": "text", "value": this.json.roomNumber }).inject(node); node = this.phoneNumberNode.getLast().empty(); var input = new Element("input", { "styles": this.css.roomDocItemInputNode, "type": "text", "value": this.json.phoneNumber || "" }).inject(node); node = this.deviceberNode.getLast().empty(); var deviceList = this.json.device.split("#"); Object.each(this.app.lp.device, function(d, k){ var check = (deviceList.indexOf(k)!=-1) ? "checked" : ""; new Element("div", { "styles": {"float": "left", "width": "90px"}, "html": ""+d }).inject(node); }.bind(this)); node = this.capacityNode.getLast().empty(); input = new Element("input", { "styles": this.css.roomDocItemInputNode, "type": "number", "value": this.json.capacity }).inject(node); node = this.auditorNode.getLast().empty(); auditorDiv = new Element("div", {"styles": this.css.roomDocItemAuditorDivNode}).inject(node); this.auditorNode.store("names", this.json.auditor); var explorer = { "actions": this.app.personActions, "app": { "lp": this.app.lp } } if (this.json.auditor){ MWF.require("MWF.widget.Identity", function(){ var _self = this; var person = new MWF.widget.Person({"name": this.json.auditor}, auditorDiv, explorer, true, function(e){ this.node.destroy(); MWF.release(this); _self.auditorNode.eliminate("names"); _self.auditorNode.eliminate("person"); e.stopPropagation(); }, {"style": "meeting"}); this.auditorNode.store("person", person); }.bind(this)); } var name = this.json.auditor; MWF.xDesktop.requireApp("Organization", "Selector.package", function(){ auditorDiv.addEvents({ "click": function(){ var options = { "type": "person", "names": (name) ? [name] : [], "count": 1, "onComplete": function(items){ var op = this.auditorNode.retrieve("person"); if (op){ op.node.destroy(); MWF.release(op); this.auditorNode.eliminate("person"); } this.auditorNode.store("names", items[0].data.name); MWF.require("MWF.widget.Identity", function(){ var _self = this; var person = new MWF.widget.Person(items[0].data, auditorDiv, explorer, true, function(e){ this.node.destroy(); MWF.release(this); _self.auditorNode.eliminate("names"); _self.auditorNode.eliminate("person"); e.stopPropagation(); }, {"style": "meeting"}); this.auditorNode.store("person", person); }.bind(this)); }.bind(this) }; var selector = new MWF.OrgSelector(this.app.content, options); }.bind(this) }); }.bind(this)); node = this.availableNode.getLast().empty(); new Element("div", { "styles": {"float": "left"}, "html": ""+this.app.lp.enable }).inject(node); new Element("div", { "styles": {"float": "left"}, "html": ""+this.app.lp.disable }).inject(node); this.titleNode.removeEvent("click", this.editDocumentFun); if (this.addrNode) this.addrNode.removeEvent("click", this.editDocumentFun); this.isEditMode = true; this.setMeetingNodeSize(); }, readDocument: function(){ this.saveAction.setStyle("display", "none"); this.editAction.setStyle("display", "block"); var name = this.titleInput.get("value"); this.titleInput.destroy(); this.titleNode.set("text", name); var node = this.floorNode.getLast().empty(); node.set("text", this.json.floor+this.app.lp.floor); node = this.roomNumberNode.getLast().empty(); node.set("text", this.json.roomNumber); node = this.phoneNumberNode.getLast().empty(); node.set("text", this.json.phoneNumber); node = this.deviceberNode.getLast().empty(); var deviceList = this.json.device.split("#"); var deviceNameList = []; deviceList.each(function(d){deviceNameList.push(this.app.lp.device[d]);}.bind(this)); node.set("text", deviceNameList.join(" ")); node = this.capacityNode.getLast().empty(); node.set("text", this.json.capacity+this.app.lp.person); node = this.auditorNode.getLast().empty(); var explorer = { "actions": this.app.personActions, "app": { "lp": this.app.lp } } if (this.json.auditor){ MWF.require("MWF.widget.Identity", function(){ var _self = this; var person = new MWF.widget.Person({"name": this.json.auditor}, node, explorer, false, null, {"style": "meeting"}); }.bind(this)); } node = this.availableNode.getLast().empty(); var availableTxt = (this.json.available) ? this.app.lp.enable : this.app.lp.disable; node.set("text", availableTxt); this.titleNode.addEvent("click", this.editDocumentFun); if (this.addrNode) this.addrNode.addEvent("click", this.editDocumentFun); this.isEditMode = false; }, saveDocument: function(noNotice, callback){ if (this.getRoomData()){ this.app.actions.saveRoom(this.json, function(json){ if (!noNotice) this.app.notice(this.app.lp.save_success, "success", this.node, {"x": "right", "y": "top"}); this.readDocument(); this.room.reload(); if (callback) callback(); }.bind(this)); } }, getRoomData: function(){ var flag = true; var name = this.titleInput.get("value"); var select = this.floorNode.getElement("select"); var floor = select.options[select.selectedIndex].value; var number = this.roomNumberNode.getElement("input").get("value"); var phone = this.phoneNumberNode.getElement("input").get("value"); var deviceList = []; var deviceChecks = this.deviceberNode.getElements("input"); deviceChecks.each(function(input){ if (input.checked) deviceList.push(input.get("value")); }.bind(this)); var device = deviceList.join("#"); var capacity = this.capacityNode.getElement("input").get("value"); var auditor = this.auditorNode.retrieve("names", "") var available = true; var radios = this.availableNode.getElements("input"); for (var i=0; i