dojo.provide("parus.designerTemplateRoleAndUserAssignDialog");

dojo.require("dijit.Dialog");
dojo.require("dijit.form.Button");
dojo.require("dijit.form.DateTextBox");

dojo.require("parus.parus8");
dojo.require("parus.dialog");
dojo.require("parus.formats");

dojo.require("parus.editDictionaryDialog");

dojo.declare("parus.designerTemplateRoleAndUserAssignDialog", [parus.editDictionaryDialog], {

  onLoadParams: function(store, item, editMode) {
    this.inherited(arguments);

    if (store && item) {
      this.userEdit.attr("value", store.getValue(item, "NAME"));
      this.roleEdit.attr("value", store.getValue(item, "ROLENAME"));
    }
  },

  roleChanged: function() {
    if (this.roleEdit.attr("value")) {
      this.userEdit.attr("value", "");
    }
  },

  userChanged: function() {
    if (this.userEdit.attr("value")) {
      this.roleEdit.attr("value", "");
    }
  },

  executeInsert: function(duplicate) {
    var response = parus.database.execute("designer.Template.RoleAndUserAssignment.Insert", {
      PRN: this.prn,
      USER_NAME: this.userEdit.attr("value"),
      ROLE_NAME: this.roleEdit.attr("value")
    });

    if (response) return parus.parus8.nodeField(parus.parus8.rowNodes(response)[0], "NRN");
  },

  executeUpdate: function() {
    var response = parus.database.execute("designer.Template.RoleAndUserAssignment.Update", {
      RN: this.rn,
      USER_NAME: this.userEdit.attr("value"),
      ROLE_NAME: this.roleEdit.attr("value")
    });

    return !!response;
  },

  executeDelete: function(store, item) {
    var response = parus.database.execute("designer.Template.RoleAndUserAssignment.Delete", {
      RN: store.getValue(item, "RN")
    });

    return !!response;
  }

});