diff --git a/class/ResidenceHallMenu.php b/class/ResidenceHallMenu.php index fccf2af1..3cecb7b0 100644 --- a/class/ResidenceHallMenu.php +++ b/class/ResidenceHallMenu.php @@ -17,24 +17,6 @@ public function __construct() $residenceHallCmd->setOnSelectCmd(CommandFactory::getCommand('EditResidenceHallView')); $this->addCommand('Edit a residence hall', $residenceHallCmd); } - if(Current_User::allow('hms', 'floor_view')){ - $floorCmd = CommandFactory::getCommand('SelectFloor'); - $floorCmd->setTitle('Edit a Floor'); - $floorCmd->setOnSelectCmd(CommandFactory::getCommand('EditFloorView')); - $this->addCommand('Edit a floor', $floorCmd); - } - if(Current_User::allow('hms', 'room_view')){ - $roomCmd = CommandFactory::getCommand('SelectRoom'); - $roomCmd->setTitle('Edit a Room'); - $roomCmd->setOnSelectCmd(CommandFactory::getCommand('EditRoomView')); - $this->addCommand('Edit a room', $roomCmd); - } - if(Current_User::allow('hms', 'bed_view')){ - $bedCmd = CommandFactory::getCommand('SelectBed'); - $bedCmd->setTitle('Edit a Bed'); - $bedCmd->setOnSelectCmd(CommandFactory::getCommand('EditBedView')); - $this->addCommand('Edit a bed', $bedCmd); - } } } diff --git a/class/SelectHallView.php b/class/SelectHallView.php index 777a62e3..7c70e649 100644 --- a/class/SelectHallView.php +++ b/class/SelectHallView.php @@ -23,6 +23,9 @@ public function show() { $tpl = array(); + javascript('jquery'); + javascriptMod('hms', 'hall_editor'); + $tpl['TITLE'] = $this->title; $tpl['TERM'] = Term::getPrintableSelectedTerm(); diff --git a/class/command/AjaxGetBedsCommand.php b/class/command/AjaxGetBedsCommand.php index 39cd9850..59f083a3 100644 --- a/class/command/AjaxGetBedsCommand.php +++ b/class/command/AjaxGetBedsCommand.php @@ -7,7 +7,7 @@ class AjaxGetBedsCommand extends Command { private $roomId; public function getRequestVars(){ - return array('action'=>'AjaxGetFloors'); + return array('action'=>'AjaxGetBeds'); } public function execute(CommandContext $context) @@ -19,20 +19,18 @@ public function execute(CommandContext $context) $room = new HMS_Room($context->get('roomId')); - $beds = $room->get_beds(); + $bedsResult = $room->get_beds(); - $json_beds = array(); - $json_beds[0] = 'Select...'; + $beds = array(); + $i = 0; - foreach ($beds as $bed){ - if($bed->room_change_reserved != 0){ - //Cannot assign to reserved rooms - continue; - } - $json_beds[$bed->id] = $bed->bed_letter; + foreach ($bedsResult as $bed) + { + $beds[$i]['bed_letter'] = strtoupper($bed->getBedroomLabel()) . $bed->getLetter(); + $beds[$i]['bed_id'] = $bed->getId(); + $i++; } - $context->setContent(json_encode($json_beds)); + $context->setContent(json_encode($beds)); } } - diff --git a/class/command/AjaxGetFloorsCommand.php b/class/command/AjaxGetFloorsCommand.php index 48d1cd9f..2d2af3c1 100644 --- a/class/command/AjaxGetFloorsCommand.php +++ b/class/command/AjaxGetFloorsCommand.php @@ -19,26 +19,21 @@ public function execute(CommandContext $context) $hall = new HMS_Residence_Hall($context->get('hallId')); - $floors = $hall->get_floors(); - - #test($floors, 1); - - $json_floors = array(); - $json_floors[0] = 'Select...'; - - foreach ($floors as $floor){ - unset($text); - - $text = $floor->floor_number; - - if($hall->gender_type == COED && $floor->gender_type != COED){ - $text .= (' (' . HMS_Util::formatGender($floor->gender_type) . ')'); - } - - $json_floors[$floor->id] = $text; + $floorsResult = $hall->getFloors(); + + $floors = array(); + $i = 0; + + foreach ($floorsResult as $floor) + { + if(!empty($floor->get_rooms())) + { + $floors[$i]['floor_number'] = $floor->getFloorNumber(); + $floors[$i]['floor_id'] = $floor->getId(); + $i++; + } } - $context->setContent(json_encode($json_floors)); + $context->setContent(json_encode($floors)); } } - diff --git a/class/command/AjaxGetHallsCommand.php b/class/command/AjaxGetHallsCommand.php new file mode 100644 index 00000000..a9b5c402 --- /dev/null +++ b/class/command/AjaxGetHallsCommand.php @@ -0,0 +1,34 @@ +'AjaxGetHalls'); + } + + public function execute(CommandContext $context) + { + PHPWS_Core::initModClass('hms', 'HMS_Floor.php'); + + $term = Term::getSelectedTerm(); + + $hallsResults = ResidenceHallFactory::getHallsForTerm($term); + + $halls = array(); + + $i = 0; + + foreach ($hallsResults as $hall) + { + $halls[$i]['hall_name'] = $hall->getHallName(); + $halls[$i]['hall_id'] = $hall->getId(); + $i++; + } + + $context->setContent(json_encode($halls)); + } +} diff --git a/class/command/AjaxGetRoomsCommand.php b/class/command/AjaxGetRoomsCommand.php index 79604d4a..9078447f 100644 --- a/class/command/AjaxGetRoomsCommand.php +++ b/class/command/AjaxGetRoomsCommand.php @@ -7,7 +7,7 @@ class AjaxGetRoomsCommand extends Command { private $floorId; public function getRequestVars(){ - return array('action'=>'AjaxGetFloors'); + return array('action'=>'AjaxGetRooms'); } public function execute(CommandContext $context) @@ -19,16 +19,68 @@ public function execute(CommandContext $context) $floor = new HMS_Floor($context->get('floorId')); - $rooms = $floor->get_rooms(); + $roomsResult = $floor->get_rooms(); - $json_rooms = array(); - $json_rooms[0] = 'Select...'; + $rooms = array(); + $i = 0; - foreach ($rooms as $room){ - $json_rooms[$room->id] = $room->room_number; + foreach ($roomsResult as $room) + { + $text = $room->getRoomNumber(); + + if($floor->gender_type == COED){ + $text .= (' (' . HMS_Util::formatGender($room->gender_type) . ')'); + } + + if($room->ra == 1){ + $text .= (' (RA)'); + } + + if($room->reserved == 1) + { + $text .= (' (Reserved)'); + } + + if($room->offline == 1) + { + $text .= (' (Offline)'); + } + + if($room->private == 1) + { + $text .= (' (Private)'); + } + + if($room->overflow == 1) + { + $text .= (' (Overflow)'); + } + + if($room->parlor == 1) + { + $text .= (' (Parlor)'); + } + + if($room->ada == 1) + { + $text .= (' (ADA)'); + } + + if($room->hearing_impaired == 1) + { + $text .= (' (Hearing Impaired)'); + } + + if($room->bath_en_suite) + { + $text .= (' (Bath En Suite)'); + } + + $rooms[$i]['room_number'] = $text; + $rooms[$i]['room_id'] = $room->getId(); + $i++; } - $context->setContent(json_encode($json_rooms)); + $context->setContent(json_encode($rooms)); } } - diff --git a/javascript/hall_editor/HallEditor.jsx b/javascript/hall_editor/HallEditor.jsx new file mode 100644 index 00000000..5fed5bcb --- /dev/null +++ b/javascript/hall_editor/HallEditor.jsx @@ -0,0 +1,353 @@ +//The top level component class that holds the state and handles the server requests. +var HallEditorBox = React.createClass({ + //Sets the initial state of the class + getInitialState: function() { + return {halls: [], floors: [], rooms: [], beds: [], hallId: 0, floorId: 0, roomId: 0, bedId: 0}; + }, + //Resets the states of all the lower level dropdowns and then gets the floors for the hall chosen + chooseHall: function(hallIdToGet) + { + this.setState({hallId: hallIdToGet, floors: [], floorId: 0, rooms: [], roomId: 0, beds: [], bedId: 0}); + this.getFloors(hallIdToGet); + }, + //Resets the states for the room and bed, so that the relevant components are updated, and then gets the rooms for the floor chosen + chooseFloor: function(floorIdToGet) + { + this.setState({floorId: floorIdToGet, rooms: [], roomId: 0, beds: [], bedId: 0}); + this.getRooms(floorIdToGet); + }, + //Resets the bed's state, so it can be passed ot the relevant components, and then gets the beds for the room chosen + chooseRoom: function(roomIdToGet) + { + this.setState({roomId: roomIdToGet, beds: [], bedId: 0}); + this.getBeds(roomIdToGet); + }, + //Sets the state of the bedId which is passed to the relevant components + chooseBed: function(bedIdToSet) + { + this.setState({bedId: bedIdToSet}); + }, + //Grabs the appropriate data on initial mount + componentWillMount: function() + { + this.getHalls(); + }, + //Takes care of the ajax request for getting all the active halls + getHalls: function() + { + $.ajax({ + url: 'index.php?module=hms&action=AjaxGetHalls', + type: 'GET', + dataType: 'json', + success: function(data) + { + this.setState({halls: data}); + }.bind(this), + error: function(xhr, status, err) + { + alert(err.toString()) + console.error(this.props.url, status, err.toString()); + }.bind(this) + }); + }, + //Takes care of the ajax request for getting all the halls with rooms on them + getFloors: function(hallId) + { + $.ajax({ + url: 'index.php?module=hms&action=AjaxGetFloors&hallId='+hallId, + type: 'GET', + dataType: 'json', + success: function(data) + { + this.setState({floors: data}); + }.bind(this), + error: function(xhr, status, err) + { + alert(err.toString()) + console.error(this.props.url, status, err.toString()); + }.bind(this) + }); + }, + //Takes care of the ajax request for getting all the rooms on a floor + getRooms: function(floorId) + { + $.ajax({ + url: 'index.php?module=hms&action=AjaxGetRooms&floorId='+floorId, + type: 'GET', + dataType: 'json', + success: function(data) + { + this.setState({rooms: data}); + }.bind(this), + error: function(xhr, status, err) + { + alert(err.toString()) + console.error(this.props.url, status, err.toString()); + }.bind(this) + }); + }, + //Takes care of the ajax request for retrieving the beds in a room+ + getBeds: function(roomId) + { + $.ajax({ + url: 'index.php?module=hms&action=AjaxGetBeds&roomId='+roomId, + type: 'GET', + dataType: 'json', + success: function(data) + { + this.setState({beds: data}); + }.bind(this), + error: function(xhr, status, err) + { + alert(err.toString()) + console.error(this.props.url, status, err.toString()); + }.bind(this) + }); + }, + //Renders all the components and passes the appropriate state values to them + render: function() + { + return ( +
+ + + + +
+ ); + } +}); + + +//The react class responsible for taking care of the creation of the dropdown and button +//for the Halls +var HallBox = React.createClass({ + change: function() { + var hallId = parseInt(this.refs.hallChoices.getDOMNode().value); + this.props.changed(hallId); + }, + render: function() { + var options = Array({hall_id:0, hall_name: "Select..."}); + var data = this.props.halls; + for(i = 0; i < data.length; i++) + { + options.push(data[i]); + } + var selectOptions = options.map(function(node){ + return (); + }); + return ( +
+ +
+
+ +
+ +
+
+ ); + } +}); + + +//The react class responsible for taking care of the logic for creating the button +var HallButton = React.createClass({ + render: function(){ + if(this.props.id != 0 && !this.props.floorId) + { + var link = 'index.php?module=hms&action=EditResidenceHallView&hallId='+this.props.id; + return(
+ Edit Hall +
); + } + else { + return(
); + } + } +}); + + +//The react class responsible for taking care of the creation of the dropdown and button +//for the Floors +var FloorBox = React.createClass({ + change: function() { + var floorId = this.refs.floorChoices.getDOMNode().value; + this.props.changed(floorId); + }, + render: function() { + if(this.props.floors[0] == undefined) + { + return (
); + } + else + { + var options = Array({floor_id:0, floor_number: "Select..."}); + var data = this.props.floors; + for(i = 0; i < data.length; i++) + { + options.push(data[i]); + } + var selectOptions = options.map(function(node){ + return (); + }); + return ( +
+ +
+
+ +
+ +
+
+ ); + } + } +}); + + +//The react class responsible for taking care of the logic for creating the button +var FloorButton = React.createClass({ + render: function(){ + if(this.props.id != 0 && !this.props.roomId) + { + var link = 'index.php?module=hms&action=EditFloorView&floor='+this.props.id; + return(
+ Edit Floor +
); + } + else { + return(
); + } + } +}); + + +//The react class responsible for taking care of the creation of the dropdown and button +//for the Rooms +var RoomBox = React.createClass({ + change: function() { + var roomId = this.refs.roomChoices.getDOMNode().value; + this.props.changed(roomId); + }, + render: function() { + if(this.props.rooms[0] == undefined) + { + return (
); + } + else + { + var options = Array({room_id:0, room_number: "Select..."}); + var data = this.props.rooms; + for(i = 0; i < data.length; i++) + { + options.push(data[i]); + } + var selectOptions = options.map(function(node){ + return (); + }); + return ( +
+ +
+
+ +
+ +
+
+ ); + } + } +}); + + +//The react class responsible for taking care of the logic for creating the button +var RoomButton = React.createClass({ + render: function(){ + if(this.props.id != 0 && !this.props.bedId) + { + var link = 'index.php?module=hms&action=EditRoomView&room='+this.props.id; + return(
+ Edit Room +
); + } + else { + return(
); + } + } +}); + + + +//The react class responsible for taking care of the creation of the dropdown and button +//for the Beds +var BedBox = React.createClass({ + change: function() { + var bedId = this.refs.bedChoices.getDOMNode().value; + this.props.changed(bedId); + }, + render: function() { + if(this.props.beds[0] == undefined) + { + return (
); + } + else + { + var options = Array({bed_id:0, bed_letter: "Select..."}); + var data = this.props.beds; + for(i = 0; i < data.length; i++) + { + options.push(data[i]); + } + var selectOptions = options.map(function(node){ + return (); + }); + return ( +
+ +
+
+ +
+ +
+
+ ); + } + } +}); + + +//The react class responsible for taking care of the logic for creating the button +var BedButton = React.createClass({ + render: function(){ + + if(this.props.id != 0) + { + var link = 'index.php?module=hms&action=EditBedView&bed='+this.props.id; + return(
+ Edit Bed +
); + } + else { + return(
); + } + } +}); + + +//Inserts all the react components within the giving element. +React.render( + , + document.getElementById('HallPicker') +); diff --git a/javascript/hall_editor/head.js b/javascript/hall_editor/head.js new file mode 100644 index 00000000..c75cd249 --- /dev/null +++ b/javascript/hall_editor/head.js @@ -0,0 +1,3 @@ + + + diff --git a/templates/admin/select_residence_hall.tpl b/templates/admin/select_residence_hall.tpl index ee29bb0a..2d519673 100644 --- a/templates/admin/select_residence_hall.tpl +++ b/templates/admin/select_residence_hall.tpl @@ -1,17 +1,4 @@

{TITLE} {TERM}

-
-
- {START_FORM} - -
- - {HALLID} -
- -
- -
- {END_FORM} -
+