Skip to content
This repository was archived by the owner on Apr 11, 2022. It is now read-only.

Commit c8d2cae

Browse files
committed
Added ability to hide contact information on subleases.
1 parent 8192363 commit c8d2cae

8 files changed

Lines changed: 134 additions & 30 deletions

File tree

boost/boost.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* @license http://opensource.org/licenses/gpl-3.0.html
1919
*/
2020
$proper_name = 'Properties';
21-
$version = '2.2.3';
21+
$version = '2.3.0';
2222
$register = false;
2323
$unregister = false;
2424
$import_sql = false;

boost/update.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ public function run(&$content)
163163
case $this->compare('2.2.3'):
164164
$methodName = $this->getMethodName('2.2.3');
165165
$this->$methodName($content);
166+
167+
case $this->compare('2.3.0'):
168+
$methodName = $this->getMethodName('2.3.0');
169+
$this->$methodName($content);
166170
}
167171
return $content;
168172
}
@@ -436,6 +440,16 @@ public function v2_2_3(&$content)
436440
$updates = array('Fixed image upload.', 'Added error messages on broken uploads.', 'Added image size limit.');
437441
$this->addContent($content, '2.2.3', $updates);
438442
}
443+
444+
public function v2_3_0(&$content)
445+
{
446+
$db = Database::getDB();
447+
$tbl = $db->addTable('prop_sublease');
448+
$hideContact = new \phpws2\Database\Datatype\Boolean($tbl, 'hideContact');
449+
$hideContact->add();
450+
$updates = array('Sublease admins may hide contact information.');
451+
$this->addContent($content, '2.3.0', $updates);
452+
}
439453

440454
private function addContent(&$content, $version, array $changes)
441455
{

class/Factory/Sublease.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,17 @@ public function view($sublease, $admin = false)
142142
}
143143
$tpl['otherInformationTemplate'] = PHPWS_SOURCE_DIR . 'mod/properties/templates/sublease/OtherInformation.html';
144144
$tpl['amenitiesTemplate'] = PHPWS_SOURCE_DIR . 'mod/properties/templates/sublease/Amenities.html';
145+
if ($sublease->hideContact && !\Current_User::isLogged()) {
146+
$tpl['hideContact'] = true;
147+
} else {
148+
$tpl['hideContact'] = false;
149+
}
150+
$auth = \Current_User::getAuthorization();
151+
if (isset($auth->login_link)) {
152+
$tpl['login'] = $auth->login_link;
153+
} else {
154+
$tpl['login'] = \Canopy\Server::getSiteUrl() . 'admin';
155+
}
145156
$template = new \phpws2\Template($tpl);
146157
$template->setModuleTemplate('properties', 'sublease/view.html');
147158
}
@@ -200,7 +211,7 @@ public function flipSubleaseTimeout()
200211
public function patch(\properties\Resource\Sublease $sublease, $param,
201212
$value)
202213
{
203-
static $allowed_params = array('active');
214+
static $allowed_params = array('active', 'hideContact');
204215

205216
if (!in_array($param, $allowed_params)) {
206217
throw new \Exception('Parameter may not be patched');

class/Resource/Sublease.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class Sublease extends Place
2929
protected $landlord_perm;
3030
protected $move_out_date;
3131
protected $user_id;
32+
protected $hideContact;
3233
protected $table = 'prop_sublease';
3334

3435
public function __construct()
@@ -43,6 +44,7 @@ public function __construct()
4344
$this->landlord_perm = new Variable\BooleanVar(false, 'landlord_perm');
4445
$this->move_out_date = new Variable\DateVar(time() + 86400*180, 'move_out_date');
4546
$this->user_id = new Variable\IntegerVar(0, 'user_id');
47+
$this->hideContact = new Variable\BooleanVar(false, 'hideContact');
4648
}
4749

4850
public function view()

javascript/SubleaseForm/SubleaseForm.jsx

Lines changed: 56 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import CheckValues from '../Mixin/Helper/CheckValues.js'
1616
import moment from 'moment'
1717
import Help from '../Mixin/Html/Help.jsx'
1818
import UtilityFunctions from '../Mixin/Edit/UtilityFunctions.js'
19+
import {FontAwesomeIcon} from '@fortawesome/react-fontawesome'
20+
import {faToggleOn, faToggleOff} from '@fortawesome/free-solid-svg-icons'
1921
import './style.css'
2022

2123
/* global $, subleaseCurrent */
@@ -41,7 +43,9 @@ export default class SubleaseForm extends Base {
4143
'setMoveIn',
4244
'setMoveOut',
4345
'updateParking',
44-
'sendActive'
46+
'sendActive',
47+
'hideContact',
48+
'showContact'
4549
]
4650
bindMethods(methods, this)
4751
}
@@ -244,6 +248,36 @@ export default class SubleaseForm extends Base {
244248
]
245249
}
246250

251+
hideContact() {
252+
$.ajax({
253+
url: './properties/Sublease/' + this.state.sublease.id,
254+
data: {
255+
varname: 'hideContact',
256+
value: true
257+
},
258+
dataType: 'json',
259+
type: 'patch',
260+
success: function () {
261+
this.setValue('hideContact', true)
262+
}.bind(this)
263+
})
264+
}
265+
266+
showContact() {
267+
$.ajax({
268+
url: './properties/Sublease/' + this.state.sublease.id,
269+
data: {
270+
varname: 'hideContact',
271+
value: false
272+
},
273+
dataType: 'json',
274+
type: 'patch',
275+
success: function () {
276+
this.setValue('hideContact', false)
277+
}.bind(this)
278+
})
279+
}
280+
247281
updateRent(e) {
248282
const rent = e.target.value.replace(/[^\d]/g, '')
249283
this.setError('monthly_rent', empty(rent))
@@ -288,40 +322,35 @@ export default class SubleaseForm extends Base {
288322
onClose={this.unsetMessage}/>
289323
}
290324

325+
let hideContactButton
326+
if (empty(sublease.hideContact)) {
327+
hideContactButton = (
328+
<div key="1" onClick={this.hideContact} className="lead pointer text-success"><FontAwesomeIcon icon={faToggleOn}/>&nbsp;Contact information shown to everyone</div>
329+
)
330+
} else {
331+
hideContactButton = (
332+
<div key="2" onClick={this.showContact} className="lead pointer text-danger"><FontAwesomeIcon icon={faToggleOff}/>&nbsp;Contact information shown only to other students.</div>
333+
)
334+
}
335+
291336
let activateButton
292-
let deactivateButton
293-
let showActivate = 'd-inline'
294-
let showDeactivate = 'd-inline'
295337
if (sublease.id > 0) {
296338
if (empty(sublease.active)) {
297-
showDeactivate = 'd-none'
339+
activateButton = (
340+
<div key="3" onClick={this.activate} className="lead pointer text-danger"><FontAwesomeIcon icon={faToggleOff}/>&nbsp;Sublease inactive</div>
341+
)
298342
} else {
299-
showActivate = 'd-none'
343+
activateButton = (
344+
<div key="4" onClick={this.deactivate} className="lead pointer text-success"><FontAwesomeIcon icon={faToggleOn}/>&nbsp;Sublease active</div>
345+
)
300346
}
301-
302-
activateButton = (
303-
<div
304-
key="1"
305-
onClick={this.activate}
306-
className={`lead pointer text-muted ${showActivate}`}>
307-
<i className="fa fa-toggle-off"></i>&nbsp; Sublease inactive</div>
308-
)
309-
310-
deactivateButton = (
311-
<div
312-
key="2"
313-
onClick={this.deactivate}
314-
className={`lead pointer text-success ${showDeactivate}`}>
315-
<i className="fa fa-toggle-on"></i>&nbsp; Sublease active</div>
316-
)
317347
}
318348

319349
let contactAlert
320350
if (this.state.sublease.id === 0) {
321351
contactAlert = (
322352
<div className="alert alert-info">
323-
<strong>Notice:</strong>&nbsp; a sublease listing requires contact information.<br/>
324-
Use our&nbsp;<a href="./properties/Roommate">roommate section</a>&nbsp;ifyouwanttokeep your contact information available only to other students.</div>
353+
<strong>Notice:</strong>&nbsp; a sublease listing requires contact information.</div>
325354
)
326355
}
327356

@@ -355,8 +384,8 @@ export default class SubleaseForm extends Base {
355384
<h2>{suffixTitle}&nbsp;my sublease</h2>
356385
{message}
357386
{contactAlert}
358-
<div className="text-align mb-1">
359-
{activateButton}{deactivateButton}
387+
<div className="mb-1">
388+
{activateButton}
360389
</div>
361390
<div className="row">
362391
<div className="col-sm-6">
@@ -397,6 +426,7 @@ export default class SubleaseForm extends Base {
397426
onChange={this.setValue.bind(this, 'description')}/>
398427
</div>
399428
</div>
429+
{hideContactButton}
400430
<div className="row">
401431
<div className="col-sm-6">
402432
<InputField

package-lock.json

Lines changed: 41 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "properties",
3-
"version": "2.2.3",
3+
"version": "2.3.0",
44
"description": "Online property manager",
55
"dependencies": {},
66
"devDependencies": {
@@ -11,6 +11,9 @@
1111
"@essappstate/canopy-react-buttongroup": "^0.2.0",
1212
"@essappstate/canopy-react-inputfield": "^0.2.0",
1313
"@essappstate/canopy-react-overlay": "^0.2.0",
14+
"@fortawesome/fontawesome-svg-core": "^1.2.18",
15+
"@fortawesome/free-solid-svg-icons": "^5.8.2",
16+
"@fortawesome/react-fontawesome": "^0.1.4",
1417
"assets-webpack-plugin": "^3.9.10",
1518
"babel-loader": "^8.0.5",
1619
"browser-sync": "^2.26.3",

templates/sublease/view.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@ <h3 class="sublease-address"><a href="<?=$property_map_address?>" target="_blank
3333
<div class="card card-success">
3434
<div class="card-header"><h4>Contact information</h4></div>
3535
<div class="card-body">
36+
<?php if($hideContact):?>
37+
<p><a href="<?=$login?>">Log in for contact information.</a></p>
38+
<?php else: ?>
3639
<a href="<?=$contact_phone_tel?>" target="_blank"><i class="fa fa-phone"></i>&nbsp;<?=$contact_phone?></a><br />
3740
<a href="mailto:<?=$contact_email?>" target="_blank"><i class="far fa-envelope"></i>&nbsp;Email</a>
41+
<?php endif; ?>
3842
</div>
3943
</div>
4044
</div>

0 commit comments

Comments
 (0)