Search in sources :

Example 6 with ActivityDTO

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

the class DbEditor method onNew.

private void onNew(String entityName) {
    final EntityDTO newEntity;
    ModelData parent;
    ModelData selected = tree.getSelectionModel().getSelectedItem();
    if (ActivityDTO.ENTITY_NAME.equals(entityName)) {
        newEntity = new ActivityDTO();
        newEntity.set(DATABASE_ID_PROPERTY, db.getId());
        newEntity.set(CLASSIC_VIEW_PROPERTY, true);
        newEntity.set(PUBLISHED_PROPERTY, Published.NOT_PUBLISHED);
        parent = null;
    } else if ("Form".equals(entityName)) {
        newEntity = new ActivityDTO();
        newEntity.set(DATABASE_ID_PROPERTY, db.getId());
        newEntity.set(CLASSIC_VIEW_PROPERTY, false);
        newEntity.set(REPORTING_FREQUENCY_PROPERTY, ActivityFormDTO.REPORT_ONCE);
        newEntity.set(LOCATION_TYPE_ID_PROPERTY, db.getCountry().getNullLocationType().getId());
        newEntity.set(PUBLISHED_PROPERTY, Published.NOT_PUBLISHED);
        parent = null;
    } else if (FolderDTO.ENTITY_NAME.equals(entityName)) {
        newEntity = new FolderDTO(db.getId(), null);
        parent = null;
    } else if (LocationTypeDTO.ENTITY_NAME.equals(entityName)) {
        newEntity = new LocationTypeDTO();
        newEntity.set(DATABASE_ID_PROPERTY, db.getId());
        parent = null;
    } else if (AttributeGroupDTO.ENTITY_NAME.equals(entityName)) {
        IsActivityDTO activity = findActivityFolder(selected);
        AttributeGroupDTO newAttributeGroup = new AttributeGroupDTO();
        newAttributeGroup.setMultipleAllowed(false);
        newEntity = newAttributeGroup;
        newEntity.set("activityId", activity.getId());
        parent = treeStore.getChild((ModelData) activity, 0);
    } else if (AttributeDTO.ENTITY_NAME.equals(entityName)) {
        AttributeGroupDTO group = findAttributeGroupNode(selected);
        newEntity = new AttributeDTO();
        newEntity.set("attributeGroupId", group.getId());
        parent = group;
    } else if (IndicatorDTO.ENTITY_NAME.equals(entityName)) {
        IsActivityDTO activity = findActivityFolder(selected);
        IndicatorDTO newIndicator = new IndicatorDTO();
        newIndicator.setAggregation(IndicatorDTO.AGGREGATE_SUM);
        newIndicator.setType(FieldTypeClass.QUANTITY);
        if (activity instanceof ActivityFormDTO) {
            newIndicator.set(SORT_ORDER_PROPERTY, ((ActivityFormDTO) activity).getIndicators().size() + 1);
        }
        newEntity = newIndicator;
        newEntity.set("activityId", activity.getId());
        parent = treeStore.getChild((ModelData) activity, 1);
    } else {
        Log.error("Unsupported entity type.");
        return;
    }
    createEntity(parent, newEntity);
}
Also used : ModelData(com.extjs.gxt.ui.client.data.ModelData) ActivityDTO(org.activityinfo.legacy.shared.model.ActivityDTO)

Example 7 with ActivityDTO

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

the class DbEditor method onNodeDropped.

private void onNodeDropped(List<TreeStoreModel> data) {
    if (data.isEmpty()) {
        return;
    }
    // update sortOrder and folder membership
    ModelData source = data.get(0).getModel();
    ModelData parent = treeStore.getParent(source);
    LOGGER.info("source = " + source);
    List<ModelData> children = parent == null ? treeStore.getRootItems() : treeStore.getChildren(parent);
    for (int i = 0; i != children.size(); ++i) {
        Record record = treeStore.getRecord(children.get(i));
        record.set("sortOrder", i);
    }
    if (source instanceof ActivityDTO) {
        Record record = treeStore.getRecord(source);
        if (parent instanceof FolderDTO) {
            record.set("folderId", ((FolderDTO) parent).getId());
        } else {
            record.set("folderId", null);
        }
    }
}
Also used : ModelData(com.extjs.gxt.ui.client.data.ModelData) Record(com.extjs.gxt.ui.client.store.Record) ActivityDTO(org.activityinfo.legacy.shared.model.ActivityDTO)

Example 8 with ActivityDTO

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

the class DbEditor method fillStore.

private void fillStore(ActivityDTO activity) {
    ActivityDTO activityNode = new ActivityDTO(activity);
    if (activity.getFolder() != null) {
        treeStore.add(activity.getFolder(), activityNode, false);
    } else {
        treeStore.add(activityNode, false);
    }
    if (!activityNode.getClassicView()) {
        return;
    }
    final AttributeGroupFieldGroup attributeFolder = new AttributeGroupFieldGroup(I18N.CONSTANTS.attributes());
    treeStore.add(activityNode, attributeFolder, false);
    final IndicatorFieldGroup indicatorFolder = new IndicatorFieldGroup(I18N.CONSTANTS.indicators());
    treeStore.add(activityNode, indicatorFolder, false);
    service.execute(new GetActivityForm(activity.getId())).then(new SuccessCallback<ActivityFormDTO>() {

        @Override
        public void onSuccess(ActivityFormDTO activityForm) {
            filleStore(activityForm, attributeFolder, indicatorFolder);
        }
    });
}
Also used : ActivityDTO(org.activityinfo.legacy.shared.model.ActivityDTO)

Example 9 with ActivityDTO

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

the class DesignTreeDropTarget method showFeedback.

@Override
protected void showFeedback(DNDEvent event) {
    final TreePanel.TreeNode overItem = tree.findNode(event.getTarget());
    if (overItem == null) {
        clearStyles(event);
    }
    ModelData sourceModel = tree.getSelectionModel().getSelectedItem();
    ModelData overModel = null;
    if (overItem != null) {
        overModel = overItem.getModel();
        // Dropping a node onto itself? Abort.
        if (overModel == sourceModel) {
            clearStyles(event);
            return;
        }
        // Dropping a node into one of its children? Nope.
        List<ModelData> children = tree.getStore().getChildren(sourceModel, true);
        if (children.contains(overItem.getModel())) {
            clearStyles(event);
            return;
        }
    }
    // Now decide whether this move is legal
    // insert = insert after the overItem as a sibling
    // append = append to the overItem's children
    boolean insert = false;
    boolean append = false;
    // For most items, we will only allow inserting within the same parent
    if (overModel != null && tree.getStore().getParent(sourceModel) == tree.getStore().getParent(overModel)) {
        insert = true;
    }
    // Activities/Forms can be moved into other folders
    if (sourceModel instanceof ActivityDTO) {
        if (overModel == null || overModel instanceof FolderDTO) {
            insert = true;
            append = true;
        }
        if (overModel instanceof ActivityDTO) {
            insert = true;
        }
    }
    // which operation is allowed.
    if (append) {
        setFeedback(DND.Feedback.BOTH);
    } else {
        setFeedback(DND.Feedback.INSERT);
    }
    if (append && overItem == null) {
        handleAppend(event, overItem);
    } else if (insert) {
        handleInsert(event, overItem);
    } else if (append) {
        handleAppend(event, overItem);
    } else {
        if (activeItem != null) {
            tree.getView().onDropChange(activeItem, false);
        }
        status = -1;
        activeItem = null;
        appendItem = null;
        Insert.get().hide();
        event.getStatus().setStatus(false);
    }
}
Also used : ModelData(com.extjs.gxt.ui.client.data.ModelData) FolderDTO(org.activityinfo.legacy.shared.model.FolderDTO) TreePanel(com.extjs.gxt.ui.client.widget.treepanel.TreePanel) ActivityDTO(org.activityinfo.legacy.shared.model.ActivityDTO)

Example 10 with ActivityDTO

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

the class GeoDigestRenderer method renderSites.

private void renderSites(StringBuilder html, DatabaseModel databaseModel, Collection<Integer> siteIds) {
    if (!siteIds.isEmpty()) {
        for (Integer siteId : siteIds) {
            SiteResult siteResult = dispatcher.execute(GetSites.byId(siteId));
            SiteDTO siteDTO = siteResult.getData().get(0);
            ActivityDTO activityDTO = databaseModel.getModel().getSchemaDTO().getActivityById(siteDTO.getActivityId());
            // Check to see if this activity is visible to the user...
            if (activityDTO != null) {
                List<SiteHistory> histories = findSiteHistory(siteId, databaseModel.getModel().getUserDigest().getFrom());
                for (SiteHistory history : histories) {
                    html.append("<span class='geo-site' style='margin-left:10px;'>&bull; ");
                    html.append(I18N.MESSAGES.geoDigestSiteMsg(history.getUser().getEmail(), history.getUser().getName(), activityDTO.getName(), siteDTO.getLocationName()));
                    Date targetDate = databaseModel.getModel().getUserDigest().getDate();
                    Date creationDate = new Date(history.getTimeCreated());
                    if (DateCalc.isOnToday(targetDate, creationDate)) {
                        html.append(I18N.MESSAGES.geoDigestSiteMsgDateToday(creationDate));
                    } else if (DateCalc.isOnYesterday(targetDate, creationDate)) {
                        html.append(I18N.MESSAGES.geoDigestSiteMsgDateYesterday(creationDate));
                    } else {
                        html.append(I18N.MESSAGES.geoDigestSiteMsgDateOther(creationDate));
                    }
                    html.append("</span><br>");
                }
            }
        }
    }
}
Also used : SiteResult(org.activityinfo.legacy.shared.command.result.SiteResult) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) SiteHistory(org.activityinfo.server.database.hibernate.entity.SiteHistory) ActivityDTO(org.activityinfo.legacy.shared.model.ActivityDTO)

Aggregations

ActivityDTO (org.activityinfo.legacy.shared.model.ActivityDTO)11 GetSchema (org.activityinfo.legacy.shared.command.GetSchema)4 UserDatabaseDTO (org.activityinfo.legacy.shared.model.UserDatabaseDTO)4 ModelData (com.extjs.gxt.ui.client.data.ModelData)3 SchemaDTO (org.activityinfo.legacy.shared.model.SchemaDTO)3 MessageBoxEvent (com.extjs.gxt.ui.client.event.MessageBoxEvent)1 Record (com.extjs.gxt.ui.client.store.Record)1 TreePanel (com.extjs.gxt.ui.client.widget.treepanel.TreePanel)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 ArrayList (java.util.ArrayList)1 XFormList (org.activityinfo.io.xform.formList.XFormList)1 XFormListItem (org.activityinfo.io.xform.formList.XFormListItem)1 AuthenticatedUser (org.activityinfo.legacy.shared.AuthenticatedUser)1 Filter (org.activityinfo.legacy.shared.command.Filter)1 GetActivityForm (org.activityinfo.legacy.shared.command.GetActivityForm)1 SiteResult (org.activityinfo.legacy.shared.command.result.SiteResult)1 FolderDTO (org.activityinfo.legacy.shared.model.FolderDTO)1 SiteDTO (org.activityinfo.legacy.shared.model.SiteDTO)1