log on update, only if changes

log on update, only if changes

montoyammontoyam Posts: 568Questions: 136Answers: 5

I see in the asp.net documentation how to log changes/appends/deletes. However, is there a way to detect if no changes are made when the user clicks update? I don't want to log 'non-changes'.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,213Questions: 1Answers: 10,415 Site admin

    If you use the submit: 'changed' or submit: 'allIfChanged option on the client-side (form-options) then Editor won't submit data when there are no changes. So you'd know that there must be a change if you get the server-side events.

    Allan

  • montoyammontoyam Posts: 568Questions: 136Answers: 5

    I tried 'allIfChanged' and 'changed' but it didn't seem to work. It will still create a record without any actual updates.

    Is it because a field is being updated automatically somehow?

        var CaseActionsEditor = new $.fn.dataTable.Editor({
            ajax: {
                url: 'api/CaseActions',
                data: function (d) {
                    var selected = CasesTable.row({ selected: true });
                    if (selected.any()) {
                        d['CaseFilterID'] = selected.data().Cases.CaseID;
                    }
                }
            },
            submit: 'changed',
            table: '#CaseActions',
            fields: [
                { label: "CaseID:", name: "CaseActions.CaseID", type: "hidden" },
                { name: "Cases.CaseNumber", label: "Case Number", type: "readonly" },
                {
                    label: "Action:",
                    name: "CaseActions.ActionID",
                    type: "select",
                    placeholder: "<Select Action>",
                    placeholderValue: 0,
                    placeholderDisabled: false
                },
                {
                    label: "Defendant:",
                    name: "CaseActions.CaseDefendantID",
                    type: "select",
                    placeholder: "<Select Defendant>",
                    placeholderValue: 0,
                    placeholderDisabled: false
                },
                {
                    name: "CaseActions.ActionDate",
                    label: "Action Date",
                    type: "datetime",
                    format: 'MM-DD-YYYY',
                    def: function () {
                        var d = new Date();
                        return d;
                    }
    
                },
                {
                    name: "CaseActions.FollowUpDate",
                    label: "FollowUp Date",
                    type: "datetime",
                    format: 'MM-DD-YYYY',
                    def: function () {
                        var d = new Date();
                        return d;
                    }
     },
                {
                    name: "CaseActions.ActionStatusID",
                    label: "Action Status",
                    type: "select",
                    placeholder: "<Select Status>",
                    placeholderValue: 0,
                    placeholderDisabled: false
                },
                {
                    name: "CaseActions.CompletedDate",
                    label: "Date Completed",
                    type: "datetime",
                    format: 'MM-DD-YYYY',
                    def: function () {
                        var d = new Date();
                        return d;
                    }
    
                },
                {
                    name: "CaseActions.FollowUpStaffID",
                    label: "Staff to Follow Up",
                    type: "select",
                    placeholder: "<Select staff>",
                    placeholderValue: 0,
                    placeholderDisabled: false
                },
                { name: "CaseActions.ActionNote", label: "Note", type: "textarea" },
                { name: "CaseActions.BillingAmount", label: "Amount to Bill" },
                {
                    name: "CaseActions.BilledDate",
                    label: "Date Billed",
                    type: "datetime",
                    format: 'MM-DD-YYYY',
                    def: function () {
                        var d = new Date();
                        return d;
                    }
    
                },
                { name: "CaseActions.EnteredBy", label: "Added By", type: "select" },
                {
                    label: "Date Added:",
                    name: "CaseActions.DateAdded",
                    type: "readonly",
                    def: function () {
                        var d = new Date();
                        return d;
                    }
    
                }
            ]
        });
    
  • montoyammontoyam Posts: 568Questions: 136Answers: 5
        public class CaseActionsController : ApiController
        {
            [Route("api/CaseActions")]
            [HttpGet]
            [HttpPost]
            public IHttpActionResult CaseActions()
            {
                var request = HttpContext.Current.Request;
                var settings = Properties.Settings.Default;
    
                using (var db = new Database(settings.DbType, settings.DbConnection))
                {
                    var response = new Editor(db, "CaseActions", "CaseActionID")
                        .Model<CaseActionsModel>("CaseActions")
    
    
                        .Field(new Field("CaseActions.ActionID")
                            .Validator(Validation.NotEmpty())
                            .Options(new Options()
                                        .Table("Actions")
                                        .Value("ActionID")
                                        .Label("ActionName")
                            )
    
                        )
                        .Field(new Field("CaseActions.CaseDefendantID")
                            .Options(new Options()
                                        .Table("CaseDefendants")
                                        .Value("CaseDefendantID")
                                        .Label(new[] { "DefendantFirstName", "DefendantLastName" })
                                        .Render(row => row["DefendantLastName"] + ", " + row["DefendantFirstName"])
                            )
                        )
                        .Field(new Field("CaseActions.ActionDate")
                            .Validator(Validation.NotEmpty())
                            .GetFormatter(Format.DateSqlToFormat("MM/dd/yyyy"))
                        )
                        .Field(new Field("CaseActions.CompletedDate")
                            .SetFormatter(Format.NullEmpty())
                            .GetFormatter(Format.DateSqlToFormat("MM/dd/yyyy"))
                        )
                        .Field(new Field("CaseActions.FollowUpDate")
                            .SetFormatter(Format.NullEmpty())
                            .GetFormatter(Format.DateSqlToFormat("MM/dd/yyyy"))
                        )
                        .Field(new Field("CaseActions.BillingAmount")
                            .SetFormatter(Format.IfEmpty(0))
                        )
                        .Field(new Field("CaseActions.ActionStatusID")
                            .Validator(Validation.NotEmpty())
                            .Options(new Options()
                                        .Table("ActionStatus")
                                        .Value("ActionStatusID")
                                        .Label("StatusName")
                            )
                        )
                        .Field(new Field("CaseActions.FollowUpStaffID")
                            .Options(new Options()
                                        .Table("Staff")
                                        .Value("StaffID")
                                        .Label(new[] { "StaffFirstName", "StaffLastName" })
                                        .Render(row => row["StaffLastName"] + ", " + row["StaffFirstName"])
                            )
                        )
                        .Field(new Field("CaseActions.EnteredBy")
                            .Options(new Options()
                                        .Table("Staff")
                                        .Value("StaffID")
                                        .Label(new[] { "StaffFirstName", "StaffLastName" })
                                        .Render(row => row["StaffLastName"] + ", " + row["StaffFirstName"])
                            )
                        )
                        .Field(new Field("CaseActions.DateAdded")
                            .Set(false)
                        )
                        .Field(new Field("CaseActions.BilledDate")
                            .SetFormatter(Format.NullEmpty())
                            .GetFormatter(Format.DateSqlToFormat("MM/dd/yyyy"))
                        )
                        .LeftJoin("Cases", "Cases.CaseID", "=", "CaseActions.CaseID")
                            .Field(new Field("Cases.CaseNumber").Set(false))
                        .LeftJoin("CaseDefendants", "CaseDefendants.CaseDefendantID", "=", "CaseActions.CaseDefendantID")
                            .Model<CaseDefendantsModel>("CaseDefendants")
                        .LeftJoin("Actions", "Actions.ActionID", "=", "CaseActions.ActionID")
                            .Field(new Field("Actions.ActionName"))
                        .LeftJoin("ActionStatus", "ActionStatus.ActionStatusID", "=", "CaseActions.ActionStatusID")
                            .Field(new Field("ActionStatus.StatusName"))
                        .LeftJoin("Staff as FollowUpStaff", "FollowUpStaff.StaffID", "=", "CaseActions.FollowUpStaffID")
                            .Field(new Field("FollowUpStaff.StaffFirstName as FollowUpFirstName"))
                            .Field(new Field("FollowUpStaff.StaffLastName as FollowUpLastName"))
                        .LeftJoin("Staff as EnteredByStaff", "EnteredByStaff.StaffID", "=", "CaseActions.EnteredBy")
                            .Field(new Field("EnteredByStaff.StaffFirstName as EnteredByFirstName"))
                            .Field(new Field("EnteredByStaff.StaffLastName as EnteredByLastName"))
                        .Where("CaseActions.CaseID", request.Form["CaseFilterID"]);
    
    
                    response.PostCreate += (sender, e) => _LogChange(db, "create", e.Id, e.Values);
                    response.PostEdit += (sender, e) => _LogChange(db, "create", e.Id, e.Values);
                    response.PostRemove += (sender, e) => _LogChange(db, "create", e.Id, e.Values);
    
                    return Json(
                        response.Process(request).Data()
                    );
                }
            }
    
  • allanallan Posts: 63,213Questions: 1Answers: 10,415 Site admin
    Answer ✓

    submit: 'changed', isn’t a top level option in the Editor configuration. It is part of the form-options object, which can be used with formOptions (one of its child properties) or with methods such as inline().

    Allan

  • montoyammontoyam Posts: 568Questions: 136Answers: 5

    ah, yes. thanks.

        var CaseActionsEditor = new $.fn.dataTable.Editor({
            ajax: {
                url: 'api/CaseActions',
                data: function (d) {
                    var selected = CasesTable.row({ selected: true });
                    if (selected.any()) {
                        d['CaseFilterID'] = selected.data().Cases.CaseID;
                    }
                }
            },
            formOptions: {
                main: {
                    submit: 'allIfChanged'
                }
            },
            
            table: '#CaseActions',
    
This discussion has been closed.