package kz.cafe.admin;

import java.util.*;
import kz.cafe.admin.constants.AccessConstants.EditMode;
import kz.cafe.admin.panel_extensions.*;
import kz.cafe.admin.panels.*;
import kz.cafe.admin.panels.model.*;
import kz.cafe.constants.*;
import kz.cafe.db.*;
import kz.cafe.db.model.*;

/**
 * Main application class.
 */
public class TabCafe extends AbstractTab{

   private static final long serialVersionUID = -8282516969343075333L;




   public TabCafe(AdminMain application, Set<EditMode> setMode){
      super(application, setMode);
   }
   
   

   @Override
   public DBListPanel<MCafe> build(){
      CustomDescriptor dscr = new CustomDescriptor();

      CustomField field = new CustomField();
      field.visible = true;
      field.search.mode = CustomField.Search.SEARCH_MODES.INTEGER;
      field.name = "ID";
      field.db = "ID";
      field.isEditable = false;
      field.style.width = 30;
      field.isSortable = true;
      field.search.row = 0;
      dscr.addField(field);



      field = new CustomField();
      field.visible = true;
      field.name = "Название";
      field.db = "name";
      field.isEditable = true;
      field.style.width = 200;
      field.isMust = true;
      field.search.mode = CustomField.Search.SEARCH_MODES.LOCALIZED_STRING;
      dscr.addField(field);


      CustomImageField fieldLogo = new CustomImageField();
      fieldLogo.visible = true;
      fieldLogo.name = "Логотип";
      fieldLogo.db = "image";
      fieldLogo.isEditable = true;
      fieldLogo.style.width = 110;
      fieldLogo.style.height = 110;
      fieldLogo.isImageInTable = false;
      dscr.addField(fieldLogo);




//      CustomComboField ccf = new CustomComboField();
//      ccf.visible = true;
//      ccf.name = "Тип";
//      ccf.db = "type";
//      ccf.isEditable = true;
//      ccf.style.width = 100;
//      ccf.add(new CustomComboField.Element(0, "кафе", null));
//      ccf.add(new CustomComboField.Element(1, "ресторан", null));
//      ccf.add(new CustomComboField.Element(2, "пиццерия", null));
//      ccf.add(new CustomComboField.Element(3, "бар", null));
//      ccf.isMust = true;
//      dscr.addField(ccf);




//      CustomFixedComboField ccf = new CustomFixedComboField();
//      ccf.visible = true;
//      ccf.name = "Тип";
//      ccf.db = "type";
//      ccf.isEditable = true;
//      ccf.style.width = 100;
//      ccf.isMust = true;
//      ccf.search.row = 1;
//      dscr.addField(ccf);
      field = new CustomMultiCombo("Тип", "types", CustomMultiCombo.TYPE.COMBO);
      field.visible = true;
      field.isEditable = true;
      field.style.width = 150;
      field.style.height = 100;
//      field.isSortable = true;
      field.search.mode = CustomField.Search.SEARCH_MODES.BOOLEAN_ONLY_TRUE;
      field.search.row = 3;
      dscr.addField(field);
      




      CustomFixedComboField ccf = new CustomFixedComboField();
      ccf.visible = true;
      ccf.name = "Город";
      ccf.db = "city";
      ccf.isEditable = true;
      ccf.style.width = 100;
      ccf.isMust = true;
      ccf.search.row = 0;
      dscr.addField(ccf);



      
      FCustomController fController = new FCustomController();
      fController.visible = true;
      fController.name = "Резервирование";
      fController.db = "hasReservation";
      fController.isEditable = true;
      fController.style.width = 50;
      fController.isSortable = true;
      fController.search.mode = CustomField.Search.SEARCH_MODES.BOOLEAN_ONLY_TRUE;
      fController.search.row = 3;
      dscr.addField(fController);
      fController.listFields.add("Заказы с");      
      fController.listFields.add("Заказы до");      
      
      

      CustomDateField dateField = new CustomDateField();
      dateField.visible = true;
      dateField.name = "Заказы с";
      dateField.db = "timeOrdersFrom";
      dateField.isEditable = true;
      dateField.style.width = 55;
      dateField.isSortable = true;
      dateField.format = "HH:mm";
      dateField.search.mode = CustomField.Search.SEARCH_MODES.TIME_RANGE;
      dateField.search.row = 0;
      dscr.addField(dateField);
      
      dateField = new CustomDateField();
      dateField.visible = true;
      dateField.name = "Заказы до";
      dateField.db = "timeOrdersTo";
      dateField.isEditable = true;
      dateField.style.width = 55;
      dateField.isSortable = true;
      dateField.format = "HH:mm";
      dateField.search.mode = CustomField.Search.SEARCH_MODES.TIME_RANGE;
      dateField.search.row = 0;
      dscr.addField(dateField);
      
      
      

      fController = new FCustomController();
      fController.visible = true;
      fController.name = "Доставка";
      fController.db = "hasDelivery";
      fController.isEditable = true;
      fController.style.width = 50;
      fController.isSortable = true;
      fController.search.mode = CustomField.Search.SEARCH_MODES.BOOLEAN_ONLY_TRUE;
      fController.search.row = 3;
      fController.listFields.add("Дост. с");      
      fController.listFields.add("Дост. до");      
      dscr.addField(fController);
      
      

      dateField = new CustomDateField();
      dateField.visible = true;
      dateField.name = "Дост. с";
      dateField.db = "timeReservationFrom";
      dateField.isEditable = true;
      dateField.style.width = 50;
      dateField.isSortable = true;
      dateField.format = "HH:mm";
      dateField.search.mode = CustomField.Search.SEARCH_MODES.TIME_RANGE;
      dateField.search.row = 0;
      dscr.addField(dateField);
      
      dateField = new CustomDateField();
      dateField.visible = true;
      dateField.name = "Дост. до";
      dateField.db = "timeReservationTo";
      dateField.isEditable = true;
      dateField.style.width = 50;
      dateField.isSortable = true;
      dateField.format = "HH:mm";
      dateField.search.mode = CustomField.Search.SEARCH_MODES.TIME_RANGE;
      dateField.search.row = 0;
      dscr.addField(dateField);
      
      
      
      
      
      



      ccf = new CustomFixedComboField();
      ccf.type = CustomFixedComboField.TYPE.IMAGE;
      ccf.visible = true;
      ccf.name = "Рейтинг";
      ccf.db = "rate";
      if(application.isAdmin){
         ccf.isEditable = true;
      }
      else{
         ccf.isEditable = false;
      }
      ccf.style.width = 60;
      ccf.add(new CustomFixedComboField.Element(0, "нет", "<img src=\"" + ServerConstants.getImageURL() + "spacer.gif\"/>"));
      ccf.add(new CustomFixedComboField.Element(1, "1", "<img src=\"" + ServerConstants.getImageURL() + "star1.png\"/>"));
      ccf.add(new CustomFixedComboField.Element(2, "2", "<img src=\"" + ServerConstants.getImageURL() + "star2.png\"/>"));
      ccf.add(new CustomFixedComboField.Element(3, "3", "<img src=\"" + ServerConstants.getImageURL() + "star3.png\"/>"));
      ccf.add(new CustomFixedComboField.Element(4, "4", "<img src=\"" + ServerConstants.getImageURL() + "star4.png\"/>"));
      ccf.add(new CustomFixedComboField.Element(5, "5", "<img src=\"" + ServerConstants.getImageURL() + "star5.png\"/>"));
      ccf.isMust = true;
      ccf.search.row = 1;
      dscr.addField(ccf);











//      CustomDateField dateField = new CustomDateField();
//      dateField.visible = true;
//      dateField.name = "Открыто";
//      dateField.db = "timeOpen";
//      dateField.isEditable = true;
//      dateField.style.width = 60;
//      dateField.isSortable = true;
//      dateField.format = "HH:mm";
//      dateField.search.mode = CustomField.Search.SEARCH_MODES.TIME_RANGE;
//      dateField.search.row = 0;
//      dscr.addField(dateField);
//
//      dateField = new CustomDateField();
//      dateField.visible = true;
//      dateField.name = "Закрыто";
//      dateField.db = "timeClose";
//      dateField.isEditable = true;
//      dateField.style.width = 60;
//      dateField.isSortable = true;
//      dateField.format = "HH:mm";
//      dateField.search.mode = CustomField.Search.SEARCH_MODES.TIME_RANGE;
//      dateField.search.row = 0;
//      dscr.addField(dateField);
//      
//      
//      dateField = new CustomDateField();
//      dateField.visible = true;
//      dateField.name = "(вых) Открыто";
//      dateField.db = "timeOpenWeekend";
//      dateField.isEditable = true;
//      dateField.style.width = 80;
//      dateField.isSortable = true;
//      dateField.format = "HH:mm";
//      dateField.search.mode = CustomField.Search.SEARCH_MODES.TIME_RANGE;
//      dateField.search.row = 0;
//      dscr.addField(dateField);
//
//      dateField = new CustomDateField();
//      dateField.visible = true;
//      dateField.name = "(вых) Закрыто";
//      dateField.db = "timeCloseWeekend";
//      dateField.isEditable = true;
//      dateField.style.width = 80;
//      dateField.isSortable = true;
//      dateField.format = "HH:mm";
//      dateField.search.mode = CustomField.Search.SEARCH_MODES.TIME_RANGE;
//      dateField.search.row = 0;
//      dscr.addField(dateField);      


      

      
      dateField = new CustomDateField();
      dateField.visible = true;
      dateField.name = "(Пн) Откр";
      dateField.db = "timeOpenMo";
      dateField.isEditable = true;
      dateField.style.width = 45;
      dateField.isSortable = true;
      dateField.format = "HH:mm";
      dateField.search.mode = CustomField.Search.SEARCH_MODES.TIME_RANGE;
      dateField.search.row = 0;
      dscr.addField(dateField);

      dateField = new CustomDateField();
      dateField.visible = true;
      dateField.name = "(Пн) Закр";
      dateField.db = "timeCloseMo";
      dateField.isEditable = true;
      dateField.style.width = 45;
      dateField.isSortable = true;
      dateField.format = "HH:mm";
      dateField.search.mode = CustomField.Search.SEARCH_MODES.TIME_RANGE;
      dateField.search.row = 0;
      dscr.addField(dateField);
      
      
      
      
      dateField = new CustomDateField();
      dateField.visible = true;
      dateField.name = "(Вт) Откр";
      dateField.db = "timeOpenTu";
      dateField.isEditable = true;
      dateField.style.width = 45;
      dateField.isSortable = true;
      dateField.format = "HH:mm";
      dateField.search.mode = CustomField.Search.SEARCH_MODES.TIME_RANGE;
      dateField.search.row = 0;
      dscr.addField(dateField);

      dateField = new CustomDateField();
      dateField.visible = true;
      dateField.name = "(Вт) Закр";
      dateField.db = "timeCloseTu";
      dateField.isEditable = true;
      dateField.style.width = 45;
      dateField.isSortable = true;
      dateField.format = "HH:mm";
      dateField.search.mode = CustomField.Search.SEARCH_MODES.TIME_RANGE;
      dateField.search.row = 0;
      dscr.addField(dateField);      
      
      

      
      
      dateField = new CustomDateField();
      dateField.visible = true;
      dateField.name = "(Ср) Откр";
      dateField.db = "timeOpenWe";
      dateField.isEditable = true;
      dateField.style.width = 45;
      dateField.isSortable = true;
      dateField.format = "HH:mm";
      dateField.search.mode = CustomField.Search.SEARCH_MODES.TIME_RANGE;
      dateField.search.row = 0;
      dscr.addField(dateField);

      dateField = new CustomDateField();
      dateField.visible = true;
      dateField.name = "(Ср) Закр";
      dateField.db = "timeCloseWe";
      dateField.isEditable = true;
      dateField.style.width = 45;
      dateField.isSortable = true;
      dateField.format = "HH:mm";
      dateField.search.mode = CustomField.Search.SEARCH_MODES.TIME_RANGE;
      dateField.search.row = 0;
      dscr.addField(dateField);
      

      
      
      
      dateField = new CustomDateField();
      dateField.visible = true;
      dateField.name = "(Чт) Откр";
      dateField.db = "timeOpenTh";
      dateField.isEditable = true;
      dateField.style.width = 45;
      dateField.isSortable = true;
      dateField.format = "HH:mm";
      dateField.search.mode = CustomField.Search.SEARCH_MODES.TIME_RANGE;
      dateField.search.row = 0;
      dscr.addField(dateField);

      dateField = new CustomDateField();
      dateField.visible = true;
      dateField.name = "(Чт) Закр";
      dateField.db = "timeCloseTh";
      dateField.isEditable = true;
      dateField.style.width = 45;
      dateField.isSortable = true;
      dateField.format = "HH:mm";
      dateField.search.mode = CustomField.Search.SEARCH_MODES.TIME_RANGE;
      dateField.search.row = 0;
      dscr.addField(dateField);
      
      
      
      
      
      dateField = new CustomDateField();
      dateField.visible = true;
      dateField.name = "(Пт) Откр";
      dateField.db = "timeOpenFr";
      dateField.isEditable = true;
      dateField.style.width = 45;
      dateField.isSortable = true;
      dateField.format = "HH:mm";
      dateField.search.mode = CustomField.Search.SEARCH_MODES.TIME_RANGE;
      dateField.search.row = 0;
      dscr.addField(dateField);

      dateField = new CustomDateField();
      dateField.visible = true;
      dateField.name = "(Пт) Закр";
      dateField.db = "timeCloseFr";
      dateField.isEditable = true;
      dateField.style.width = 45;
      dateField.isSortable = true;
      dateField.format = "HH:mm";
      dateField.search.mode = CustomField.Search.SEARCH_MODES.TIME_RANGE;
      dateField.search.row = 0;
      dscr.addField(dateField);      
      
      
      

      dateField = new CustomDateField();
      dateField.visible = true;
      dateField.name = "(Сб) Откр";
      dateField.db = "timeOpenSa";
      dateField.isEditable = true;
      dateField.style.width = 45;
      dateField.isSortable = true;
      dateField.format = "HH:mm";
      dateField.search.mode = CustomField.Search.SEARCH_MODES.TIME_RANGE;
      dateField.search.row = 0;
      dscr.addField(dateField);

      dateField = new CustomDateField();
      dateField.visible = true;
      dateField.name = "(Сб) Закр";
      dateField.db = "timeCloseSa";
      dateField.isEditable = true;
      dateField.style.width = 45;
      dateField.isSortable = true;
      dateField.format = "HH:mm";
      dateField.search.mode = CustomField.Search.SEARCH_MODES.TIME_RANGE;
      dateField.search.row = 0;
      dscr.addField(dateField);
      
      
      
      
      
      dateField = new CustomDateField();
      dateField.visible = true;
      dateField.name = "(Вс) Откр";
      dateField.db = "timeOpenSu";
      dateField.isEditable = true;
      dateField.style.width = 45;
      dateField.isSortable = true;
      dateField.format = "HH:mm";
      dateField.search.mode = CustomField.Search.SEARCH_MODES.TIME_RANGE;
      dateField.search.row = 0;
      dscr.addField(dateField);

      dateField = new CustomDateField();
      dateField.visible = true;
      dateField.name = "(Вс) Закр";
      dateField.db = "timeCloseSu";
      dateField.isEditable = true;
      dateField.style.width = 45;
      dateField.isSortable = true;
      dateField.format = "HH:mm";
      dateField.search.mode = CustomField.Search.SEARCH_MODES.TIME_RANGE;
      dateField.search.row = 0;
      dscr.addField(dateField);      
      
      
      
      
    dateField = new CustomDateField();
    dateField.visible = true;
    dateField.name = "Открыто";
    dateField.db = "timeOpen";
    dateField.isEditable = true;
    dateField.style.width = 60;
    dateField.isSortable = true;
    dateField.format = "HH:mm";
    dateField.search.mode = CustomField.Search.SEARCH_MODES.TIME_RANGE;
    dateField.search.row = 0;
    dscr.addField(dateField);

    dateField = new CustomDateField();
    dateField.visible = true;
    dateField.name = "Закрыто";
    dateField.db = "timeClose";
    dateField.isEditable = true;
    dateField.style.width = 60;
    dateField.isSortable = true;
    dateField.format = "HH:mm";
    dateField.search.mode = CustomField.Search.SEARCH_MODES.TIME_RANGE;
    dateField.search.row = 0;
    dscr.addField(dateField);
    
    
    dateField = new CustomDateField();
    dateField.visible = true;
    dateField.name = "(вых) Открыто";
    dateField.db = "timeOpenWeekend";
    dateField.isEditable = true;
    dateField.style.width = 80;
    dateField.isSortable = true;
    dateField.format = "HH:mm";
    dateField.search.mode = CustomField.Search.SEARCH_MODES.TIME_RANGE;
    dateField.search.row = 0;
    dscr.addField(dateField);

    dateField = new CustomDateField();
    dateField.visible = true;
    dateField.name = "(вых) Закрыто";
    dateField.db = "timeCloseWeekend";
    dateField.isEditable = true;
    dateField.style.width = 80;
    dateField.isSortable = true;
    dateField.format = "HH:mm";
    dateField.search.mode = CustomField.Search.SEARCH_MODES.TIME_RANGE;
    dateField.search.row = 0;
    dscr.addField(dateField);      
      
      
      
      


    field = new CustomMultiCombo("Сервис", "service", CustomMultiCombo.TYPE.COMBO);
    field.visible = true;
    field.isEditable = true;
    field.isMust = false;
    field.style.width = 200;
    field.style.height = 100;
//    field.isSortable = true;
    field.search.mode = CustomField.Search.SEARCH_MODES.BOOLEAN_ONLY_TRUE;
    field.search.row = 3;
    dscr.addField(field);




    
    field = new CustomMultiCombo("Требования", "faceControl", CustomMultiCombo.TYPE.COMBO);
    field.visible = true;
    field.isEditable = true;
    field.isMust = false;
    field.style.width = 200;
    field.style.height = 100;
    
//    field.isSortable = true;
    field.search.mode = CustomField.Search.SEARCH_MODES.BOOLEAN_ONLY_TRUE;
    field.search.row = 3;
    dscr.addField(field);
    


    
    
    field = new CustomMultiCombo("Кухни", "cuisines", CustomMultiCombo.TYPE.COMBO);
    field.visible = true;
    field.isEditable = true;
    field.isMust = false;
    field.style.width = 200;
    field.style.height = 100;
    
//    field.isSortable = true;
    field.search.mode = CustomField.Search.SEARCH_MODES.BOOLEAN_ONLY_TRUE;
    field.search.row = 4;
    dscr.addField(field);
    



      field = new CustomField();
      field.visible = true;
      field.name = "Описание";
      field.db = "description";
      field.isEditable = true;
      field.style.width  = 800;
      field.style.height = 100;
      field.search.mode = CustomField.Search.SEARCH_MODES.LOCALIZED_STRING;
      field.search.row = 1;
      dscr.addField(field);



      field = new CustomField();
      field.visible = true;
      field.name = "Телефон";
      field.db = "phone";
      field.isEditable = true;
      field.style.width = 100;
      field.search.mode = CustomField.Search.SEARCH_MODES.STRING;
      field.search.row = 1;
      dscr.addField(field);




      field = new CustomField();
      field.visible = true;
      field.name = "Адрес";
      field.db = "address";
      field.isEditable = true;
      field.style.width = 200;
      field.search.mode = CustomField.Search.SEARCH_MODES.STRING;
      field.search.row = 2;
      dscr.addField(field);





      field = new CustomField();
      field.visible = true;
      field.name = "Карта";
      field.db = "coordinates";
      
      if(application.isAdmin) {
         field.isEditable = true;
      }
      else{
         field.isEditable = false;
      }
      field.style.width = 200;
      //field.search.mode = CustomField.Search.SEARCH_MODES.STRING;
      field.search.row = 1;
      dscr.addField(field);

      
      ccf = new CustomFixedComboField();
      ccf.type = CustomFixedComboField.TYPE.IMAGE;
      ccf.visible = true;
      ccf.name = "Ср.Cчет";
      ccf.db = "price";
      ccf.isEditable = true;
      ccf.style.width = 50;
      ccf.add(new CustomFixedComboField.Element(0, "$", "<img src=\"" + ServerConstants.getImageURL() + "dollar1.png\"/>"));
      ccf.add(new CustomFixedComboField.Element(1, "$$", "<img src=\"" + ServerConstants.getImageURL() + "dollar2.png\"/>"));
      ccf.add(new CustomFixedComboField.Element(2, "$$$", "<img src=\"" + ServerConstants.getImageURL() + "dollar3.png\"/>"));
      ccf.isMust = true;
      ccf.search.row = 1;
      dscr.addField(ccf);
      
      
      
      field = new CustomField();
      field.visible = true;
      field.name = "Ср. счет (от)";
      field.db = "bill_average_min";
      field.isEditable = true;
      field.style.width  = 80;
      field.style.expandable = false;
      field.search.mode = CustomField.Search.SEARCH_MODES.INTEGER_RANGE;
      field.search.row = 3;
      dscr.addField(field);
      
      
      field = new CustomField();
      field.visible = true;
      field.name = "Ср. счет (до)";
      field.db = "bill_average_max";
      field.isEditable = true;
      field.style.width  = 80;
      field.style.expandable = false;
      field.search.mode = CustomField.Search.SEARCH_MODES.INTEGER_RANGE;
      field.search.row = 3;
      dscr.addField(field);
      

      
      field = new CustomField();
      field.visible = true;
      field.name = "Всего столиков";
      field.db = "tableTotal";
      field.isEditable = true;
      field.style.width  = 80;
      field.style.expandable = false;
      field.search.mode = CustomField.Search.SEARCH_MODES.INTEGER_RANGE;
      field.search.row = 3;
      dscr.addField(field);
      
      
      field = new CustomField();
      field.visible = true;
      field.name = "Из них свободно";
      field.db = "tableFree";
      field.isEditable = true;
      field.style.width  = 80;
      field.style.expandable = false;
      field.search.mode = CustomField.Search.SEARCH_MODES.INTEGER_RANGE;
      field.search.row = 3;
      dscr.addField(field);
      



      if(application.isAdmin){
         ccf = new CustomFixedComboField();
         ccf.visible = true;
         ccf.name = "Владелец";
         ccf.db = MAbstractDataElement.F_OWNER_ID;
         ccf.isEditable = true;
         ccf.style.width = 120;
         ccf.isMust = true;
         //ccf.search.mode = CustomField.Search.SEARCH_MODES.NONE;
         ccf.search.row = 2;
         dscr.addField(ccf);
      }





      dateField = new CustomDateField();
      dateField.visible = true;
      dateField.name = "Создан";
      dateField.db = "created";
      dateField.isEditable = false;
      dateField.style.width = 120;
      dateField.isSortable = true;
      dateField.search.mode = CustomField.Search.SEARCH_MODES.DATE_RANGE;
      dateField.search.row = 2;
      dscr.addField(dateField);





      dateField = new CustomDateField();
      dateField.visible = true;
      dateField.name = "Обновлен";
      dateField.db = "updated";
      dateField.isEditable = false;
      dateField.style.width = 120;
      dateField.isSortable = true;
      dateField.search.mode = CustomField.Search.SEARCH_MODES.DATE_RANGE;
      dateField.search.row = 2;
      dscr.addField(dateField);



      field = new CustomField();
      field.visible = true;
      field.name = "Опубликовано";
      field.db = "published";
      field.isEditable = true;
      field.style.width = 50;
      field.isSortable = true;
      field.search.mode = CustomField.Search.SEARCH_MODES.BOOLEAN_ONLY_TRUE;
      field.search.row = 3;
      dscr.addField(field);


      Constraint constraint = new Constraint();


      if(application.isAdmin){
      }
      else{
         constraint.criteria.add(new Constraint.Criterion(MUser.F_OWNER_ID,    application.UID));
      }




      DBListPanel<MCafe> panel = new DBListPanel<MCafe>(application,
                                          MCafe.class,
                                          dscr,
                                          Dimension.getFull(application),
                                          setMode,
                                          constraint);
      panel.addPanel(new ExtraPanelGoogleMap(panel, "Карта"), false);
      panel.addPanel(new ExtraPanelImageUploader(panel, fieldLogo), false);
      panel.addPanel(new ExtraPanelImageViewer(panel, fieldLogo), true);
      panel.addPanel(new ExtraPanelMenu(application, panel), false);
      panel.addPanel(new ExtraPanelFeedbacks(application, panel), false);


      return panel;
   }


   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   @Override
   public DBSingle<MCafe> build(int ID){
      CustomDescriptor dscr = new CustomDescriptor();

      CustomField field = new CustomField();
      field.visible = true;
      field.search.mode = CustomField.Search.SEARCH_MODES.INTEGER;
      field.name = "ID";
      field.db = "ID";
      field.isEditable = false;
      field.style.width = 30;
      field.isSortable = true;
      field.search.row = 0;
      dscr.addField(field);



      field = new CustomField();
      field.visible = true;
      field.name = "Название";
      field.db = "name";
      field.isEditable = true;
      field.style.width = 200;
      field.isMust = true;
      field.search.mode = CustomField.Search.SEARCH_MODES.LOCALIZED_STRING;
      dscr.addField(field);


      CustomImageField fieldLogo = new CustomImageField();
      fieldLogo.visible = true;
      fieldLogo.name = "Логотип";
      fieldLogo.db = "image";
      fieldLogo.isEditable = true;
      fieldLogo.style.width = 110;
      fieldLogo.style.height = 110;
      fieldLogo.isImageInTable = false;
      dscr.addField(fieldLogo);




//      CustomComboField ccf = new CustomComboField();
//      ccf.visible = true;
//      ccf.name = "Тип";
//      ccf.db = "type";
//      ccf.isEditable = true;
//      ccf.style.width = 100;
//      ccf.add(new CustomComboField.Element(0, "кафе", null));
//      ccf.add(new CustomComboField.Element(1, "ресторан", null));
//      ccf.add(new CustomComboField.Element(2, "пиццерия", null));
//      ccf.add(new CustomComboField.Element(3, "бар", null));
//      ccf.isMust = true;
//      dscr.addField(ccf);




      CustomFixedComboField ccf = new CustomFixedComboField();
      ccf.visible = true;
      ccf.name = "Тип";
      ccf.db = "type";
      ccf.isEditable = true;
      ccf.style.width = 100;
      ccf.isMust = true;
      ccf.search.row = 1;
      dscr.addField(ccf);




      ccf = new CustomFixedComboField();
      ccf.visible = true;
      ccf.name = "Город";
      ccf.db = "city";
      ccf.isEditable = true;
      ccf.style.width = 100;
      ccf.isMust = true;
      ccf.search.row = 0;
      dscr.addField(ccf);





      ccf = new CustomFixedComboField();
      ccf.type = CustomFixedComboField.TYPE.IMAGE;
      ccf.visible = true;
      ccf.name = "Рейтинг";
      ccf.db = "rate";
      ccf.isEditable = true;
      ccf.style.width = 60;
      ccf.add(new CustomFixedComboField.Element(0, "нет", "<img src=\"" + ServerConstants.getImageURL() + "spacer.gif\"/>"));
      ccf.add(new CustomFixedComboField.Element(1, "1", "<img src=\"" + ServerConstants.getImageURL() + "star1.png\"/>"));
      ccf.add(new CustomFixedComboField.Element(2, "2", "<img src=\"" + ServerConstants.getImageURL() + "star2.png\"/>"));
      ccf.add(new CustomFixedComboField.Element(3, "3", "<img src=\"" + ServerConstants.getImageURL() + "star3.png\"/>"));
      ccf.add(new CustomFixedComboField.Element(4, "4", "<img src=\"" + ServerConstants.getImageURL() + "star4.png\"/>"));
      ccf.add(new CustomFixedComboField.Element(5, "5", "<img src=\"" + ServerConstants.getImageURL() + "star5.png\"/>"));
      ccf.isMust = true;
      ccf.search.row = 1;
      dscr.addField(ccf);



      ccf = new CustomFixedComboField();
      ccf.type = CustomFixedComboField.TYPE.IMAGE;
      ccf.visible = true;
      ccf.name = "Ср.Cчет";
      ccf.db = "price";
      ccf.isEditable = true;
      ccf.style.width = 50;
      ccf.add(new CustomFixedComboField.Element(0, "$", "<img src=\"" + ServerConstants.getImageURL() + "dollar1.png\"/>"));
      ccf.add(new CustomFixedComboField.Element(1, "$$", "<img src=\"" + ServerConstants.getImageURL() + "dollar2.png\"/>"));
      ccf.add(new CustomFixedComboField.Element(2, "$$$", "<img src=\"" + ServerConstants.getImageURL() + "dollar3.png\"/>"));
      ccf.isMust = true;
      ccf.search.row = 1;
      dscr.addField(ccf);








      CustomDateField dateField = new CustomDateField();
      dateField.visible = true;
      dateField.name = "Открыто";
      dateField.db = "timeOpen";
      dateField.isEditable = true;
      dateField.style.width = 60;
      dateField.isSortable = true;
      dateField.format = "HH:mm";
      dateField.search.mode = CustomField.Search.SEARCH_MODES.TIME_RANGE;
      dateField.search.row = 0;
      dscr.addField(dateField);

      dateField = new CustomDateField();
      dateField.visible = true;
      dateField.name = "Закрыто";
      dateField.db = "timeClose";
      dateField.isEditable = true;
      dateField.style.width = 60;
      dateField.isSortable = true;
      dateField.format = "HH:mm";
      dateField.search.mode = CustomField.Search.SEARCH_MODES.TIME_RANGE;
      dateField.search.row = 0;
      dscr.addField(dateField);






    field = new CustomField();
    field.visible = true;
    field.name = "Сервис";
    field.db = "service";
    field.isEditable = true;
    field.style.width = 40;
//    field.isSortable = true;
    field.search.mode = CustomField.Search.SEARCH_MODES.BOOLEAN_ONLY_TRUE;
    field.search.row = 3;
    dscr.addField(field);








      field = new CustomField();
      field.visible = true;
      field.name = "Описание";
      field.db = "description";
      field.isEditable = true;
      field.style.width = 200;
      field.search.mode = CustomField.Search.SEARCH_MODES.LOCALIZED_STRING;
      field.search.row = 1;
      dscr.addField(field);



      field = new CustomField();
      field.visible = true;
      field.name = "Телефон";
      field.db = "phone";
      field.isEditable = true;
      field.style.width = 100;
      field.search.mode = CustomField.Search.SEARCH_MODES.STRING;
      field.search.row = 1;
      dscr.addField(field);




      field = new CustomField();
      field.visible = true;
      field.name = "Адрес";
      field.db = "address";
      field.isEditable = true;
      field.style.width = 200;
      field.search.mode = CustomField.Search.SEARCH_MODES.STRING;
      field.search.row = 2;
      dscr.addField(field);





      field = new CustomField();
      field.visible = true;
      field.name = "Карта";
      field.db = "coordinates";
      field.isEditable = true;
      field.style.width = 200;
      //field.search.mode = CustomField.Search.SEARCH_MODES.STRING;
      field.search.row = 1;
      dscr.addField(field);



      if(application.isAdmin){
         ccf = new CustomFixedComboField();
         ccf.visible = true;
         ccf.name = "Владелец";
         ccf.db = MAbstractDataElement.F_OWNER_ID;
         ccf.isEditable = true;
         ccf.style.width = 120;
         ccf.isMust = true;
         //ccf.search.mode = CustomField.Search.SEARCH_MODES.NONE;
         ccf.search.row = 2;
         dscr.addField(ccf);
      }





      dateField = new CustomDateField();
      dateField.visible = true;
      dateField.name = "Создан";
      dateField.db = "created";
      dateField.isEditable = false;
      dateField.style.width = 120;
      dateField.isSortable = true;
      dateField.search.mode = CustomField.Search.SEARCH_MODES.DATE_RANGE;
      dateField.search.row = 2;
      dscr.addField(dateField);





      dateField = new CustomDateField();
      dateField.visible = true;
      dateField.name = "Обновлен";
      dateField.db = "updated";
      dateField.isEditable = false;
      dateField.style.width = 120;
      dateField.isSortable = true;
      dateField.search.mode = CustomField.Search.SEARCH_MODES.DATE_RANGE;
      dateField.search.row = 2;
      dscr.addField(dateField);



      field = new CustomField();
      field.visible = true;
      field.name = "Опубликовано";
      field.db = "published";
      field.isEditable = true;
      field.style.width = 50;
      field.isSortable = true;
      field.search.mode = CustomField.Search.SEARCH_MODES.BOOLEAN_ONLY_TRUE;
      field.search.row = 3;
      dscr.addField(field);


      Constraint constraint = new Constraint();


      if(application.isAdmin){
      }
      else{
         constraint.criteria.add(new Constraint.Criterion(MUser.F_OWNER_ID,    application.UID));
      }




      DBSingle<MCafe> panel = new DBSingle<MCafe>(application,
                                                  MCafe.class,
                                                  ID,
                                                  dscr,
                                                  Dimension.getFull(application),
                                                  setMode
                                                  );


      return panel;
   }
}

