dojo.provide("parus.dictEdit");

dojo.require("dijit.form.ComboBox");
dojo.require("dijit.form._FormWidgetMixin");


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

dojo.declare("parus.checkEdit", [dijit.form.ComboBox], {
  postCreate: function() {
    this.inherited(arguments);
    dojo.query(".dijitArrowButtonInner", this.domNode).addClass("checkButton");
  },

  _onDropDownMouseDown: function() {
    if (!this.disabled) this.dictButtonClick();
    return this.inherited(arguments);
  },

  dictButtonClick: function() {
    //to be overriden
  }
});

dojo.declare("parus.dictEdit", [parus.checkEdit], {

  dictionary: null,

  multiselect: false,

  intermediateChanges: true,

  unitCode: null,

  menu: null,
  catalogMenu: null,
  detailMenu: null,

  autoComplete: false,

  dialogClass: parus.dictionaryDialog,

  onGetGridConditions: function() {

  },

  onGetMenu: function() {

  },

  onGetDetailMenu: function() {

  },

  onGetCatalogMenu: function() {

  },

  onMixInDictionary: function(dictionaryInfo) {

  },

  showingDictionary: false,

  onApplyDictionary: function(dialog) {

  },

  dictButtonClick: function() {
    if (this.onDictButtonClick()) return;

    if (this.dictionary) {

      if (this.showingDictionary) return;

      var dictionaryInfo = parus.dictionaries[this.dictionary];

      dojo.mixin(dictionaryInfo, {
        multiselect: this.multiselect,
        label: this.value,
        dictionary: dictionaryInfo,
        unitCode: this.unitCode || dictionaryInfo.unitCode,
        gridConditions: this.onGetGridConditions(),
        menu: this.menu ? this.menu : this.onGetMenu(),
        detailMenu: this.detailMenu ? this.detailMenu : this.onGetDetailMenu(),
        catalogMenu: this.catalogMenu ? this.catalogMenu : this.onGetCatalogMenu(),
        onApply: dojo.hitch(this, function(dialog) {
          this.setValue(dialog.getLabel());
          this.onApplyDictionary(dialog);
          return true;
        }),

        onClose: dojo.hitch(this, function(dialog) {
          this.showingDictionary = false;
          dijit.focus(this.focusNode);
        })
      });

      this.onMixInDictionary(dictionaryInfo);

      this.showingDictionary = true;
      dijit.hideTooltip(this.domNode);
      setTimeout(dojo.hitch(this, function() {
        new this.dialogClass(dictionaryInfo).show();
      }), 100);
    };

  },

  _checkMenu: function(dialog, menu, onGetMenuCallback) {
    if (!menu && onGetMenuCallback) {
      menu = onGetMenuCallback();
      return menu;
    }
  },

  onDictButtonClick: function() {
    //to be overriden
  },

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

    var inner = dojo.query(".dijitArrowButtonInner", this.domNode);
    inner.removeClass("checkButton");
    inner.addClass("dictButton");

    dojo.query(".dijitArrowButtonChar", this.domNode).forEach(function(node) {
      while (node.childNodes.length > 0)
      node.removeChild(node.firstChild);
      node.appendChild(document.createTextNode(String.fromCharCode(8230)));
    });
  },

  _startSearch: function(key) {
    if (this.showingDictionary) return;
    if (!this.autoComplete) return;
    if (!key) return;
    if (this.store) this.inherited(arguments);
  },

  _itemCount: null,

  postMixInProperties: function() {

    if (this.autoComplete && this.dictionary) this.store = parus.dictionaries._getStore(this.dictionary);

    this.inherited(arguments);

    if (this.autoComplete && this.dictionary) {

      var dictionary = parus.dictionaries[this.dictionary];

      this.searchAttr = dictionary.labelField;

      this.conditions = {};
      this.store.fetch({
        start: 0,
        query: this.onGetGridConditions() || {},
        queryOptions: {
          ignoreCase: true,
          deep: true
        },
        onBegin: dojo.hitch(this, function(cnt) {
          this._itemCount = cnt;
          if (parus.dictionaries._autoCompleteLimit != null) {
            if (this._itemCount >= parus.dictionaries._autoCompleteLimit) {
              this.autoComplete = false;
              this.searchAttr = "";
            }
          }
        })
      });
    }
  }

});

dojo.declare("parus.editableDictEdit", [parus.dictEdit], {

  editDialogClass: null,
  editDetailDialogClass: null,

  allowEditCatalog: null,
  allowMoveCatalog: null,
  moveCatalogQueryID: null,

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

    if (!this.dialogClass || this.dialogClass == parus.dictionaryDialog) this.dialogClass = parus.editableDictionaryDialog;
  },

  onMixInDictionary: function(dictionaryInfo) {
    dojo.mixin(dictionaryInfo, {
      editDialogClass: this.editDialogClass,
      editDetailDialogClass: this.editDetailDialogClass
    });

    if (this.allowEditCatalog != null) dictionaryInfo.allowEditCatalog = this.allowEditCatalog;
    if (this.allowMoveCatalog != null) dictionaryInfo.allowMoveCatalog = this.allowMoveCatalog;
    if (this.moveCatalogQueryID != null) dictionaryInfo.moveCatalogQueryID = this.moveCatalogQueryID;
  }

});

if (!parus) parus = {};

if (!parus.dictionaries) dojo.mixin(parus, {
  dictionaries: {}
});

dojo.mixin(parus.dictionaries, {

  BalanceReportForms: {

    title: "Формы отчетов",
    catalogsQueryID: "catalogsQuery",
    labelField: "CODE",
    keyField: "RN",
    pathQueryID: "BalanceReportFormsPath",
    queryID: "BalanceReportForms",
    catalogLinkFieldName: "CRN",
    unitCode: "BalanceReportForms",
    columns: [{
      name: "Мнемокод",
      field: "CODE",
      width: "121px"
    },
    {
      name: "Наименование",
      field: "NAME",
      width: "200px"
    }]
  },

  AGNLISTByAGNABBR: {

    title: "Контрагенты",

    catalogsQueryID: "catalogsQuery",
    labelField: "AGNABBR",
    keyField: "RN",
    pathQueryID: "AGNLISTByAGNABBRPath",
    queryID: "AGNLIST",
    catalogLinkFieldName: "CRN",
    unitCode: "AGNLIST",

    columns: [{
      name: "Мнемокод",
      field: "AGNABBR",
      width: "121px"
    },
    {
      name: "Наименование",
      field: "AGNNAME",
      width: "200px"
    },
    {
      name: "Идентификационный номер налогоплательщика",
      field: "AGNIDNUMB",
      width: "200px"
    },
    {
      name: "Головная организация",
      field: "HEAD_ORG_NAME",
      width: "200px"
    }]
  },

  AGNLISTByAGNNAME: {

    title: "Контрагенты",

    catalogsQueryID: "catalogsQuery",
    labelField: "AGNNAME",
    keyField: "RN",
    pathQueryID: "AGNLISTByAGNNAMEPath",
    queryID: "AGNLIST",
    catalogLinkFieldName: "CRN",
    unitCode: "AGNLIST",

    columns: [{
      name: "Мнемокод",
      field: "AGNABBR",
      width: "121px"
    },
    {
      name: "Наименование",
      field: "AGNNAME",
      width: "200px"
    },
    {
      name: "Идентификационный номер налогоплательщика",
      field: "AGNIDNUMB",
      width: "200px"
    },
    {
      name: "Головная организация",
      field: "HEAD_ORG_NAME",
      width: "200px"
    }]
  },


  BalanceReportDates: {
    title: "Периодичности представления отчетов",

    labelField: "BDATE",
    queryID: "BalanceReportViewPeriodsDates",
    unitCode: "BalanceReportViewPeriodsDates",

    columns: [{
      name: "Дата представления",
      field: "BDATE",
      dataType: "2",
      sortField: "T.BDATE",
      width: "200px"
    }]
  },

  BalanceReportFormsSections: {
    title: "Разрезы отчетности",

    catalogsQueryID: "BalanceReportFormsSectionsHier",
    labelField: "CODE",
    keyField: "RN",
    pathQueryID: "BalanceReportFormsSectionsHierPath",
    queryID: "BalanceReportFormsSections",
    catalogLinkFieldName: "CRN",
    unitCode: "BalanceReportFormsSections",

    columns: [{
      name: "Мнемокод",
      field: "CODE",
      width: "121px"
    },
    {
      name: "Наименование",
      field: "NAME",
      width: "200px"
    }]
  },


  BalanceCalcTypesOfReport: {
    title: "Типы пересчетов отчетов",

    labelField: "CODE",
    queryID: "BalanceCalcTypesOfReport",
    unitCode: "BalanceCalcType",

    columns: [{
      name: "Мнемокод",
      field: "CODE",
      width: "200px"
    },
    {
      name: "Наименование",
      field: "NAME",
      width: "200px"
    }]
  },


  BalanceCalcType: {
    title: "Типы пересчетов отчетов",

    catalogsQueryID: "catalogsQuery",
    labelField: "CODE",

    keyField: "RN",
    catalogLinkFieldName: "CRN",
    queryID: "BalanceReportRecalcTypes",
    unitCode: "BalanceCalcType",

    pathQueryID: "BalanceReportRecalcTypesPath",

    columns: [{
      name: "Мнемокод",
      field: "CODE",
      width: "200px"
    },
    {
      name: "Наименование",
      field: "NAME",
      width: "200px"
    }]
  },

  CustomFormats: {

    title: "Форматы загрузки-выгрузки в текст",

    catalogsQueryID: "catalogsQuery",
    labelField: "CODE",

    keyField: "RN",
    catalogLinkFieldName: "CRN",
    queryID: "CustomFormats",
    unitCode: "BalanceTextFormats",

    pathQueryID: "CustomFormatsPath",

    columns: [{
      name: "Мнемокод",
      field: "CODE",
      width: "200px"
    },
    {
      name: "Наименование",
      field: "NAME",
      width: "200px"
    }]


  },


  UnionAgentsGroups: {

    title: "Группы контрагентов",

    catalogsQueryID: "catalogsQuery",
    labelField: "CODE",

    keyField: "RN",
    catalogLinkFieldName: "CRN",
    queryID: "UnionAgentsGroups",
    unitCode: "UnionAgentsGroups",

    pathQueryID: "UnionAgentsGroupsPath",

    columns: [{
      name: "Мнемокод",
      field: "CODE",
      width: "200px"
    },
    {
      name: "Наименование",
      field: "NAME",
      width: "200px"
    }]


  },


  BalanceReportsChecks: {
    title: "Перечни проверок",

    keyField: "RN",
    labelField: "CODE",

    queryID: "BalanceReportFormsCheckLists",

    unitCode: "BalanceReportFormsCheckLists",

    columns: [{
      name: "Мнемокод",
      field: "CODE",
      width: "100px"
    },

    {
      name: "Наименование",
      field: "NAME",
      width: "100px"
    },

    {
      name: "Периодичность",
      field: "PERIOD",
      width: "100px"
    },

    {
      name: "Основной перечень",
      field: "MAIN",
      width: "120px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatBoolean(data, rowIndex, column)
      }
    },

    {
      name: "Форма",
      field: "FORM_CODE",
      width: "125px"
    },

    {
      name: "Редакция действует с",
      field: "BEGDATE",
      dataType: "2",
      sortField: "E.BEGDATE",
      width: "125px"
    },


    {
      name: "Редакция действует по",
      field: "ENDDATE",
      dataType: "2",
      sortField: "E.ENDDATE",
      width: "150px"
    }]


  },

  BalanceReportsStatusesHistory: {

    title: "История статусов отчета",

    labelField: "CHANGEDATE",
    queryID: "BalanceReportsStatusesHistory",
    unitCode: "BalanceReportsStatusesHistory",
    hasAttributes: true,

    columns: [{
      name: "Дата",
      field: "CHANGEDATE",
      dataType: "2",
      sortField: "T.CHANGE_DATE",
      width: "200px"
    },
    {
      name: "Статус",
      field: "STATUS_NAME",
      width: "121px"
    },

    {
      name: "Пользователь",
      field: "NAME",
      width: "200px"
    },

    {
      name: "Способ установки",
      field: "SET_MODE",
      formatter: function(data, rowIndex, column) {
        return parus.balance.formatReportStatusSetMode(data, rowIndex, column)
      },
      width: "200px"
    },

    {
      name: "Действие",
      field: "ACTION_NAME",
      width: "200px"
    }

    ]

  },


  BalanceSubReportsStatusesHistory: {

    title: "История статусов подотчета",

    labelField: "CHANGEDATE",
    queryID: "BalanceSubReportsStatusesHistory",
    unitCode: "BalanceSubReportsStatusesHistory",
    hasAttributes: true,

    columns: [{
      name: "Дата",
      field: "CHANGEDATE",
      dataType: "2",
      sortField: "T.CHANGE_DATE",
      width: "200px"
    },
    {
      name: "Статус",
      field: "STATUS_NAME",
      width: "121px"
    },

    {
      name: "Пользователь",
      field: "NAME",
      width: "200px"
    },

    {
      name: "Способ установки",
      field: "SET_MODE",
      formatter: function(data, rowIndex, column) {
        return parus.balance.formatReportStatusSetMode(data, rowIndex, column)
      },
      width: "200px"
    },

    {
      name: "Действие",
      field: "ACTION_NAME",
      width: "200px"
    }

    ]

  },

  BalanceReportsStatesHistory: {
    title: "История состояний отчета",

    labelField: "CHANGEDATE",
    queryID: "BalanceReportsStatesHistory",
    unitCode: "BalanceReportsStatesHistory",
    hasAttributes: true,

    columns: [{
      name: "Дата",
      field: "CHANGEDATE",
      dataType: "2",
      sortField: "T.CHANGEDATE, T.RN",
      width: "200px"
    },
    {
      name: "Состояние",
      field: "STATE",
      formatter: function(data, rowIndex, column) {
        return parus.balance.formatReportStatus(data, rowIndex, column)
      },
      width: "200px"
    },
    {
      name: "Пользователь",
      field: "NAME",
      width: "200px"
    }]
  },

  BalanceReportsValuesHistory: {
    title: "История значений отчета",

    keyField: "RN",
    labelField: "REPORT_DATE",
    queryID: "BalanceReportsValuesHistory",
    unitCode: "BalanceReportsValuesHistory",

    columns: [{
      name: "Пользователь",
      field: "USERNAME",
      width: "200px"
    },
    {
      name: "Дата",
      field: "REPORT_DATE",
      dataType: "2",
      sortField: "T.REPORT_DATE",
      width: "200px"
    },
    {
      name: "Примечание",
      field: "NOTE",
      width: "200px"
    }]
  },

  ConditionFolders: {
    title: "Папки отбора",

    queryID: "ConditionFolders",

    keyField: "RN",
    labelField: "NAME",

    columns: [{
      name: "Папки",
      field: "NAME",
      width: "200px"
    }]
  },


  BalanceCompareReportRuleSectionGroups: {

    title: "Группы разрезов",

    queryID: "BalanceCompareReportRuleSectionGroups",
    unitCode: "BalanceCompareReportRuleSectionGroups",
    labelField: "CODE",

    columns: [{
      name: "Мнемокод",
      field: "CODE",
      width: "200px"
    },
    {
      name: "Наименование",
      field: "NAME",
      width: "200px"
    }

    ]

  },


  ConsolidationReports: {
    title: "Вхождения",

    queryID: "ConsolidationReports",

    keyField: "RN",

    hasAttributes: true,
    unitCode: "BalanceReportsConstition",

    columns: [{
      name: "Форма",
      field: "CODE",
      width: "150px"
    },
    {
      name: "Дата",
      field: "BDATE",
      dataType: "2",
      sortField: "R.BDATE",
      width: "81px"
    },

    /*2*/ {
      name: "Контрагент <br/> <span style=\"font-size:80%;\">(мнемокод)</span>",
      field: "AGNABBR",
      width: "121px"
    },
    {
      name: "Контрагент <br/> <span style=\"font-size:80%;\">(наименование)</span>",
      field: "AGNNAME",
      width: "161px"
    },
    {
      name: "Тип отчета",
      field: "KIND",
      width: "81px",
      formatter: function(data, rowIndex, column) {
        return parus.balance.formatReportKind(data, rowIndex, column)
      }
    },

    {
      name: "Состояние",
      field: "STATE",
      width: "100px",
      formatter: function(data, rowIndex, column) {
        return parus.balance.formatReportStatus(data, rowIndex, column)
      }
    },
    {
      name: "Проверен",
      field: "CHECKED",
      width: "81px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatBoolean(data, rowIndex, column)
      }
    },
    {
      name: "Отправлен",
      field: "SENT",
      width: "81px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatBoolean(data, rowIndex, column)
      }
    },

    {
      name: "Принят",
      field: "ACCEPTED",
      width: "81px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatBoolean(data, rowIndex, column)
      }
    },
    {
      name: "Статус",
      field: "STATUS_NAME",
      width: "121px"
    },


    /*10*/ {
      name: "Контрагент <br/> <span style=\"font-size:80%;\">(мнемокод)</span>",
      field: "AGNABBR1",
      width: "121px"
    },
    {
      name: "Контрагент <br/> <span style=\"font-size:80%;\">(наименование)</span>",
      field: "AGNNAME1",
      width: "161px"
    },
    {
      name: "Тип отчета",
      field: "KIND1",
      width: "81px",
      formatter: function(data, rowIndex, column) {
        return parus.balance.formatReportKind(data, rowIndex, column)
      }
    },

    {
      name: "Состояние",
      field: "STATE1",
      width: "100px",
      formatter: function(data, rowIndex, column) {
        return parus.balance.formatReportStatus(data, rowIndex, column)
      }
    },
    {
      name: "Проверен",
      field: "CHECKED1",
      width: "81px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatBoolean(data, rowIndex, column)
      }
    },
    {
      name: "Отправлен",
      field: "SENT1",
      width: "81px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatBoolean(data, rowIndex, column)
      }
    },

    {
      name: "Принят",
      field: "ACCEPTED1",
      width: "81px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatBoolean(data, rowIndex, column)
      }
    },
    {
      name: "Статус",
      field: "STATUS_NAME1",
      width: "121px"
    }

    ]
  },


  ConsolidationProposal: {
    title: "Состав свода",

    queryID: "ConsolidationProposal",

    keyField: "RN",

    hasAttributes: true,
    unitCode: "BalanceReportsConstition",

    columns: [{
      name: "Форма",
      field: "CODE",
      width: "150px"
    },
    {
      name: "Дата",
      field: "BDATE",
      dataType: "2",
      sortField: "R.BDATE",
      width: "81px"
    },

    {
      name: "Контрагент <br/> <span style=\"font-size:80%;\">(мнемокод)</span>",
      field: "AGNABBR",
      width: "121px"
    },
    {
      name: "Контрагент <br/> <span style=\"font-size:80%;\">(наименование)</span>",
      field: "AGNNAME",
      width: "150px"
    },

    {
      name: "Тип отчета",
      field: "KIND",
      width: "81px",
      formatter: function(data, rowIndex, column) {
        return parus.balance.formatReportKind(data, rowIndex, column)
      }
    },

    {
      name: "В своде",
      field: "CONSOLIDATED",
      width: "100px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatBoolean(data, rowIndex, column)
      }
    }

    ]
  },


  AttachedDocumentTypes: {
    title: "Типы присоединенных документов",

    queryID: "AttachedDocumentTypes",
    pathQueryID: "AttachedDocumentTypesPath",
    keyField: "RN",
    labelField: "CODE",

    catalogsQueryID: "catalogsQuery",
    catalogLinkFieldName: "CRN",

    unitCode: "FileLinksTypes",

    columns: [{
      name: "Мнемокод",
      field: "CODE",
      width: "150px"
    },
    {
      name: "Наименование",
      field: "NAME",
      sortField: "NAME",
      width: "81px"
    },
    {
      name: "Тип содержимого",
      field: "CONTENT_TYPE",
      width: "150px",
      formatter: function(data, rowIndex, column) {
        return parus.balance.formatAttachedContentFileType(data, rowIndex, column)
      }
    },
    {
      name: "Каталог присоединенных документов",
      field: "CRNFLNKS_NAME",
      sortField: "CRNFLNKS_NAME",
      width: "300px"
    }]
  },

  BalanceCompareReportRules: {

    title: "Правила сравнения отчетов",

    queryID: "BalanceCompareReportRules",
    pathQueryID: "BalanceCompareReportRulesPath",
    keyField: "RN",
    labelField: "CODE",

    catalogsQueryID: "catalogsQuery",
    catalogLinkFieldName: "CRN",

    unitCode: "BalanceCompareReportRules",

    columns: [{
      name: "Мнемокод",
      field: "CODE",
      sortField: "T.CODE",
      width: "150px"
    },
    {
      name: "Наименование",
      field: "NAME",
      sortField: "T.NAME",
      width: "300px"
    },
    {
      name: "Форма отчета",
      field: "FORM_CODE",
      sortField: "F.CODE",
      width: "150px"
    },

    {
      name: "Таблица показателей",
      field: "TABLE_CODE",
      sortField: "B.CODE",
      width: "150px"
    },
    {
      name: "Допускается изменение активности критериев сравнения",
      field: "CRITERIA_SIGN",
      sortField: "T.CRITERIA_SIGN",
      width: "350px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatBoolean(data, rowIndex, column)
      }
    }]
  },


  BalanceRemarkStates: {

    title: "Статусы замечаний",

    labelField: "CODE",
    queryID: "BalanceRemarkStates",
    unitCode: "BalanceRemarkStates",

    columns: [{
      name: "Мнемокод",
      field: "CODE",
      sortField: "T.CODE",
      width: "200px"
    },

    {
      name: "Наименование",
      field: "NAME",
      sortField: "T.NAME",
      width: "200px"
    },
    {
      name: "Цвет",
      field: "COLOR",
      sortField: "T.COLOR",
      width: "200px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatColor(data, rowIndex, column)
      }
    }]



  },


  Users: {

    title: "Пользователи",

    queryID: "Users",
    pathQueryID: "UsersPath",
    keyField: "RN",
    labelField: "AUTHID",

    catalogsQueryID: "catalogsQuery",
    catalogLinkFieldName: "CRN",

    unitCode: "Users",

    columns: [{
      name: "Имя",
      field: "AUTHID",
      width: "120px"
    },
    {
      name: "Наименование",
      field: "NAME",
      sortField: "NAME",
      width: "250px"
    },

    {
      name: "Дата создания пользователя БД",
      field: "CREATED",
      width: "120px"
    },
    {
      name: "Режим доступа",
      field: "USER_MODE",
      width: "100px"
    },
    {
      name: "Максимальное количество одновременных сеансов",
      field: "LOGIN_ENABLED",
      width: "180px"
    },
    {
      name: "Регистрация начала/завершения сеанса",
      field: "REGISTER_SIGN",
      width: "150px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatBoolean(data, rowIndex, column)
      }
    },
    {
      name: "Продолжительность неиспользования учетной записи (дни)",
      field: "LOGIN_ENABLED_LIFE",
      width: "180px"
    },

    {
      name: "Анонимный пользователь",
      field: "ANONYMOUS",
      width: "100px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatBoolean(data, rowIndex, column)
      }
    },
    {
      name: "Фоновый пользователь",
      field: "BACKGROUND",
      width: "100px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatBoolean(data, rowIndex, column)
      }
    },
    {
      name: "Доступна работа через WIN-клиент",
      field: "CLIENT_WIN",
      width: "150px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatBoolean(data, rowIndex, column)
      }
    },
    {
      name: "Пользователь может сменить пароль БД",
      field: "PASSWORD_CHANGE",
      width: "150px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatBoolean(data, rowIndex, column)
      }
    },
    {
      name: "Пользователь может сменить WEB-пароль",
      field: "PASSWORD_CHANGE_WEB",
      width: "150px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatBoolean(data, rowIndex, column)
      }
    },
    {
      name: "Доступно сохранение/считывание параметров соединения",
      field: "USE_SETTINGS_SIGN",
      width: "180px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatBoolean(data, rowIndex, column)
      }
    },
    {
      name: "Доступно сохранение/считывание пароля",
      field: "SAVE_PASSWORD_SIGN",
      width: "150px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatBoolean(data, rowIndex, column)
      }
    },
    {
      name: "Доступна работа через WEB-клиент",
      field: "CLIENT_WEB",
      width: "150px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatBoolean(data, rowIndex, column)
      }
    },
    {
      name: "Максимальное количество попыток начала WEB-сеанса",
      field: "LOGON_TRY_WEB",
      width: "200px"
    },
    {
      name: "Продолжительность блокировки начала WEB-сеанса (мин.)",
      field: "LOGON_LOCK_WEB",
      width: "200px"
    },
    {
      name: "Пароль WEB-пользователя",
      field: "PASSWORD_WEB",
      width: "150px"
    },
    {
      name: "Необходимо сменить пароль WEB-пользователя",
      field: "PASSWORD_MSTCHG_WEB",
      width: "180px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatBoolean(data, rowIndex, column)
      }
    },
    {
      name: "Учетная запись заблокирована",
      field: "ACC_LOCK",
      width: "120px"
    },
    {
      name: "Дата блокировки учетной записи",
      field: "ACC_LOCK_DATE",
      width: "120px"
    },
    {
      name: "Учетная запись WIN-пользователя заблокирована",
      field: "ACC_LOCK_WIN",
      width: "100px"
    },
    {
      name: "Дата блокировки учетной записи WIN-пользователя",
      field: "ACC_LOCK_DATE_WIN",
      width: "150px"
    },
    {
      name: "Учетная запись WEB-пользователя заблокирована",
      field: "ACC_LOCK_WEB",
      width: "150px"
    },
    {
      name: "Дата блокировки учетной записи WEB-пользователя",
      field: "ACC_LOCK_DATE_WEB",
      width: "150px"
    },
    {
      name: "Используемый профиль безопасности",
      field: "SEC_NAME",
      width: "200px"
    }


    ]

  },

  UserExternalAccounts: {

    title: "Логины внешних провайдеров аутентификации",

    queryID: "UserExternalAccounts",
    keyField: "RN",
    labelField: "CODE",

    columns: [{
      name: "Провайдер",
      field: "PROVIDER_NAME",
      width: "120px"
    },
    {
      name: "Примечание о провайдере",
      field: "PROVIDER_NAME",
      width: "180px"
    },
    {
      name: "Наименование логина",
      field: "CODE",
      width: "120px"
    },
    {
      name: "Организация",
      field: "COMPANY_NAME",
      width: "120px"
    },
    {
      name: "Приложение",
      field: "APPNAME",
      width: "180px"
    }]

  },

  UserProcedures: {
    title: "Пользовательские процедуры",

    queryID: "allUserProcs",
    pathQueryID: "UserProcsPath",
    keyField: "RN",
    labelField: "CODE",

    catalogsQueryID: "catalogsQuery",
    catalogLinkFieldName: "CRN",

    unitCode: "UserProcedures",

    columns: [{
      name: "Мнемокод",
      field: "CODE",
      width: "150px"
    },
    {
      name: "Наименование",
      field: "NAME",
      sortField: "NAME",
      width: "250px"
    },


    {
      name: "Тип",
      field: "PROCTYPE",
      width: "150px",
      formatter: function(data, rowIndex, column) {
        return parus.balance.formatUserProcedureType(data, rowIndex, column)
      }
    },


    {
      name: "Способ исполнения",
      field: "PROCAUTO",
      width: "150px",
      formatter: function(data, rowIndex, column) {
        return parus.balance.formatUserProcedureAuto(data, rowIndex, column)
      }
    },

    {
      name: "Имя хранимой процедуры",
      field: "PROCNAME",
      width: "150px"
    },

    {
      name: "Блокировка при выполнении",
      field: "LOCK4EXEC",
      width: "150px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatBoolean(data, rowIndex, column)
      }
    },

    {
      name: "Пиктограмма",
      field: "SYSIMAGE_CODE",
      width: "100px"
    },

    {
      name: "Преобразована",
      field: "BLK2PRC",
      width: "100px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatBoolean(data, rowIndex, column)
      }
    }]
  },


  catalogsQuery: {
    title: "Выбор каталога",

    queryID: "catalogsQuery",
    keyField: "ID",
    labelField: "NAME",

    columns: [{
      name: "Каталоги",
      field: "NAME",
      width: "300px"
    }]
  },

  ConditionSchemesElementsParamsValues: {

    title: "Список значений",

    labelField: "CAPTION",
    queryID: "ConditionSchemesElementsParamsValues",
    unitCode: "ConditionSchemesElementsParamsValues",

    columns: [{
      name: "Значение",
      field: "CAPTION",
      sortField: "T.CAPTION",
      width: "200px"
    }]

  },

  MessagesJournal: {

    title: "Журнал сообщений",

    labelField: "MSG_TEXT",

    queryID: "MessagesJournal",
    columns: [{
      name: "Вид сообщения",
      field: "RECTYPE",
      sortField: "T.RECTYPE",
      width: "160px",
      formatter: function(data, rowIndex, column) {
        return parus.balance.formatMessageRectype(data, rowIndex, column)
      }
    },


    {
      name: "Текст сообщения",
      field: "MSG_TEXT",
      sortField: "T.MSG_TEXT",
      width: "400px"
    }]

  },

  BalanceReportExchangeKinds: {
    title: "Виды обмена отчетностью",

    queryID: "BalanceReportExchangeKinds",
    keyField: "RN",
    labelField: "CODE",

    unitCode: "BalanceReportExchangeKinds",

    columns: [{
      name: "Мнемокод",
      field: "CODE",
      sortField: "T.CODE",
      width: "150px"
    },
    {
      name: "Наименование",
      field: "NAME",
      sortField: "T.NAME",
      width: "300px"
    },
    {
      name: "Обмен через WEB",
      field: "WEB_SIGN",
      sortField: "T.WEB_SIGN",
      width: "150px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatBoolean(data, rowIndex, column)
      }
    },
    {
      name: "Шаблон имени файла",
      field: "FILE_PATTERN",
      sortField: "T.FILE_PATTERN",
      width: "200px"
    },
    {
      name: "Шаблон имени архива",
      field: "ARCH_PATTERN",
      sortField: "T.ARCH_PATTERN",
      width: "200px"
    },

    {
      name: "Процедура формирования имени файла",
      field: "FILE_PROC_CODE",
      sortField: "U2.CODE",
      width: "200px"
    },
    {
      name: "Процедура разбора заголовочной части файла",
      field: "HEADER_PROC_CODE",
      sortField: "U.CODE",
      width: "200px"
    },
    {
      name: "Процедура формирования имени архива",
      field: "ARCH_PROC_CODE",
      sortField: "U3.CODE",
      width: "200px"
    },
    {
      name: "Кодировка файла",
      field: "CHARSET",
      sortField: "T.CHARSET",
      width: "200px",
      formatter: function(data, rowIndex, column) {
        return parus.balance.formatCharset(data, rowIndex, column)
      }
    }]
  },

  BalanceStatusModelHistory: {
    title: "История статусов",

    queryID: "BalanceStatusModelHistory",
    keyField: "RN",
    labelField: "CHANGEDATE",

    unitCode: "BalanceStatusModelHistory",

    columns: [{
      name: "Дата изменения",
      field: "CHANGEDATE",
      dataType: "2",
      sortField: "T.CHANGE_DATE",
      width: "200px"
    },
    {
      name: "Действие",
      field: "ACTION_NAME",
      width: "200px"
    },

    {
      name: "Автор",
      field: "AUTHNAME",
      width: "200px"
    },

    {
      name: "Статус",
      field: "EVENT_STAT",
      width: "200px"
    },

    {
      name: "Описание",
      field: "EVENT_DESCR",
      width: "200px"
    },

    {
      name: "Отметка об исполнении",
      field: "PERF_MARK",
      width: "200px"
    },

    {
      name: "Организация клиента",
      field: "CLIENT_CLIENT",
      width: "200px"
    },

    {
      name: "Сотрудник клиента",
      field: "CLIENT_PERSON",
      width: "200px"
    },

    {
      name: "Клиент",
      field: "CLIENT",
      width: "200px"
    },

    {
      name: "Направить",
      field: "SEND",
      width: "200px"
    },

    {
      name: "Направить (контрагент)",
      field: "SEND_PERSON_AGNCODE",
      width: "200px"
    },

    {
      name: "Заголовок примечания",
      field: "NOTE_HEADER",
      width: "200px"
    },

    {
      name: "Примечание",
      field: "NOTE",
      width: "200px"
    },

    {
      name: "Автор примечания",
      field: "NOTE_AUTHNAME",
      width: "200px"
    },

    {
      name: "Действие в разделе",
      field: "LINKED_ACTION_NAME",
      width: "200px"
    },

    {
      name: "Основание изменения",
      field: "REASON",
      width: "200px"
    },

    {
      name: "Связанный раздел",
      field: "ACTREC_UNTINAME",
      width: "200px"
    },

    {
      name: "Действие со связанной записью раздела",
      field: "ACTREC_NAME",
      width: "200px"
    }

    ]

  },

  BalanceStatusModelNotes: {
    title: "Примечания",

    queryID: "BalanceStatusModelNotes",
    keyField: "RN",
    labelField: "NUMB",

    unitCode: "BalanceStatusModelNotes",

    columns: [{
      name: "Номер",
      field: "NUMB",
      width: "121px"
    },
    {
      name: "Дата последнего изменения",
      field: "CHANGE_DATE_NOTE",
      dataType: "2",
      sortField: "T.CHANGE_DATE",
      width: "200px"
    },
    {
      name: "Заголовок примечания",
      field: "NOTE_HEADER",
      width: "200px"
    },

    {
      name: "Автор примечания",
      field: "NOTE_AUTHNAME",
      width: "200px"
    },

    {
      name: "Описание",
      field: "NOTE",
      width: "200px"
    }]

  },

  BalanceStatusModelNextPerformMarks: {
    title: "Допустимые отметки об исполнении",

    queryID: "BalanceStatusModelNextPerformMarks",
    keyField: "PERF_MARK_TYPE",
    labelField: "PERF_MARK_TYPE_CODE",

    unitCode: "BalanceStatusModelNextPerformMarks",

    columns: [{
      name: "Отметка об исполнении",
      field: "PERF_MARK_TYPE_CODE",
      width: "200px"
    },
    {
      name: "Добавлять примечание при проставлении отметки",
      field: "NOTE_ADD_SIGN",
      width: "200px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatBoolean(data, rowIndex, column)
      }
    },
    {
      name: "Автоматическая установка/снятие",
      field: "AUTO_SIGN",
      width: "200px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatBoolean(data, rowIndex, column)
      }
    }]

  },

  BalanceStatusModelPassNextStatus: {
    title: "Доступные точки перехода",

    queryID: "BalanceStatusModelPassNextStatus",
    keyField: "NEXT_POINT_CODE",
    labelField: "NEXT_POINT_NAME",

    unitCode: "BalanceStatusModelPassNextStatus",

    columns: [{
      name: "Наименование точки",
      field: "NEXT_POINT_CODE",
      width: "200px"
    },
    {
      name: "Наименование статуса",
      field: "NEXT_POINT_NAME",
      width: "200px"
    }]

  },

  BalanceReportStatusModels: {
    title: "Статусные модели отчетов",

    catalogsQueryID: "catalogsQuery",
    pathQueryID: "BalanceReportStatusModelsPath",
    catalogLinkFieldName: "CRN",

    queryID: "BalanceReportStatusModels",
    unitCode: "BalanceReportStatusModels",
    labelField: "CODE",
    keyField: "RN",

    columns: [{
      name: "Мнемокод",
      field: "CODE",
      width: "200px"
    },
    {
      name: "Наименование",
      field: "NAME",
      width: "200px"
    }]
  },

  DesignerBalanceReportPeriods: {
    title: "Периодичности представления отчетов",

    keyField: "RN",
    labelField: "CODE",
    queryID: "BalanceReportViewPeriods",
    unitCode: "BalanceReportViewPeriods",

    detailTitle: "Даты представления",
    detailQueryID: "BalanceReportViewPeriodDates",

    columns: [{
      name: "Мнемокод",
      field: "CODE",
      width: "200px"
    },
    {
      name: "Наименование",
      field: "NAME",
      width: "200px"
    }],

    detailColumns: [{
      name: "Дата представления",
      field: "BDATE",
      width: "200px"
    }]
  },

  DesignerTemplateUsers: {

    title: "Пользователи",

    queryID: "designer.Template.Users",
    pathQueryID: "designer.Template.UsersPath",
    keyField: "RN",
    labelField: "NAME",

    catalogsQueryID: "catalogsQuery",
    catalogLinkFieldName: "CRN",

    unitCode: "Users",

    columns: [{
      name: "Имя",
      field: "AUTHID",
      width: "120px"
    },
    {
      name: "Наименование",
      field: "NAME",
      sortField: "NAME",
      width: "250px"
    }]
  },

  DesignerTemplateRoles: {

    title: "Роли",

    queryID: "designer.Template.Roles",
    pathQueryID: "designer.Template.RolesPath",
    keyField: "RN",
    labelField: "ROLENAME",

    catalogsQueryID: "catalogsQuery",
    catalogLinkFieldName: "CRN",

    unitCode: "Roles",

    columns: [{
      name: "Наименование",
      field: "ROLENAME",
      width: "250px"
    }]
  },

  DesignerTemplateTableIndexes: {
    title: "Показатели таблицы",

    queryID: "designer.Template.TableIndexes",
    keyField: "RN",
    labelField: "CODE",

    unitCode: "BalanceTablesIndexes",

    columns: [{
      name: "Показатель",
      field: "CODE",
      width: "200px"
    },
    {
      name: "Столбец",
      field: "COL",
      width: "100px",
      formatter: function(data, rowIndex, column) {
        return "$" + parus.parus8.toLetters(data);
      }
    },
    {
      name: "Строка",
      field: "ROWN",
      width: "100px",
      formatter: function(data, rowIndex, column) {
        return "$" + data.toString();
      }
    }]

  },

  DesignerTemplateTableTotals: {
    title: "Итоги",

    queryID: "designer.Template.TableTotals",
    keyField: "RN",
    labelField: "CODE",

    unitCode: "BalanceTablesTotals",

    columns: [{
      name: "Вид",
      field: "KIND",
      width: "100px",
      formatter: function(data, rowIndex, column) {
        return (["Промежуточный", "Общий"])[data];
      }
    },
    {
      name: "Уровень",
      field: "PRIORITY",
      width: "60px"
    },
    {
      name: "По показателю",
      field: "CODE",
      width: "130px"
    },
    {
      name: "С учетом формулы",
      field: "FORMULA",
      width: "200px"
    },
    {
      name: "Столбец",
      field: "COL",
      width: "70px",
      formatter: function(data, rowIndex, column) {
        return "$" + parus.parus8.toLetters(data);
      }
    },
    {
      name: "Строка",
      field: "ROWN",
      width: "70px",
      formatter: function(data, rowIndex, column) {
        return "$" + data.toString();
      }
    },
    {
      name: "Количество столбцов",
      field: "COL_CNT",
      width: "80px"
    },
    {
      name: "Количество строк",
      field: "ROWN_CNT",
      width: "80px"
    }]

  },

  DesignerBalanceReportFormFormulas: {
    title: "Формулы пересчета",

    queryID: "designer.BalanceReportForm.Formulas",
    keyField: "RN",
    labelField: "CODE",

    unitCode: "BalanceReportFormFormulas",

    columns: [{
      name: "Тип пересчета",
      field: "RECALCTYPE",
      sortField: "RT.CODE",
      width: "200px"
    },
    {
      name: "Действует с",
      field: "BEGINDATE",
      width: "100px",
      dataType: "2"
    },
    {
      name: "Действует по",
      field: "ENDDATE",
      width: "100px",
      dataType: "2"
    },
    {
      name: "Формула",
      field: "USERPROC",
      sortField: "UP.CODE",
      width: "200px"
    }]

  },

  DesignerBalanceReportFormCheckList: {
    title: "Перечни проверок",

    queryID: "designer.BalanceReportForm.CheckList",
    keyField: "RN",
    labelField: "CODE",

    unitCode: "BalanceReportFormCheckList",

    columns: [{
      name: "Мнемокод",
      field: "CODE",
      width: "100px"
    },
    {
      name: "Наименование",
      field: "NAME",
      width: "100px"
    },
    {
      name: "Периодичность",
      field: "PERIOD",
      width: "100px"
    },
    {
      name: "Основной перечень",
      field: "MAIN",
      width: "120px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatBoolean(data, rowIndex, column)
      }
    },
    {
      name: "Форма",
      field: "FORM_CODE",
      width: "125px"
    },
    {
      name: "Редакция действует с",
      field: "BEGDATE",
      width: "125px",
      dataType: "2"
    },
    {
      name: "Редакция действует по",
      field: "ENDDATE",
      width: "125px",
      dataType: "2"
    }]

  },

  BalanceCheckListsWithDetails: {
    title: "Перечень проверок",

    catalogsQueryID: "catalogsQuery",
    labelField: "CODE",

    keyField: "RN",
    catalogLinkFieldName: "CRN",
    queryID: "designer.BalanceCheckLists",
    unitCode: "BalanceCheckLists",

    pathQueryID: "designer.BalanceCheckListsPath",

    moveDocumentQueryID: "designer.BalanceCheckLists.Move",

    detailTitle: "Проверки",
    detailQueryID: "designer.BalanceChecks",

    columns: [{
      name: "Мнемокод",
      field: "CODE",
      width: "200px"
    },
    {
      name: "Наименование",
      field: "NAME",
      width: "200px"
    }],

    detailColumns: [{
      name: "Формула",
      field: "FORMULA_CODE",
      width: "120px"
    },
    {
      name: "Наименование формулы",
      field: "FORMULA_NAME",
      width: "200px"
    },
    {
      name: "Уровень серьезности",
      field: "ERROR_LEVEL",
      width: "100px",
      formatter: function(data, rowIndex, column) {
        return parus.balance.formatCheckErrorLevel(data, rowIndex, column)
      }
    }]
  },

  BalanceCalcTypeEditable: {
    "extends": "BalanceCalcType",
    title: "Типы пересчета",

    moveDocumentQueryID: "designer.BalanceCalcType.Move"
  },

  UserProceduresWithDetails: {
    "extends": "UserProcedures",

    detailTitle: "Параметры процедуры",
    detailQueryID: "UserProcedureParams",

    detailColumns: [{
      name: "Позиция",
      field: "POSITION",
      width: "60px"
    },
    {
      name: "Наименование параметра",
      field: "PARAMNAME",
      width: "130px"
    },
    {
      name: "Тип данных",
      field: "DATA_TYPE",
      width: "80px",
      formatter: function(data, rowIndex, column) {
        return parus.balance.formatUserProcParamDataType(data, rowIndex, column)
      }
    },
    {
      name: "Тип параметра",
      field: "PARAMTYPE",
      width: "95px",
      formatter: function(data, rowIndex, column) {
        return parus.balance.formatUserProcParamType(data, rowIndex, column)
      }
    },
    {
      name: "Описание параметра",
      field: "NAME",
      width: "150px"
    },
    {
      name: "Визуализация",
      field: "VISUALIZE",
      width: "90px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatBoolean(data, rowIndex, column)
      }
    },
    {
      name: "Привязка",
      field: "LINKING",
      width: "150px",
      formatter: function(data, rowIndex, column) {
        return parus.balance.formatUserProcParamLinking(data, rowIndex, column)
      }
    },
    {
      name: "Обязательный",
      field: "MANDATORY",
      width: "95px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatBoolean(data, rowIndex, column)
      }
    },
    {
      name: "Раздел",
      field: "UNITNAME",
      width: "100px"
    },
    {
      name: "Метод вызова",
      field: "SHOWMETHODNAME",
      width: "100px"
    },
    {
      name: "Параметр",
      field: "PARAM_NAME",
      width: "100px"
    },
    {
      name: "Родительский параметр",
      field: "INITNAME",
      width: "100px"
    },
    {
      name: "Дополнительный словарь",
      field: "SED_NAME",
      width: "110px"
    }]
  },

  DesignerBalanceReportFormLinks: {
    title: "Связанные формы",

    queryID: "designer.BalanceReportForm.Links",
    keyField: "RN",
    labelField: "CODE",

    unitCode: "BalanceReportFormsLinks",

    columns: [{
      name: "Мнемокод формы",
      field: "LINKED_CODE",
      width: "150px"
    },
    {
      name: "Наименование формы",
      field: "LINKED_NAME",
      width: "300px"
    }]

  },

  DesignerBalanceReportFormIndexes: {
    title: "Состав показателей",

    queryID: "designer.BalanceReportForm.Indexes",
    keyField: "RN",
    labelField: "CODE",

    unitCode: "BalanceReportFormsIndexConstition",

    columns: [{
      name: "Показатель",
      field: "BALANCEINDEX",
      width: "150px"
    },
    {
      name: "Наименование показателя",
      field: "BALANCEINDEXNAME",
      width: "200px"
    },
    {
      name: "Тип показателя",
      field: "BITYPE",
      width: "100px",
      formatter: function(data, rowIndex, column) {
        return parus.balance.formatBalanceIndexType(data, rowIndex, column)
      }
    },
    {
      name: "Словарь",
      field: "DICTIONARY",
      width: "150px"
    },
    {
      name: "Очередность расчета",
      field: "PRIORITY",
      width: "100px"
    },
    {
      name: "Допустимо пустое значение",
      field: "NULLABLE",
      width: "120px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatBoolean(data, rowIndex, column)
      }
    },
    {
      name: "Контролировать соответствие значения словарю",
      field: "DICT_CHECK",
      width: "120px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatBoolean(data, rowIndex, column)
      }
    },
    {
      name: "Агрегирующая функция",
      field: "AGR_FUNC",
      width: "150px",
      formatter: function(data, rowIndex, column) {
        return parus.balance.formatBalanceIndexAgrFunc(data, rowIndex, column)
      }
    },
    {
      name: "Выбор строковых данных из примечания словаря",
      field: "DICT_VAL_NOTE",
      width: "130px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatBoolean(data, rowIndex, column)
      }
    }]

  },

  BalanceReportFormsWithDetails: {
    "extends": "BalanceReportForms",

    detailTitle: "Редакции форм",
    detailQueryID: "BalanceReportFormEditions",

    detailColumns: [{
      name: "Действует с",
      field: "BEGDATE",
      dataType: "2",
      width: "121px"
    },
    {
      name: "Действует по",
      field: "ENDDATE",
      dataType: "2",
      width: "121px"
    },
    {
      name: "Периодичность",
      field: "PERIOD_CODE",
      sortField: "P.CODE",
      width: "121px"
    },
    {
      name: "Автопересчет",
      field: "AUTOCALC",
      width: "121px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatBoolean(data, rowIndex, column)
      }
    },
    {
      name: "Примечание",
      field: "NOTES",
      width: "200px"
    },
    {
      name: "Расчёт итоговых подотчетов по умолчанию",
      field: "RESULTS",
      width: "200px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatBoolean(data, rowIndex, column)
      }
    },
    {
      name: "Тип пересчета по умолчанию",
      field: "CALC_CODE",
      sortField: "TR1.CODE",
      width: "200px"
    }]
  },

  DesignerBalanceSections: {
    title: "Разрезы отчетности",

    queryID: "designer.BalanceSections",
    keyField: "RN",
    labelField: "CODE",

    unitCode: "BalanceSections",

    catalogsQueryID: "hierQuerySingle",
    catalogLinkFieldName: "CRN",
    pathQueryID: "designer.BalanceSectionsPath",

    moveDocumentQueryID: "designer.BalanceSections.Move",

    columns: [{
      name: "Мнемокод",
      field: "CODE",
      width: "200px"
    },
    {
      name: "Наименование",
      field: "NAME",
      width: "200px"
    }]

  },

  ExtraDictionariesWithDetails: {
    title: "Дополнительные словари",

    queryID: "ExtraDictionaries",
    keyField: "RN",
    labelField: "CODE",
    unitCode: "ExtraDictionaries",

    catalogsQueryID: "catalogsQuery",
    catalogLinkFieldName: "CRN",
    pathQueryID: "ExtraDictionariesPath",

    detailTitle: "Значения словаря",
    detailQueryID: "ExtraDictionaryValues",

    columns: [{
      name: "Мнемокод",
      field: "CODE",
      width: "120px"
    },
    {
      name: "Наименование",
      field: "NAME",
      width: "200px"
    },
    {
      name: "Формат данных",
      field: "FORMAT",
      width: "150px",
      formatter: function(data, rowIndex, column) {
        return parus.balance.formatBalanceIndexType(data, rowIndex, column)
      }
    },
    {
      name: "Точность числовых данных",
      field: "NUM_WIDTH",
      width: "150px"
    },
    {
      name: "Количество знаков после запятой",
      field: "NUM_PRECISION",
      width: "150px"
    },
    {
      name: "Длина строковых данных",
      field: "STR_WIDTH",
      width: "150px"
    }],

    detailColumns: [{
      name: "Значение",
      field: "VALUE",
      width: "200px"
    },
    {
      name: "Примечание",
      field: "NOTE",
      width: "300px"
    }]

  },

  DesignerBalanceIndexesWithDetails: {
    title: "Показатели",

    queryID: "designer.BalanceIndexes",
    keyField: "RN",
    labelField: "CODE",
    unitCode: "BalanceIndexes",

    catalogsQueryID: "catalogsQuery",
    catalogLinkFieldName: "CRN",
    pathQueryID: "designer.BalanceIndexesPath",

    moveDocumentQueryID: "designer.BalanceIndexes.Move",

    detailTitle: "Формулы пересчета",
    detailQueryID: "designer.BalanceIndexes.Formulas",

    columns: [{
      name: "Мнемокод",
      field: "CODE",
      width: "120px"
    },
    {
      name: "Наименование",
      field: "NAME",
      width: "200px"
    },
    {
      name: "Тип",
      field: "BITYPE",
      width: "150px",
      formatter: function(data, rowIndex, column) {
        return parus.balance.formatBalanceIndexType(data, rowIndex, column)
      }
    }],

    detailColumns: [{
      name: "Тип пересчета",
      field: "RECALCTYPE",
      sortField: "RT.CODE",
      width: "200px"
    },
    {
      name: "Действует с",
      field: "BEGINDATE",
      dataType: "2",
      width: "100px"
    },
    {
      name: "Действует по",
      field: "ENDDATE",
      dataType: "2",
      width: "100px"
    },
    {
      name: "Формула",
      field: "USERPROC",
      sortField: "UP.CODE",
      width: "150px"
    }]
  },

  DesignerBalanceIndexesWithDetails: {
    title: "Показатели",

    queryID: "designer.BalanceIndexes",
    keyField: "RN",
    labelField: "CODE",
    unitCode: "BalanceIndexes",

    catalogsQueryID: "catalogsQuery",
    catalogLinkFieldName: "CRN",
    pathQueryID: "designer.BalanceIndexesPath",

    moveDocumentQueryID: "designer.BalanceIndexes.Move",

    detailTitle: "Формулы пересчета",
    detailQueryID: "designer.BalanceIndexes.Formulas",

    columns: [{
      name: "Мнемокод",
      field: "CODE",
      width: "120px"
    },
    {
      name: "Наименование",
      field: "NAME",
      width: "200px"
    },
    {
      name: "Тип",
      field: "BITYPE",
      width: "150px",
      formatter: function(data, rowIndex, column) {
        return parus.balance.formatBalanceIndexType(data, rowIndex, column)
      }
    }],

    detailColumns: [{
      name: "Тип пересчета",
      field: "RECALCTYPE",
      sortField: "RT.CODE",
      width: "200px"
    },
    {
      name: "Действует с",
      field: "BEGINDATE",
      dataType: "2",
      width: "100px"
    },
    {
      name: "Действует по",
      field: "ENDDATE",
      dataType: "2",
      width: "100px"
    },
    {
      name: "Формула",
      field: "USERPROC",
      sortField: "UP.CODE",
      width: "150px"
    }]
  },

  DesignerBalanceIndexesInputPatterns: {
    title: "Шаблоны ввода значений показателей",

    queryID: "designer.BalanceIndexes.InputPatterns",
    keyField: "RN",
    labelField: "CODE",
    unitCode: "BalanceIndexesInputPatterns",

    catalogsQueryID: "catalogsQuery",
    catalogLinkFieldName: "CRN",
    pathQueryID: "designer.BalanceIndexes.InputPatternsPath",

    moveDocumentQueryID: "designer.BalanceIndexes.InputPatterns.Move",

    columns: [{
      name: "Мнемокод",
      field: "CODE",
      width: "120px"
    },
    {
      name: "Наименование",
      field: "NAME",
      width: "150px"
    },
    {
      name: "Текст шаблона",
      field: "PATTERN",
      width: "150px"
    },
    {
      name: "Примечание",
      field: "NOTE",
      width: "150px"
    }]
  },

  DesignerBalanceIndexesGroupsWithDetails: {
    title: "Группы показателей",

    queryID: "designer.BalanceIndexes.Groups",
    keyField: "RN",
    labelField: "CODE",
    unitCode: "BalanceIndexesGroups",

    detailTitle: "Показатели в составе группы",
    detailQueryID: "designer.BalanceIndexes.GroupsParts",

    columns: [{
      name: "Мнемокод",
      field: "CODE",
      width: "200px"
    },
    {
      name: "Наименование",
      field: "NAME",
      width: "200px"
    }],

    detailColumns: [{
      name: "Показатель",
      field: "BALANCEINDEX",
      width: "200px"
    },
    {
      name: "Тип показателя",
      field: "BITYPE",
      width: "150px",
      formatter: function(data, rowIndex, column) {
        return parus.balance.formatBalanceIndexType(data, rowIndex, column)
      }
    },
    {
      name: "Наименование",
      field: "BALANCEINDEXNAME",
      width: "200px"
    }]
  },

  DesignerBalanceTablesWithIndexes: {
    title: "Таблицы показателей формы",

    queryID: "designer.BalanceTables",
    keyField: "RN",
    labelField: "CODE",
    unitCode: "BalanceTables",

    detailTitle: "Состав показателей",
    detailQueryID: "designer.BalanceTables.Indexes",

    columns: [{
      name: "Таблица показателей",
      field: "CODE",
      width: "140px"
    },
    {
      name: "Наименование таблицы",
      field: "NAME",
      width: "200px"
    },
    {
      name: "Очередность расчета",
      field: "PRIORITY",
      width: "90px"
    },
    {
      name: "Рассчитывать итоги",
      field: "SIGN_TOTALS",
      width: "90px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatBoolean(data, rowIndex, column)
      }
    },
    {
      name: "Перенос неитоговых строк в результаты пересчета",
      field: "SOURCE_TO_RESULT",
      width: "90px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatBoolean(data, rowIndex, column)
      }
    },
    {
      name: "Перенос неитоговых строк в результаты сведения",
      field: "SOURCE_TO_UNION",
      width: "90px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatBoolean(data, rowIndex, column)
      }
    }],

    detailColumns: [{
      name: "Показатель",
      field: "BALANCEINDEX",
      width: "140px"
    },
    {
      name: "Наименование показателя",
      field: "BALANCEINDEXNAME",
      width: "200px"
    },
    {
      name: "Тип показателя",
      field: "BITYPE",
      width: "90px",
      formatter: function(data, rowIndex, column) {
        return parus.balance.formatBalanceIndexType(data, rowIndex, column)
      }
    },
    {
      name: "Словарь",
      field: "DICTIONARY",
      width: "140px"
    },
    {
      name: "Очередность расчета",
      field: "PRIORITY",
      width: "90px"
    },
    {
      name: "Агрегирующая функция",
      field: "AGR_FUNC",
      width: "100px",
      formatter: function(data, rowIndex, column) {
        return parus.balance.formatBalanceIndexAgrFunc(data, rowIndex, column)
      }
    },
    {
      name: "Допустимо пустое значение",
      field: "NULLABLE",
      width: "80px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatBoolean(data, rowIndex, column)
      }
    },
    {
      name: "Контролировать соответствие значения словарю",
      field: "DICT_CHECK",
      width: "120px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatBoolean(data, rowIndex, column)
      }
    },
    {
      name: "Выбор строковых данных из примечаний словаря",
      field: "DICT_VAL_NOTE",
      width: "120px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatBoolean(data, rowIndex, column)
      }
    }]
  },

  DesignerBalanceTablesNotIncludedIndexes: {
    title: "Состав показателей таблицы",

    queryID: "designer.BalanceTables.NotIncludedIndexes",
    keyField: "RN",
    labelField: "BALANCEINDEX",
    unitCode: "BalanceTableModels",

    columns: [{
      name: "Показатель",
      field: "BALANCEINDEX",
      width: "140px"
    },
    {
      name: "Наименование показателя",
      field: "BALANCEINDEXNAME",
      width: "200px"
    },
    {
      name: "Тип показателя",
      field: "BITYPE",
      width: "90px",
      formatter: function(data, rowIndex, column) {
        return parus.balance.formatBalanceIndexType(data, rowIndex, column)
      }
    },
    {
      name: "Очередность расчета",
      field: "PRIORITY",
      width: "90px"
    },
    {
      name: "Агрегирующая функция",
      field: "AGR_FUNC",
      width: "100px",
      formatter: function(data, rowIndex, column) {
        return parus.balance.formatBalanceIndexAgrFunc(data, rowIndex, column)
      }
    }]
  },

  DesignerBalanceTableTotals: {
    title: "Итоги",

    queryID: "designer.BalanceTables.Totals",
    keyField: "RN",
    labelField: "BALANCEINDEX",
    unitCode: "BalanceTablesTotals",

    columns: [{
      name: "Вид",
      field: "KIND",
      width: "120px",
      formatter: function(data, rowIndex, column) {
        return parus.balance.formatBalanceTableTotalKind(data, rowIndex, column)
      }
    },
    {
      name: "Уровень",
      field: "PRIORITY",
      width: "120px"
    },
    {
      name: "По показателю",
      field: "BALANCEINDEX",
      width: "150px"
    },
    {
      name: "С учетом формулы",
      field: "FORMULA",
      width: "150px"
    },
    {
      name: "Расположение",
      field: "LOCATION",
      width: "150px",
      formatter: function(data, rowIndex, column) {
        return parus.balance.formatBalanceTableTotalLocation(data, rowIndex, column)
      }
    }]
  },

  DesignerBalanceTableIndexesWithUnits: {
    title: "Состав показателей таблицы",

    queryID: "designer.BalanceTables.Indexes",
    keyField: "RN",
    labelField: "BALANCEINDEX",
    unitCode: "BalanceTableModels",

    detailTitle: "Связанные разделы",
    detailQueryID: "designer.BalanceTables.Indexes.Units",

    columns: [{
      name: "Показатель",
      field: "BALANCEINDEX",
      width: "140px"
    },
    {
      name: "Наименование показателя",
      field: "BALANCEINDEXNAME",
      width: "200px"
    },
    {
      name: "Тип показателя",
      field: "BITYPE",
      width: "90px",
      formatter: function(data, rowIndex, column) {
        return parus.balance.formatBalanceIndexType(data, rowIndex, column)
      }
    },
    {
      name: "Допустимо пустое значение",
      field: "NULLABLE",
      width: "80px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatBoolean(data, rowIndex, column)
      }
    },
    {
      name: "Словарь",
      field: "DICTIONARY",
      width: "140px"
    },
    {
      name: "Контролировать соответствие значения словарю",
      field: "DICT_CHECK",
      width: "120px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatBoolean(data, rowIndex, column)
      }
    },
    {
      name: "Выбор строковых данных из примечаний словаря",
      field: "DICT_VAL_NOTE",
      width: "120px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatBoolean(data, rowIndex, column)
      }
    },
    {
      name: "Очередность расчета",
      field: "PRIORITY",
      width: "90px"
    },
    {
      name: "Агрегирующая функция",
      field: "AGR_FUNC",
      width: "100px",
      formatter: function(data, rowIndex, column) {
        return parus.balance.formatBalanceIndexAgrFunc(data, rowIndex, column)
      }
    }],

    detailColumns: [{
      name: "Наименование раздела",
      field: "UNITNAME",
      width: "200px"
    },
    {
      name: "Метод вызова",
      field: "METHOD_NAME",
      width: "200px"
    }]
  },

  DesignerBalanceTableConstraintsWithDetails: {
    title: "Ограничения",

    queryID: "designer.BalanceTables.Constraints",
    keyField: "RN",
    labelField: "NAME",
    unitCode: "BalanceTablesConstraints",

    detailTitle: "Атрибуты",
    detailQueryID: "designer.BalanceTables.Constraints.Attributes",

    columns: [{
      name: "Наименование",
      field: "NAME",
      width: "140px"
    },
    {
      name: "Тип ограничения",
      field: "CONSTR_TYPE",
      width: "80px",
      formatter: function(data, rowIndex, column) {
        return parus.balance.formatBalanceTableConstraintType(data, rowIndex, column)
      }
    },
    {
      name: "Текст ограничения",
      field: "TEXT",
      width: "150px"
    },
    {
      name: "Сообщение при нарушении",
      field: "MESSAGE",
      width: "250px"
    },
    {
      name: "Трафарет",
      field: "TEMPLATE",
      width: "150px"
    },
    {
      name: "Ограничение активно",
      field: "ACTIVE_SIGN",
      width: "90px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatBoolean(data, rowIndex, column)
      }
    }],

    detailColumns: [{
      name: "Порядковый номер",
      field: "NUMB",
      width: "200px"
    },
    {
      name: "Показатель",
      field: "BALANCEINDEX",
      width: "200px"
    }]
  },

  BalanceReportFormsTemplates: {
    title: "Трафареты",

    queryID: "BalanceReportFormsTemplates",
    unitCode: "BalanceReportFormsTemplates",
    labelField: "NAME",
    keyField: "RN",

    columns: [{
      name: "Наименование",
      field: "NAME",
      width: "250px"
    },
    {
      name: "Использование",
      field: "USAGE",
      width: "121px",
      formatter: function(data, rowIndex, column) {
        return parus.designerTemplatesDialog.formatUsage(data, rowIndex, column)
      }
    },
    {
      name: "Использовать по умолчанию",
      field: "EDIT_DEFAULT",
      width: "100px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatBoolean(data, rowIndex, column)
      }
    },
    {
      name: "Направление вывода",
      field: "DIRECT_TABLE",
      width: "100px",
      formatter: function(data, rowIndex, column) {
        return parus.designerTemplatesDialog.formatDirection(data, rowIndex, column)
      }
    },
    {
      name: "Выгружать в Excel",
      field: "TO_EXCEL_SIGN",
      width: "100px",
      formatter: function(data, rowIndex, column) {
        return parus.parus8.formatBoolean(data, rowIndex, column)
      }
    }]
  },

  DesignerUnits: { //qqq???
    title: "Разделы системы",

    catalogsQueryID: "catalogsQuery",
    pathQueryID: "designer.UnitsPath",
    catalogLinkFieldName: "CRN",

    queryID: "designer.Units",
    unitCode: "Units",
    labelField: "NAME",
    keyField: "CODE",

    columns: [{
      name: "Мнемокод раздела",
      field: "CODE",
      width: "200px"
    },
    {
      name: "Наименование раздела",
      field: "NAME",
      width: "400px"
    }]
  },

  DesignerBalanceTableModelsWithIndexes: {
    title: "Таблицы показателей",

    queryID: "designer.BalanceTableModels",
    keyField: "RN",
    labelField: "CODE",
    unitCode: "BalanceTableModels",

    catalogsQueryID: "catalogsQuery",
    catalogLinkFieldName: "CRN",
    pathQueryID: "designer.BalanceTableModelsPath",

    moveDocumentQueryID: "designer.BalanceTableModels.Move",

    detailTitle: "Состав показателей",
    detailQueryID: "designer.BalanceTableModels.Indexes",

    columns: [{
      name: "Мнемокод",
      field: "CODE",
      width: "200px"
    },
    {
      name: "Наименование",
      field: "NAME",
      width: "200px"
    }],

    detailColumns: [{
      name: "Показатель",
      field: "BALANCEINDEX",
      width: "140px"
    },
    {
      name: "Наименование показателя",
      field: "BALANCEINDEXNAME",
      width: "200px"
    },
    {
      name: "Тип показателя",
      field: "BITYPE",
      width: "90px",
      formatter: function(data, rowIndex, column) {
        return parus.balance.formatBalanceIndexType(data, rowIndex, column)
      }
    },
    {
      name: "Очередность расчета",
      field: "PRIORITY",
      width: "90px"
    },
    {
      name: "Агрегирующая функция",
      field: "AGR_FUNC",
      width: "100px",
      formatter: function(data, rowIndex, column) {
        return parus.balance.formatBalanceIndexAgrFunc(data, rowIndex, column)
      }
    }]
  },

  DesignerBalanceTableModelIndexes: {
    title: "Состав показателей таблицы",

    queryID: "designer.BalanceTableModels.Indexes",
    keyField: "RN",
    labelField: "BALANCEINDEX",
    unitCode: "BalanceTableModels",

    columns: [{
      name: "Показатель",
      field: "BALANCEINDEX",
      width: "140px"
    },
    {
      name: "Наименование показателя",
      field: "BALANCEINDEXNAME",
      width: "200px"
    },
    {
      name: "Тип показателя",
      field: "BITYPE",
      width: "90px",
      formatter: function(data, rowIndex, column) {
        return parus.balance.formatBalanceIndexType(data, rowIndex, column)
      }
    },
    {
      name: "Очередность расчета",
      field: "PRIORITY",
      width: "90px"
    },
    {
      name: "Агрегирующая функция",
      field: "AGR_FUNC",
      width: "100px",
      formatter: function(data, rowIndex, column) {
        return parus.balance.formatBalanceIndexAgrFunc(data, rowIndex, column)
      }
    }]
  },

  DesignerBalanceTableModelsTotals: {
    title: "Итоги",

    queryID: "designer.BalanceTableModels.Totals",
    keyField: "RN",
    labelField: "CODE",
    unitCode: "BalanceTableModelTotals",

    columns: [{
      name: "Вид",
      field: "KIND",
      width: "120px",
      formatter: function(data, rowIndex, column) {
        return parus.balance.formatBalanceTableTotalKind(data, rowIndex, column)
      }
    },
    {
      name: "Уровень",
      field: "PRIORITY",
      width: "120px"
    },
    {
      name: "По показателю",
      field: "BALANCEINDEX",
      width: "150px"
    },
    {
      name: "С учетом формулы",
      field: "FORMULA",
      width: "150px"
    },
    {
      name: "Расположение",
      field: "LOCATION",
      width: "150px",
      formatter: function(data, rowIndex, column) {
        return parus.balance.formatBalanceTableTotalLocation(data, rowIndex, column)
      }
    }]
  },

  DesignerBalanceTableModelsFormulas: {
    title: "Формулы пересчета",

    queryID: "designer.BalanceTableModels.Formulas",
    keyField: "RN",
    labelField: "CODE",
    unitCode: "BalanceTableModelsFormulas",

    columns: [{
      name: "Тип пересчета",
      field: "RECALCTYPE",
      width: "150px"
    },
    {
      name: "Действует с",
      field: "BEGINDATE",
      dataType: "2",
      width: "120px"
    },
    {
      name: "Действует по",
      field: "ENDDATE",
      dataType: "2",
      width: "120px"
    },
    {
      name: "Формула",
      field: "USERPROC",
      width: "200px"
    }]
  },

  DesignerBalanceTableModelsTotalFormulas: {
    "extends": "DesignerBalanceTableModelsFormulas",

    title: "Формулы коррекции итогов",
    unitCode: "BalanceTableModelsTotalFormulas"
  }

});


dojo.mixin(parus.parus8, {
  extraDictionaries: {

    _canCacheExtraDictionaries: true,

    _autoCompleteLimit: 1000,

    _stores: null,

    getStore: function(code, agent, section) {
      if (!code) return;
      if (!this._stores) this._stores = {};
      var key = code + "*" + (agent || "") + "*" + (section || "");
      var store = this._canCacheExtraDictionaries ? this._stores[key] : null;
      if (!store) {

        var sortOrder = parus.userdata.get("ExtraDictionaries-" + code).sortInfo || 2;

        var sortObj = {
          attribute: ((sortOrder == "2" || sortOrder == "-2") ? "VALUE" : "NOTE"),
          descending: sortOrder < 0,
          field: ((sortOrder == "2" || sortOrder == "-2") ? "VALUE" : "NOTE")
        };

        var order = "EV.STR_VALUE,EV.NUM_VALUE,EV.DATE_VALUE";
        if (sortOrder == "-2") order = "EV.STR_VALUE desc,EV.NUM_VALUE desc,EV.DATE_VALUE desc"
        else if (sortOrder == "2") order = "EV.STR_VALUE,EV.NUM_VALUE,EV.DATE_VALUE"
        else if (sortOrder == "-3") order = "EV.NOTE desc"
        else if (sortOrder == "3") order = "EV.NOTE"


        store = new parus.gridData({
          asJson: true,
          persistent: true,
          __lastSort: dojo.clone(sortObj),
          __lastConditions: {
            __sort: dojo.clone(sortObj)
          },
          _data: parus.database.queryObject("ExtraDictValues", {
            "DICTIONARY": code,
            "AGENT": agent,
            "SECTION": section,
            "order": order
          })
        });


        this._stores[key] = store;
      }
      return store;
    }

  }
});

dojo.declare("parus.extraDictEdit", [parus.dictEdit], {

  autoComplete: true,

  extraDictionaryCode: null,

  arbitrary: null,

  agent: null,

  section: null,

  searchAttr: "VALUE",

  _savedSearchAttr: null,

  conditions: null,

  _itemCount: null,

  _focusTimeOut: null,

  validator: function(value) {

    var result = this.inherited(arguments);

    if (result) {

      if (!this.required && !value) return true;

      if (this.arbitrary) return true;

      if (!value) return true;

      var found = this.store.find(this._savedSearchAttr, value);

      if (!found) if (!this._focusTimeOut) this._focusTimeOut = setTimeout(dojo.hitch(this, function() {
        this._focusTimeOut = null;
        dijit.focus(this.focusNode);
      }), 10);

      return !!found;

    }
    return result;
  },

  _dictionaryDialog: null,

  dictButtonClick: function() {

    if (this.showingDictionary) return;

    this.showingDictionary = true;

    this.menu = new dijit.Menu({
      "class": "balanceMenu"
    });

    this.menu.addChild(new dijit.MenuItem({
      label: "Отобрать...",
      itemAction: false,
      onClick: dojo.hitch(this, function() {
        this._dictionaryDialog.executeConditions();
      })
    }));

    this._dictionaryDialog = new this.dialogClass({

      title: "Выбор из словаря",

      label: this.value,

      multiselect: this.multiselect,

      labelField: this._savedSearchAttr || this.searchAttr,

      gridPersistent: this.store,

      queryID: "ExtraDictValues",

      menu: this.menu,

      userDataSection: "ExtraDictionaries-" + this.extraDictionaryCode,

      dictionary: {
        code: "ExtraDictionaries-" + this.extraDictionaryCode
      },

      gridConditions: this.conditions,

      columns: [{
        name: "Значение",
        field: "VALUE",
        width: "200px"
      },
      {
        name: "Примечание",
        field: "NOTE",
        width: "515px"
      }],

      onApply: dojo.hitch(this, function(dialog) {
        this.setValue(dialog.getLabel());
        this.onApplyDictionary(dialog);
        return true;
      }),

      onClose: dojo.hitch(this, function(dialog) {
        this.showingDictionary = false;
        this._dictionaryDialog = null;
        dijit.focus(this.focusNode);
      }),


      executeConditions: dojo.hitch(this, function() {


        var dialog = new parus.balanceExtraDictionaryConditionsDialog({

          title: "Значения словаря: Отбор",

          onShow: dojo.hitch(this, function() {

            dialog.valueEdit.attr("value", this.conditions["VALUE"]);
            dialog.noteEdit.attr("value", this.conditions["NOTE"]);
          }),

          onApply: dojo.hitch(this, function() {

            this.conditions["VALUE"] = dialog.valueEdit.value;
            this.conditions["NOTE"] = dialog.noteEdit.value;

            if (this.conditions["VALUE"] || this.conditions["NOTE"]) this._dictionaryDialog.filterIndicator.style.display = ""
            else this._dictionaryDialog.filterIndicator.style.display = "none"

            this._dictionaryDialog.headerPane.layout();


            this._dictionaryDialog.grid.setQuery(this.conditions);

            return true;
          })
        });

        dialog.show();


      })


    });

    var settings = parus.userdata.get("ExtraDictionaries-" + this.extraDictionaryCode);
    if (settings) {
      parus.gridSettingsDialog.mergeGridSettings(this._dictionaryDialog.grid, settings.gridSettings);
      parus.gridSettingsDialog.mergeColorConditions(this._dictionaryDialog.grid, settings.colorConditions);
    }

    this._dictionaryDialog.show();

  },

  postMixInProperties: function() {
    this.store = parus.parus8.extraDictionaries.getStore(this.extraDictionaryCode, this.agent, this.section);
    this.inherited(arguments);
    this._savedSearchAttr = this.searchAttr;
    this.conditions = {};
    this.store.fetch({
      start: 0,
      query: this.conditions,
      queryOptions: {
        ignoreCase: true,
        deep: true
      },
      onBegin: dojo.hitch(this, function(cnt) {
        this._itemCount = cnt;
        if (parus.parus8.extraDictionaries._autoCompleteLimit != null) {
          if (this._itemCount >= parus.parus8.extraDictionaries._autoCompleteLimit) {
            this.autoComplete = false;
            this.searchAttr = "";
          }
        }
      })
    });
  }

});


dojo.declare("parus.catalogDictEdit", parus.dictEdit, {

  dictButtonClick: function() {

    var _this = this;

    var path = [];

    if (_this.value) {
      var response = parus.database.query("CatalogsPath", {
        UNITCODE: _this.unitCode,
        NAME: _this.value
      });
      dojo.forEach(parus.parus8.rowNodes(response), function(item) {
        path.push(parus.parus8.nodeField(item, "RN"));
      });
    }

    (new parus.treeDialog({


      model: new parus.catalogTreeModel({
        queryid: "catalogsQuery",
        onGetConditions: dojo.hitch(this, function(model, parentNode) {
          var conditions = {
            "UNITCODE": _this.unitCode
          };
          conditions["CRN"] = parentNode ? model.getIdentity(parentNode) : "!*";
          return conditions;
        })
      }),

      key: _this.unitCode,

      onDefaultNeeded: function() {
        var response = parus.database.execute("findAvailableCatalog", {
          UNITCODE: _this.unitCode
        });
        return response ? parus.parus8.nodeField(parus.parus8.rowNodes(response)[0], "PATH") : null;
      },

      value: path.length ? path.join(";") : null,

      onPerform: function(identity, label) {
        _this.attr("value", label);
        return true;
      }
    })).show();

  }


});

for (var key in parus.dictionaries) {
  dojo.mixin(parus.dictionaries[key], {
    code: key
  });

  //inheritance support
  if (parus.dictionaries[key].hasOwnProperty("extends")) {
    var dest = dojo.clone(parus.dictionaries[parus.dictionaries[key]["extends"]]);
    dojo.mixin(dest, parus.dictionaries[key]);
    parus.dictionaries[key] = dest;
  }
}

dojo.mixin(parus.dictionaries, {

  _autoCompleteLimit: 1000,

  _stores: null,

  _getStore: function(code) {

    if (!code) return;
    if (!this._stores) this._stores = {};
    var store = this._stores[code];
    if (!store) {

      var dictionary = this[code];

      var sortField = dictionary.labelAttr;
      dojo.forEach(dictionary.columns, function(column) {
        if (column.fieldName == dictionary.labelAttr) sortField = column.sortField || dictionary.labelAttr;
      });
      var sortObj = {
        attribute: dictionary.labelAttr,
        descending: false,
        field: sortField
      };

      store = new parus.gridData({
        asJson: true,
        persistent: true,
        __lastSort: dojo.clone(sortObj),
        __lastConditions: {
          __sort: dojo.clone(sortObj)
        },
        _data: parus.database.queryObject(dictionary.queryID, {})
      });

      this._stores[code] = store;
    }
    return store;


  }
});