Search in sources :

Example 6 with PartnerDTO

use of org.activityinfo.legacy.shared.model.PartnerDTO in project activityinfo by bedatadriven.

the class DbPartnerEditor method showAddDialog.

private void showAddDialog() {
    PartnerDTO newPartner = new PartnerDTO();
    showEditDialog(newPartner);
}
Also used : PartnerDTO(org.activityinfo.legacy.shared.model.PartnerDTO)

Example 7 with PartnerDTO

use of org.activityinfo.legacy.shared.model.PartnerDTO in project activityinfo by bedatadriven.

the class DbTargetEditor method onEdit.

@Override
protected void onEdit(final TargetDTO dto) {
    this.view.showAddDialog(dto, db, true, new FormDialogCallback() {

        @Override
        public void onValidated(final FormDialogTether dlg) {
            final Record record = store.getRecord(dto);
            service.execute(new UpdateEntity(dto, getChangedProperties(record)), dlg, new AsyncCallback<VoidResult>() {

                @Override
                public void onFailure(Throwable caught) {
                    Log.error("Failed to edit target. " + caught.getMessage(), caught);
                }

                @Override
                public void onSuccess(VoidResult result) {
                    if (record.get("partnerId") != null) {
                        PartnerDTO partner = db.getPartnerById((Integer) record.get("partnerId"));
                        dto.setPartner(partner);
                    } else {
                        dto.setPartner(null);
                    }
                    if (record.get("projectId") != null) {
                        ProjectDTO project = db.getProjectById((Integer) record.get("projectId"));
                        dto.setProject(project);
                    } else {
                        dto.setProject(null);
                    }
                    store.commitChanges();
                    eventBus.fireEvent(AppEvents.SCHEMA_CHANGED);
                    dlg.hide();
                }
            });
        }
    });
}
Also used : ProjectDTO(org.activityinfo.legacy.shared.model.ProjectDTO) FormDialogCallback(org.activityinfo.ui.client.page.common.dialog.FormDialogCallback) UpdateEntity(org.activityinfo.legacy.shared.command.UpdateEntity) VoidResult(org.activityinfo.legacy.shared.command.result.VoidResult) PartnerDTO(org.activityinfo.legacy.shared.model.PartnerDTO) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) FormDialogTether(org.activityinfo.ui.client.page.common.dialog.FormDialogTether) Record(com.extjs.gxt.ui.client.store.Record)

Example 8 with PartnerDTO

use of org.activityinfo.legacy.shared.model.PartnerDTO in project activityinfo by bedatadriven.

the class DbTargetEditor method onAdd.

@Override
protected void onAdd() {
    final TargetDTO newTarget = new TargetDTO();
    this.view.showAddDialog(newTarget, db, false, new FormDialogCallback() {

        @Override
        public void onValidated(final FormDialogTether dlg) {
            service.execute(new AddTarget(db.getId(), newTarget), dlg, new AsyncCallback<CreateResult>() {

                @Override
                public void onFailure(Throwable caught) {
                    MessageBox.alert(I18N.CONSTANTS.error(), I18N.CONSTANTS.errorOnServer(), null);
                }

                @Override
                public void onSuccess(CreateResult result) {
                    newTarget.setId(result.getNewId());
                    if (newTarget.get("partnerId") != null) {
                        PartnerDTO partner = db.getPartnerById((Integer) newTarget.get("partnerId"));
                        newTarget.setPartner(partner);
                    }
                    if (newTarget.get("projectId") != null) {
                        ProjectDTO project = db.getProjectById((Integer) newTarget.get("projectId"));
                        newTarget.setProject(project);
                    }
                    store.add(newTarget);
                    store.commitChanges();
                    eventBus.fireEvent(AppEvents.SCHEMA_CHANGED);
                    dlg.hide();
                }
            });
        }
    });
}
Also used : ProjectDTO(org.activityinfo.legacy.shared.model.ProjectDTO) FormDialogCallback(org.activityinfo.ui.client.page.common.dialog.FormDialogCallback) CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) PartnerDTO(org.activityinfo.legacy.shared.model.PartnerDTO) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) FormDialogTether(org.activityinfo.ui.client.page.common.dialog.FormDialogTether) AddTarget(org.activityinfo.legacy.shared.command.AddTarget) TargetDTO(org.activityinfo.legacy.shared.model.TargetDTO)

Example 9 with PartnerDTO

use of org.activityinfo.legacy.shared.model.PartnerDTO in project activityinfo by bedatadriven.

the class DbTargetGrid method createColumnModel.

protected ColumnModel createColumnModel() {
    List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
    ColumnConfig projectColumn = new ColumnConfig("projectId", messages.project(), 150);
    projectColumn.setRenderer(new GridCellRenderer() {

        @Override
        public SafeHtml render(ModelData modelData, String s, ColumnData columnData, int i, int i1, ListStore listStore, Grid grid) {
            SafeHtmlBuilder sb = new SafeHtmlBuilder();
            Integer id = modelData.get(s);
            if (id != null) {
                ProjectDTO project = db.getProjectById(id);
                if (project != null) {
                    sb.appendEscaped(project.getName());
                }
            }
            return sb.toSafeHtml();
        }
    });
    ColumnConfig partnerColumn = new ColumnConfig("partnerId", messages.partner(), 150);
    partnerColumn.setRenderer(new GridCellRenderer() {

        @Override
        public SafeHtml render(ModelData modelData, String s, ColumnData columnData, int i, int i1, ListStore listStore, Grid grid) {
            SafeHtmlBuilder sb = new SafeHtmlBuilder();
            Integer id = modelData.get(s);
            if (id != null) {
                PartnerDTO partner = db.getPartnerById(id);
                if (partner != null) {
                    sb.appendEscaped(partner.getName());
                }
            }
            return sb.toSafeHtml();
        }
    });
    columns.add(new ColumnConfig("name", messages.name(), 150));
    columns.add(projectColumn);
    columns.add(partnerColumn);
    columns.add(new TimePeriodColumn("timePeriod", messages.timePeriod(), 300));
    return new ColumnModel(columns);
}
Also used : ProjectDTO(org.activityinfo.legacy.shared.model.ProjectDTO) ModelData(com.extjs.gxt.ui.client.data.ModelData) PartnerDTO(org.activityinfo.legacy.shared.model.PartnerDTO) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) ArrayList(java.util.ArrayList) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) ListStore(com.extjs.gxt.ui.client.store.ListStore) TimePeriodColumn(org.activityinfo.ui.client.page.common.columns.TimePeriodColumn)

Example 10 with PartnerDTO

use of org.activityinfo.legacy.shared.model.PartnerDTO in project activityinfo by bedatadriven.

the class GetPartnersDimensionHandler method execute.

@Override
public void execute(GetPartnersDimension cmd, ExecutionContext context, final AsyncCallback<PartnerResult> callback) {
    final Dimension dimension = new Dimension(DimensionType.Partner);
    PivotSites query = new PivotSites();
    query.setFilter(cmd.getFilter());
    query.setDimensions(dimension);
    query.setValueType(ValueType.TOTAL_SITES);
    if (query.isTooBroad()) {
        callback.onSuccess(new PartnerResult());
        return;
    }
    context.execute(query, new AsyncCallback<PivotSites.PivotResult>() {

        @Override
        public void onSuccess(PivotSites.PivotResult result) {
            Set<PartnerDTO> partners = new HashSet<PartnerDTO>();
            for (Bucket bucket : result.getBuckets()) {
                EntityCategory category = (EntityCategory) bucket.getCategory(dimension);
                if (category == null) {
                    Log.debug("Partner is null: " + bucket.toString());
                } else {
                    PartnerDTO partner = new PartnerDTO();
                    partner.setId(category.getId());
                    partner.setName(category.getLabel());
                    partners.add(partner);
                }
            }
            // sort partners by name (fallback on id)
            List<PartnerDTO> list = new ArrayList<PartnerDTO>(partners);
            Collections.sort(list, new Comparator<PartnerDTO>() {

                @Override
                public int compare(PartnerDTO p1, PartnerDTO p2) {
                    int result = p1.getName().compareToIgnoreCase(p2.getName());
                    if (result != 0) {
                        return result;
                    } else {
                        return ((Integer) p1.getId()).compareTo(p2.getId());
                    }
                }
            });
            callback.onSuccess(new PartnerResult(list));
        }

        @Override
        public void onFailure(Throwable caught) {
            callback.onFailure(caught);
        }
    });
}
Also used : PartnerDTO(org.activityinfo.legacy.shared.model.PartnerDTO) GetPartnersDimension(org.activityinfo.legacy.shared.command.GetPartnersDimension) Dimension(org.activityinfo.legacy.shared.reports.model.Dimension) PivotSites(org.activityinfo.legacy.shared.command.PivotSites) Bucket(org.activityinfo.legacy.shared.command.result.Bucket) EntityCategory(org.activityinfo.legacy.shared.reports.content.EntityCategory) PartnerResult(org.activityinfo.legacy.shared.command.result.PartnerResult)

Aggregations

PartnerDTO (org.activityinfo.legacy.shared.model.PartnerDTO)23 Test (org.junit.Test)6 UpdatePartner (org.activityinfo.legacy.shared.command.UpdatePartner)5 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)5 UserResult (org.activityinfo.legacy.shared.command.result.UserResult)4 ProjectDTO (org.activityinfo.legacy.shared.model.ProjectDTO)4 UserPermissionDTO (org.activityinfo.legacy.shared.model.UserPermissionDTO)4 OnDataSet (org.activityinfo.server.database.OnDataSet)4 ArrayList (java.util.ArrayList)3 Filter (org.activityinfo.legacy.shared.command.Filter)3 GetPartnersDimension (org.activityinfo.legacy.shared.command.GetPartnersDimension)3 GetUsers (org.activityinfo.legacy.shared.command.GetUsers)3 UpdateUserPermissions (org.activityinfo.legacy.shared.command.UpdateUserPermissions)3 DuplicateCreateResult (org.activityinfo.legacy.shared.command.result.DuplicateCreateResult)3 PartnerResult (org.activityinfo.legacy.shared.command.result.PartnerResult)3 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)2 GetSchema (org.activityinfo.legacy.shared.command.GetSchema)2 SchemaDTO (org.activityinfo.legacy.shared.model.SchemaDTO)2 SiteDTO (org.activityinfo.legacy.shared.model.SiteDTO)2 FormDialogCallback (org.activityinfo.ui.client.page.common.dialog.FormDialogCallback)2