Skip to content

Commit

Permalink
feat: implementa troca do tipo da emenda
Browse files Browse the repository at this point in the history
refs #870
  • Loading branch information
fragomeni committed Apr 12, 2024
1 parent 1a02930 commit be3d770
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
14 changes: 14 additions & 0 deletions demo/components/demoview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,19 @@ export class DemoView extends LitElement {
}
}

trocarModo(): void {
const novoModo = this.getElement('#modo').value;

if (this.modo === novoModo) {
alert('Escolha um modo de edição diferente do atual.');
return;
}

this.modo = novoModo;

this.elLexmlEmenda.trocarModoEdicao(this.modo, this.modo === 'emendaTextoLivre' ? 'Motivo da emenda de texto livre' : '');
}

salvar(): void {
const emenda = this.elLexmlEmenda.getEmenda();
const emendaJson = JSON.stringify(emenda, null, '\t');
Expand Down Expand Up @@ -383,6 +396,7 @@ export class DemoView extends LitElement {
<option value="emendaSubstituicaoTermo" id="optEmendaSubstituicaoTermo">Emenda Substituição de termo</option>
</select>
<input type="button" value="Ok" @click=${this.executar} />
<input type="button" value="Trocar modo" @click=${this.trocarModo} ?disabled="${!this.modo}" />
</div>
</div>
<div class="nome-proposicao">${this.proposicaoCorrente.sigla ? `${this.proposicaoCorrente.sigla} ${this.proposicaoCorrente.numero}/${this.proposicaoCorrente.ano}` : ''}</div>
Expand Down
53 changes: 53 additions & 0 deletions src/components/lexml-emenda.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,59 @@ export class LexmlEmendaComponent extends connect(rootStore)(LitElement) {
this.updateView();
}

public trocarModoEdicao(modo: string, motivo = ''): void {
if (this.modo === modo) {
console.log('Ignorando tentativa de mudança para o mesmo modo de edição.');
return;
}

if (!this.projetoNorma && modo === 'emenda') {
throw 'Não é possível trocar para o modo "emenda" quando não há texto da proposição.';
}

this._lexmlEmendaComando.emenda = [];
this.modo = modo;

this.motivo = motivo;
if (this.isEmendaTextoLivre() && !this.motivo) {
throw 'Deve ser informado um motivo para a emenda de texto livre.';
}

if (!this.isEmendaTextoLivre() && !this.isEmendaSubstituicaoTermo()) {
this._lexmlEta!.inicializarEdicao(this.modo, this.urn, this.projetoNorma, false);
}

rootStore.dispatch(limparAlertas());

if (this.isEmendaTextoLivre()) {
this._lexmlEmendaTextoRico.setContent('');
this._lexmlEmendaTextoRico.anexos = [];
} else if (this.isEmendaSubstituicaoTermo()) {
this._substituicaoTermo!.setSubstituicaoTermo(new SubstituicaoTermo());
}

this.limparAlertas();

if (this.isEmendaTextoLivre() && !this._lexmlEmendaTextoRico.texto) {
this.showAlertaEmendaTextoLivre();
}
setTimeout(this.handleResize, 0);

this._tabsEsquerda.show('lexml-eta');

if (this.modo.startsWith('emenda') && !this.isEmendaTextoLivre()) {
setTimeout(() => {
this._tabsDireita?.show('comando');
});
} else {
setTimeout(() => {
this._tabsDireita?.show('notas');
});
}

this.updateView();
}

private inicializaProposicao(params: LexmlEmendaParametrosEdicao): void {
this.urn = '';
this.ementa = '';
Expand Down

0 comments on commit be3d770

Please sign in to comment.