Avanços amb els formularis
This commit is contained in:
parent
f621a29953
commit
e129eb4107
@ -59,11 +59,20 @@ export const Necessitats = () => {
|
||||
action={d => {
|
||||
if (d.get('selTipus'))
|
||||
try {
|
||||
const tipusSeleccionat = tipus.find(t => t._id === d.get('selTipus')) || "";
|
||||
const pobleSeleccionat = pobles.find(p => p._id === d.get('selPoble')) || "";
|
||||
Meteor.callAsync('afigNecessitat', {
|
||||
...necessitatSeleccionada || [],
|
||||
titol: d.get('titol'),
|
||||
tipus: d.get('selTipus') || "",
|
||||
poble: d.get('selPoble')
|
||||
titol: d.get('taTitol'),
|
||||
tipus: tipusSeleccionat,
|
||||
poble: pobleSeleccionat,
|
||||
descrip: d.get('taDescripcio'),
|
||||
contacte: {
|
||||
nom: d.get('inContacte'),
|
||||
tel: d.get('inTelefon'),
|
||||
email: d.get('inEMail'),
|
||||
adr: d.get('inAdreça')
|
||||
}
|
||||
})
|
||||
.then(() => setNecessitatSeleccionada(null))
|
||||
.catch(err => console.error(err))
|
||||
@ -76,7 +85,7 @@ export const Necessitats = () => {
|
||||
>
|
||||
|
||||
<label htmlFor="taTitol">Títol</label> <br />
|
||||
<textarea name='taTitol' placeholder='Títol de la necessitat...'></textarea>
|
||||
<textarea name='taTitol' placeholder='Títol de la necessitat...' defaultValue={ necessitatSeleccionada ? necessitatSeleccionada.titol : ""} ></textarea>
|
||||
|
||||
<br /><br />
|
||||
|
||||
@ -91,6 +100,7 @@ export const Necessitats = () => {
|
||||
formatCreateLabel={(inputValue) => "Crear nou tipus..."}
|
||||
defaultOptions={tipus.map((v,i) => ({value: v._id, label: v.titol})).sort((a,b) => a.label.toLowerCase() > b.label.toLowerCase()) }
|
||||
onCreateOption={(inputValue) => Meteor.callAsync('afigTipus', {titol: inputValue})}
|
||||
defaultValue={ necessitatSeleccionada ? { value: necessitatSeleccionada.tipus._id, label: necessitatSeleccionada.tipus.titol} : ""}
|
||||
// loadOptions={tipus.map((v,i) => ({value: v, label: v.titol}))}
|
||||
/>
|
||||
|
||||
@ -106,7 +116,9 @@ export const Necessitats = () => {
|
||||
|
||||
<label htmlFor="poble">Poble</label>
|
||||
|
||||
<CreatableSelect name="selPoble" options={pobles.map((v,i) => ({value: v._id, label: v.nomPoble})) } />
|
||||
<CreatableSelect name="selPoble" options={pobles.map((v,i) => ({value: v._id, label: v.nomPoble})) }
|
||||
defaultValue={ necessitatSeleccionada ? { value: necessitatSeleccionada.poble._id, label: necessitatSeleccionada.poble.nomPoble} : ""}
|
||||
/>
|
||||
{/* <select name="selPoble">
|
||||
{
|
||||
pobles.map((v,i) => <option key={`optPob${i}`}>{v.nomPoble}</option>)
|
||||
@ -116,7 +128,9 @@ export const Necessitats = () => {
|
||||
<br />
|
||||
|
||||
<label htmlFor="taDescripcio">Descripció: </label> <br />
|
||||
<textarea name="taDescripcio" id="taDescripcio" placeholder='Observacions i detalls particulars...'></textarea> <br />
|
||||
<textarea name="taDescripcio" id="taDescripcio" placeholder='Observacions i detalls particulars...'
|
||||
defaultValue={ necessitatSeleccionada ? necessitatSeleccionada?.descrip : ""}
|
||||
></textarea> <br />
|
||||
|
||||
<br />
|
||||
|
||||
@ -125,10 +139,18 @@ export const Necessitats = () => {
|
||||
border: `1px solid #6666`
|
||||
}}>
|
||||
<legend>Contacte</legend>
|
||||
<input required type="text" name="inContacte" id="inContacte" placeholder='Nom' /> <br />
|
||||
<input required type="text" name="inTelefon" id="inTelefon" placeholder='Telèfon' /> <br />
|
||||
<input required type="text" name="inEMail" id="inEMail" placeholder='Correu electrònic' /> <br />
|
||||
<input type="text" name="inAdreça" id="inAdreça" placeholder='Adreça' /> <br />
|
||||
<input required type="text" name="inContacte" id="inContacte" placeholder='Nom'
|
||||
defaultValue={ necessitatSeleccionada ? necessitatSeleccionada.contacte?.nom : ""}
|
||||
/> <br />
|
||||
<input required type="text" name="inTelefon" id="inTelefon" placeholder='Telèfon'
|
||||
defaultValue={ necessitatSeleccionada ? necessitatSeleccionada.contacte?.tel : ""}
|
||||
/> <br />
|
||||
<input required type="text" name="inEMail" id="inEMail" placeholder='Correu electrònic'
|
||||
defaultValue={ necessitatSeleccionada ? necessitatSeleccionada.contacte?.email : ""}
|
||||
/> <br />
|
||||
<input type="text" name="inAdreça" id="inAdreça" placeholder='Adreça'
|
||||
defaultValue={ necessitatSeleccionada ? necessitatSeleccionada.contacte?.adr : ""}
|
||||
/> <br />
|
||||
</fieldset>
|
||||
|
||||
<br />
|
||||
@ -173,7 +195,7 @@ export const Necessitats = () => {
|
||||
backgroundColor: `${'lightgreen' || 'lightcoral'}`
|
||||
}}
|
||||
>
|
||||
{nec.titol}{esEditor && <button onClick={() => {setNecessitatSeleccionada(nec)}}>Edita</button>}</li>)
|
||||
{nec.titol} {esEditor && <button onClick={() => {setNecessitatSeleccionada(nec)}}>Edita</button>}</li>)
|
||||
}</ul>
|
||||
</Suspense>;
|
||||
};
|
||||
@ -18,6 +18,7 @@ export const Poble = () => {
|
||||
// const [pobleSeleccionat, setPobleSeleccionat] = useState(null);
|
||||
// const [creantPoble, setCreantPoble] = useState(false);
|
||||
useSubscribe('pobles');
|
||||
useSubscribe('usuaris');
|
||||
// const pobles = useTracker("pobles", () => PoblesCollection.find().fetchAsync());
|
||||
const pobles = useFind(PoblesCollection, [{}, {sort: {nomPoble: 1}}]);
|
||||
|
||||
@ -77,10 +78,10 @@ export const Poble = () => {
|
||||
// }}
|
||||
// >
|
||||
// <label htmlFor="nomPoble">Població: </label>
|
||||
// <input
|
||||
// name="nomPoble"
|
||||
// type="text"
|
||||
// defaultValue={ pobleSeleccionat ? pobleSeleccionat.nomPoble : ""}
|
||||
// <input
|
||||
// name="nomPoble"
|
||||
// type="text"
|
||||
// defaultValue={ pobleSeleccionat ? pobleSeleccionat.nomPoble : ""}
|
||||
// onChange={ev => refInAmbitAssignat.current.value = ev.target.value.replace(/ +/g, '-').toLowerCase()}
|
||||
// /><br />
|
||||
// <label htmlFor="comarca">Comarca: </label><input name="comarca" type="text" /><br />
|
||||
@ -111,6 +112,60 @@ export const Poble = () => {
|
||||
|
||||
<h1>{pob?.nomPoble}</h1>
|
||||
|
||||
<h2>Monitores:</h2>
|
||||
<ul>
|
||||
{
|
||||
(async () => {
|
||||
const monitors = await Roles.getUsersInRoleAsync("monitor_de_poble", pob?.ambitAssociat);
|
||||
console.log("monitors: ", monitors);
|
||||
return monitors?.map( (u) => <li style={{
|
||||
display: `block`,
|
||||
border: `1px solid #6666`,
|
||||
borderRadius: `.4em`,
|
||||
padding: `4px`,
|
||||
listStyle: `none`,
|
||||
backgroundColor: `${'lightcoral'}`
|
||||
}}>{u.username}</li> );
|
||||
})()
|
||||
}
|
||||
</ul>
|
||||
|
||||
<h2>Encarregades de tasques:</h2>
|
||||
<ul>
|
||||
{
|
||||
(async () => {
|
||||
const encarregats = await Roles.getUsersInRoleAsync("encarregat_de_tasques", pob?.ambitAssociat);
|
||||
console.log("encarregats: ", encarregats);
|
||||
return encarregats?.map( (u) => <li style={{
|
||||
display: `block`,
|
||||
border: `1px solid #6666`,
|
||||
borderRadius: `.4em`,
|
||||
padding: `4px`,
|
||||
listStyle: `none`,
|
||||
backgroundColor: `${'orange'}`
|
||||
}}>{u.username}</li> );
|
||||
})()
|
||||
}
|
||||
</ul>
|
||||
|
||||
<h2>Voluntàries de poble:</h2>
|
||||
<ul>
|
||||
{
|
||||
(async () => {
|
||||
const voluntaris = await Roles.getUsersInRoleAsync("voluntari_de_poble", pob?.ambitAssociat);
|
||||
console.log("voluntaris: ", voluntaris);
|
||||
return voluntaris?.map( (u) => <li style={{
|
||||
display: `block`,
|
||||
border: `1px solid #6666`,
|
||||
borderRadius: `.4em`,
|
||||
padding: `4px`,
|
||||
listStyle: `none`,
|
||||
backgroundColor: `${'lightgreen'}`
|
||||
}}>{u.username}</li> );
|
||||
})()
|
||||
}
|
||||
</ul>
|
||||
|
||||
{/* { esEditor && (pobleSeleccionat || creantPoble) && <QuadreInfo_Poble /> }
|
||||
|
||||
<ul style={{
|
||||
|
||||
@ -125,7 +125,14 @@ export const Pobles = () => {
|
||||
}}
|
||||
>
|
||||
<Link to={`/poble/${pob.ambitAssociat}`}>
|
||||
{pob.nomPoble}{esEditor && <button onClick={() => {setPobleSeleccionat(pob)}}>Edita</button>}
|
||||
{pob.nomPoble}{esEditor && <button
|
||||
onClick={(ev) => {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
|
||||
setPobleSeleccionat(pob);
|
||||
}
|
||||
}>Edita</button>}
|
||||
</Link>
|
||||
</li>)
|
||||
|
||||
|
||||
@ -194,13 +194,20 @@ Meteor.startup(async () => {
|
||||
|
||||
Meteor.publish('usuaris', async function (uid) {
|
||||
|
||||
const esAdmin = await Roles.userIsInRoleAsync(Meteor.userId(), "admin");
|
||||
const userRoles = await Roles.getRolesForUserAsync(Meteor.userId());
|
||||
const esAdmin = await Roles.userIsInRoleAsync(this.userId, "admin", null);
|
||||
const userRoles = await Roles.getRolesForUserAsync(this.userId);
|
||||
|
||||
console.log("userRoles: ", userRoles);
|
||||
if (uid) {
|
||||
return Meteor.users.find({_id: uid},{fields: {username: 1, avatarId: 1, avatarLink: 1}});
|
||||
console.log("esAdmin: ", esAdmin);
|
||||
|
||||
if (esAdmin) {
|
||||
return Meteor.users.find({});
|
||||
}
|
||||
|
||||
if (uid) {
|
||||
return Meteor.users.find({_id: uid}, {fields: {username: 1, avatarId: 1, avatarLink: 1}});
|
||||
}
|
||||
|
||||
return Meteor.users.find({},{fields: {username: 1, avatarId: 1, avatarLink: 1}});
|
||||
});
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -222,7 +229,7 @@ Meteor.startup(async () => {
|
||||
|
||||
// Publish user's own roles
|
||||
Meteor.publish(null, async function () {
|
||||
if (await Roles.userIsInRoleAsync(Meteor.userId(), "admin")) {
|
||||
if (await Roles.userIsInRoleAsync(this.userId, "admin")) {
|
||||
return Meteor.roleAssignment.find();
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user