dojo.provide("parus.editDictionaryDialog");

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

dojo.require("dojox.grid.DataGrid");
dojo.require("dojo.data.ItemFileReadStore");

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

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

  parentDialog: null,
  store: null,
  item: null,

  rn: null,
  prn: null,
  crn: null,

  editMode: false,
  titlePostfix: null,

  postCreate: function() {
    this.inherited(arguments);

    if (this.titlePostfix) this.dialog.titleNode.innerHTML += " " + this.titlePostfix;
    this.onLoadParams(this.store, this.item, this.editMode);
  },

  //to override
  onLoadParams: function(store, item, editMode) {
    if (store) {
      if (item) {
        this.rn = store.getValue(item, "RN");
        this.prn = store.getValue(item, "PRN");
        this.crn = store.getValue(item, "CRN");
      } else {
        if (store.parentRN) this.prn = store.parentRN;
        if (store.catalogRN) this.crn = store.catalogRN;
      }
    }
  },

  getParentDialogCondition: function(field) {
    //get parentDialog PRN (not master grid for detail) - PRN of master grid!
    if (this.parentDialog && this.parentDialog.gridConditions && this.parentDialog.gridConditions.hasOwnProperty(field)) return this.parentDialog.gridConditions[field];
  },

  getParentDialogMasterGridItem: function(fieldName) {
    if (this.parentDialog && this.parentDialog.grid) {
      var grid = this.parentDialog.grid;
      var store = grid.store;
      var item = grid.selection.getFirstSelected();

      return store.getValue(item, fieldName);
    }
  },

  getParentDialogDetailGridItem: function(fieldName) {
    if (this.parentDialog && this.parentDialog.detailGrid) {
      var grid = this.parentDialog.detailGrid;
      var store = grid.store;
      var item = grid.selection.getFirstSelected();

      return store.getValue(item, fieldName);
    }
  },

  executeInsert: function(duplicate) {
    //to override
  },

  executeUpdate: function() {
    //to override
  },

  //static
  executeDelete: function(store, item) {
    //to override
  }

});