public DialogCarma(KarmaHome home, KarmaUser user) { super(false, true); this.homeParent = home; this.user = user; setHTML(CONSTANTS.this_html()); VerticalPanel verticalPanel = new VerticalPanel(); verticalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); setWidget(verticalPanel); verticalPanel.setWidth("100%"); HorizontalPanel horizontalPanel = new HorizontalPanel(); horizontalPanel.setSpacing(5); verticalPanel.add(horizontalPanel); horizontalPanel.setWidth("100%"); VerticalPanel verticalPanel_2 = new VerticalPanel(); horizontalPanel.add(verticalPanel_2); verticalPanel_2.setSize("260", "110"); Grid grid_1 = new Grid(3, 2); verticalPanel_2.add(grid_1); grid_1.setSize("", "100"); Label label_10 = new Label(CONSTANTS.label_10_text()); grid_1.setWidget(0, 0, label_10); grid_1.getCellFormatter().setWidth(0, 0, "100"); listTypes = new ListBox(); grid_1.setWidget(0, 1, listTypes); grid_1.getCellFormatter().setWidth(0, 1, "150"); listTypes.setWidth("100%"); ClientUtils.fillTypes(listTypes); Label label_11 = new Label(CONSTANTS.label_11_text()); grid_1.setWidget(1, 0, label_11); tbPlate = new TextBox(); tbPlate.setVisibleLength(10); grid_1.setWidget(1, 1, tbPlate); tbPlate.setWidth("100%"); cbxForeign = new CheckBox(CONSTANTS.cbxForeign_text()); grid_1.setWidget(2, 0, cbxForeign); cbxForeign.addClickHandler( new ClickHandler() { public void onClick(ClickEvent event) { showCountries(); } }); listCountry = new ListBox(); grid_1.setWidget(2, 1, listCountry); listCountry.setWidth("100%"); listCountry.setVisible(false); ClientUtils.fillCountries(listCountry); VerticalPanel verticalPanel_6 = new VerticalPanel(); horizontalPanel.add(verticalPanel_6); verticalPanel_6.setSize("260", "110"); Grid grid_2 = new Grid(3, 2); verticalPanel_6.add(grid_2); grid_2.setSize("", "100"); Label label_15 = new Label(CONSTANTS.label_15_text()); grid_2.setWidget(0, 0, label_15); grid_2.getCellFormatter().setWidth(0, 0, "50"); date = new DateBox(); date.setFormat(new DefaultFormat(DateTimeFormat.getFormat("yyyy-MM-dd HH:mm"))); grid_2.setWidget(0, 1, date); grid_2.getCellFormatter().setWidth(0, 1, "200"); date.setWidth("100%"); date.addValueChangeHandler( new ValueChangeHandler<Date>() { @Override public void onValueChange(ValueChangeEvent<Date> event) { Date d = event.getValue(); if (d.after(new Date()) || d.before(new Date(System.currentTimeMillis() - 31536000000L))) { date.setValue(new Date()); MsgMan.getInstance().showError(CONSTANTS.error_date1(), date); } } }); Label label_16 = new Label(CONSTANTS.label_16_text()); grid_2.setWidget(1, 0, label_16); taNotes = new TextArea(); taNotes.addKeyPressHandler( new KeyPressHandler() { public void onKeyPress(KeyPressEvent event) { updateCounter(); } }); taNotes.setSize("100%", "50"); grid_2.setWidget(1, 1, taNotes); lblCounter = new Label("New label"); lblCounter.addStyleName("counter"); grid_2.setWidget(2, 1, lblCounter); grid_2.getCellFormatter().setHorizontalAlignment(2, 1, HasHorizontalAlignment.ALIGN_RIGHT); HorizontalPanel horizontalPanel_3 = new HorizontalPanel(); horizontalPanel_3.setSpacing(5); horizontalPanel_3.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT); verticalPanel.add(horizontalPanel_3); verticalPanel.setCellHorizontalAlignment( horizontalPanel_3, HasHorizontalAlignment.ALIGN_CENTER); btnPuntuar = new Button("New button"); horizontalPanel_3.add(btnPuntuar); btnPuntuar.setText(CONSTANTS.btnPuntuar_text()); btnPuntuar.setWidth("100"); Button btnCancel = new Button("New button"); horizontalPanel_3.add(btnCancel); btnCancel.setText(CONSTANTS.btnCancel_text()); btnCancel.setWidth("100"); btnPuntuar.addClickHandler( new ClickHandler() { public void onClick(ClickEvent event) { makeKarma(); } }); btnCancel.addClickHandler( new ClickHandler() { public void onClick(ClickEvent event) { DialogCarma.this.hide(); } }); updateCounter(); }
private void makeKarma() { int type = Integer.parseInt(listTypes.getValue(listTypes.getSelectedIndex())); if (type == -1) { MsgMan.getInstance().showError(CONSTANTS.error_type(), listTypes); return; } System.out.println("Seleccionado Carma tipo: " + type); String plate = tbPlate.getText().toUpperCase(); if (ClientUtils.isEmpty(plate)) { MsgMan.getInstance().showError(CONSTANTS.error_plate1(), tbPlate); return; } else if (!ClientUtils.isValidAlphanumeric(plate)) { MsgMan.getInstance().showError(CONSTANTS.error_plate2(), tbPlate); return; } else if (plate.equals(user.getPlate())) { if (!cbxForeign.getValue() || (cbxForeign.getValue() && listCountry .getValue(listCountry.getSelectedIndex()) .equals(user.getCountryCode()))) { MsgMan.getInstance().showError(CONSTANTS.error_plate3(), tbPlate); return; } } System.out.println("Matrícula pasa el test: " + plate); String txt = taNotes.getText(); if (txt.length() > Message.MAX_LENGTH_MESSAGE) { MsgMan.getInstance() .showError(CONSTANTS.error_message() + Message.MAX_LENGTH_MESSAGE, taNotes); return; } Date d = date.getValue(); if (d == null) { MsgMan.getInstance().showError(CONSTANTS.error_date2(), date); return; } String cCode = cbxForeign.getValue() ? listCountry.getValue(listCountry.getSelectedIndex()) : user.getCountryCode(); System.out.println("La fecha pasa el test: " + d); Message msg = new Message(type, user.getId(), plate, cCode, txt, d); System.out.println("Mensaje a guardar: " + msg); AsyncCallback<Integer> callback = new AsyncCallback<Integer>() { public void onFailure(Throwable caught) { System.out.println("Fallo al llamar al servicio: " + caught); MsgMan.getInstance().showError(CONSTANTS.error_generic()); } public void onSuccess(Integer resultCode) { if (resultCode == Message.REGISTERED) { System.out.println(CONSTANTS.ok_carma()); homeParent.updateScreen(); DialogCarma.this.hide(); ClientUtils.recordAnalyticsHit("account-set-carma"); MsgMan.getInstance().showMessage(ClientUtils.getCarmaReturnMessage(resultCode)); } else { // Mostrar mensajito de error bajo la caja System.out.println("No ha podido registrarse el karma: " + resultCode); MsgMan.getInstance().showError(ClientUtils.getCarmaReturnMessage(resultCode)); } } }; SVC.getSvc().registerMessage(msg, callback); }