Search in sources :

Example 6 with LockedPeriodDTO

use of org.activityinfo.shared.dto.LockedPeriodDTO in project activityinfo by bedatadriven.

the class LockedPeriodGrid method getUnsavedItems.

@Override
public List<LockedPeriodDTO> getUnsavedItems() {
    List<LockedPeriodDTO> unsavedItems = new ArrayList<LockedPeriodDTO>();
    List<Record> modifiedRecords = lockedPeriodStore.getModifiedRecords();
    for (Record record : modifiedRecords) {
        unsavedItems.add((LockedPeriodDTO) record.getModel());
    }
    return unsavedItems;
}
Also used : ArrayList(java.util.ArrayList) Record(com.extjs.gxt.ui.client.store.Record) LockedPeriodDTO(org.activityinfo.shared.dto.LockedPeriodDTO)

Example 7 with LockedPeriodDTO

use of org.activityinfo.shared.dto.LockedPeriodDTO in project activityinfo by bedatadriven.

the class LockedPeriodGrid method createGrid.

private void createGrid() {
    List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
    ColumnConfig columnEnabled = new EditCheckColumnConfig("enabled", I18N.CONSTANTS.enabledColumn(), 55);
    columnEnabled.setSortable(false);
    ColumnConfig columnPeriodType = new ReadLockedPeriodTypeColumn();
    columnPeriodType.setSortable(false);
    configs.add(columnEnabled);
    configs.add(columnPeriodType);
    configs.add(new ReadTextColumn("parentName", I18N.CONSTANTS.parentName(), 150));
    configs.add(new ReadTextColumn("name", I18N.CONSTANTS.name(), 100));
    configs.add(new EditableLocalDateColumn("fromDate", I18N.CONSTANTS.fromDate(), 100));
    configs.add(new EditableLocalDateColumn("toDate", I18N.CONSTANTS.toDate(), 100));
    lockedPeriodGrid = new EditorGrid<LockedPeriodDTO>(lockedPeriodStore, new ColumnModel(configs));
    lockedPeriodGrid.addListener(Events.OnClick, new Listener<ComponentEvent>() {

        @Override
        public void handleEvent(ComponentEvent be) {
            lockedPeriod = lockedPeriodGrid.getSelectionModel().getSelectedItem();
            setDeleteEnabled(lockedPeriodGrid.getSelectionModel().getSelectedItem() != null);
        }
    });
    add(lockedPeriodGrid);
}
Also used : ReadLockedPeriodTypeColumn(org.activityinfo.client.page.common.columns.ReadLockedPeriodTypeColumn) EditCheckColumnConfig(org.activityinfo.client.page.common.columns.EditCheckColumnConfig) ColumnConfig(com.extjs.gxt.ui.client.widget.grid.ColumnConfig) ReadTextColumn(org.activityinfo.client.page.common.columns.ReadTextColumn) ArrayList(java.util.ArrayList) EditableLocalDateColumn(org.activityinfo.client.page.common.columns.EditableLocalDateColumn) EditCheckColumnConfig(org.activityinfo.client.page.common.columns.EditCheckColumnConfig) LockedPeriodDTO(org.activityinfo.shared.dto.LockedPeriodDTO) ColumnModel(com.extjs.gxt.ui.client.widget.grid.ColumnModel) ComponentEvent(com.extjs.gxt.ui.client.event.ComponentEvent)

Example 8 with LockedPeriodDTO

use of org.activityinfo.shared.dto.LockedPeriodDTO in project activityinfo by bedatadriven.

the class LockedPeriodsPresenter method onConfirmDelete.

@Override
public void onConfirmDelete(ConfirmDeleteEvent deleteEvent) {
    final LockedPeriodDTO lockedPeriod = view.getValue();
    service.execute(new Delete(lockedPeriod), new AsyncCallback<VoidResult>() {

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

        @Override
        public void onSuccess(VoidResult result) {
            view.delete(lockedPeriod);
            parentModel.getLockedPeriods().remove(lockedPeriod);
        }
    });
}
Also used : Delete(org.activityinfo.shared.command.Delete) VoidResult(org.activityinfo.shared.command.result.VoidResult) LockedPeriodDTO(org.activityinfo.shared.dto.LockedPeriodDTO)

Example 9 with LockedPeriodDTO

use of org.activityinfo.shared.dto.LockedPeriodDTO in project activityinfo by bedatadriven.

the class CreateLockedPeriodHandler method execute.

@Override
public CommandResult execute(CreateLockedPeriod cmd, User user) throws CommandException {
    Activity activity = null;
    UserDatabase database = null;
    Project project = null;
    LockedPeriod lockedPeriod = new LockedPeriod();
    LockedPeriodDTO lockedPeriodDTO = cmd.getLockedPeriod();
    lockedPeriod.setFromDate(lockedPeriodDTO.getFromDate().atMidnightInMyTimezone());
    lockedPeriod.setToDate(lockedPeriodDTO.getToDate().atMidnightInMyTimezone());
    lockedPeriod.setName(lockedPeriodDTO.getName());
    lockedPeriod.setEnabled(lockedPeriodDTO.isEnabled());
    int databaseId;
    if (cmd.getUserDatabseId() != 0) {
        database = em.find(UserDatabase.class, cmd.getUserDatabseId());
        lockedPeriod.setUserDatabase(database);
        databaseId = database.getId();
    } else if (cmd.getProjectId() != 0) {
        project = em.find(Project.class, cmd.getProjectId());
        lockedPeriod.setProject(project);
        databaseId = project.getUserDatabase().getId();
    } else if (cmd.getActivityId() != 0) {
        activity = em.find(Activity.class, cmd.getActivityId());
        lockedPeriod.setActivity(activity);
        databaseId = activity.getDatabase().getId();
    } else {
        throw new CommandException("One of the following must be provdied: userDatabaseId, projectId, activityId");
    }
    UserDatabase db = em.find(UserDatabase.class, databaseId);
    em.persist(lockedPeriod);
    db.setLastSchemaUpdate(new Date());
    em.persist(db);
    if (database != null) {
        database.getLockedPeriods().add(lockedPeriod);
    }
    if (project != null) {
        project.getLockedPeriods().add(lockedPeriod);
    }
    if (activity != null) {
        activity.getLockedPeriods().add(lockedPeriod);
    }
    return new CreateResult(lockedPeriod.getId());
}
Also used : Project(org.activityinfo.server.database.hibernate.entity.Project) CreateResult(org.activityinfo.shared.command.result.CreateResult) UserDatabase(org.activityinfo.server.database.hibernate.entity.UserDatabase) Activity(org.activityinfo.server.database.hibernate.entity.Activity) CommandException(org.activityinfo.shared.exception.CommandException) CreateLockedPeriod(org.activityinfo.shared.command.CreateLockedPeriod) LockedPeriod(org.activityinfo.server.database.hibernate.entity.LockedPeriod) Date(java.util.Date) LockedPeriodDTO(org.activityinfo.shared.dto.LockedPeriodDTO)

Aggregations

LockedPeriodDTO (org.activityinfo.shared.dto.LockedPeriodDTO)9 ArrayList (java.util.ArrayList)3 CreateLockedPeriod (org.activityinfo.shared.command.CreateLockedPeriod)3 CreateResult (org.activityinfo.shared.command.result.CreateResult)3 ActivityDTO (org.activityinfo.shared.dto.ActivityDTO)3 ProjectDTO (org.activityinfo.shared.dto.ProjectDTO)3 UserDatabaseDTO (org.activityinfo.shared.dto.UserDatabaseDTO)2 SqlResultCallback (com.bedatadriven.rebar.sql.client.SqlResultCallback)1 SqlResultSet (com.bedatadriven.rebar.sql.client.SqlResultSet)1 SqlResultSetRow (com.bedatadriven.rebar.sql.client.SqlResultSetRow)1 SqlTransaction (com.bedatadriven.rebar.sql.client.SqlTransaction)1 RowHandler (com.bedatadriven.rebar.sql.client.util.RowHandler)1 LocalDate (com.bedatadriven.rebar.time.calendar.LocalDate)1 ComponentEvent (com.extjs.gxt.ui.client.event.ComponentEvent)1 Record (com.extjs.gxt.ui.client.store.Record)1 ColumnConfig (com.extjs.gxt.ui.client.widget.grid.ColumnConfig)1 ColumnModel (com.extjs.gxt.ui.client.widget.grid.ColumnModel)1 Date (java.util.Date)1 EditCheckColumnConfig (org.activityinfo.client.page.common.columns.EditCheckColumnConfig)1 EditableLocalDateColumn (org.activityinfo.client.page.common.columns.EditableLocalDateColumn)1