package kz.cafe.admin;

import java.util.*;
import kz.cafe.admin.constants.*;
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.db.*;
import kz.cafe.db.model.*;


public class TabCourse extends AbstractTab{
   private static final long serialVersionUID = 3315039865664276276L;



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




   @Override
   public DBListPanel<MCourse> 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 = 50;
		field.isSortable = true;
		field.search.row = 0;
      dscr.addField(field);
      


      
      
      
      CustomDatabaseComboField cdcf = new CustomDatabaseComboField();
      cdcf.visible = true;
      cdcf.name = "Заведение";
      cdcf.db = "CID";
      cdcf.isEditable = true;
      cdcf.style.width = 110;
      cdcf.isMust = true;
      cdcf.search.row = 1;
      
      if(application.isAdmin){
      }
      else{
         cdcf.constraint.criteria.add(new Constraint.Criterion(MAbstractDataElement.F_OWNER_ID, application.UID));         
      }
      
      dscr.addField(cdcf);
      
      
      
      
      
      
//      CustomRelationField crf = new CustomRelationField(MCafe.class, "КАФЕ (ID)");
//      crf.visible = false;
//      crf.name = "КАФЕ (ID)";
//      crf.db = "CID";
//      crf.isEditable = false;
//      crf.style.width = 30;
//      crf.isMust = true;
//      crf.search.mode = CustomField.Search.SEARCH_MODES.INTEGER;
//      crf.search.row = 1;
//      dscr.addField(crf);
//      
//      
//      
//      
//      crf = new CustomRelationField(MCafe.class, "КАФЕ (ID)");
//      crf.visible = true;
//      crf.name = "Тип";
//      crf.db = "cafe_type";
//      crf.isEditable = false;
//      crf.style.width = 100;
//      crf.isMust = true;
//      crf.search.mode = CustomField.Search.SEARCH_MODES.STRING;
//      crf.search.row = 1;
//      dscr.addField(crf);
//      
//      
//      crf = new CustomRelationField(MCafe.class, "КАФЕ (ID)");
//      crf.visible = true;
//      crf.name = "Кафе";
//      crf.db = "cafe_name";
//      crf.isEditable = false;
//      crf.style.width = 150;
//      crf.isMust = true;
//      crf.search.mode = CustomField.Search.SEARCH_MODES.STRING;
//      crf.search.row = 1;
//      dscr.addField(crf);
      
      
      
      
      
      
      CustomDatabaseComboField ccf = new CustomDatabaseComboField();
      ccf.visible = true;
      ccf.name = "Категория";
      ccf.db = "category";
      ccf.isEditable = true;
      ccf.style.width = 100;
      ccf.isMust = true;
      dscr.addField(ccf);
      

		
		
      field = new CustomField();
      field.visible = true;
      field.name = "Блюдо";
      field.db = "name";
      field.isEditable = true;
      field.style.width = 150;
      field.isMust = true;
      field.search.mode = CustomField.Search.SEARCH_MODES.LOCALIZED_STRING;
      dscr.addField(field);
      
      
      
      

      
      
      
      field = new CustomField();
      field.visible = true;
      //field.searchable = CustomField.SEARCH_MODES.INTEGER;
      
      field.name = "Описание";
      field.db = "description";
      field.isEditable = true;
      field.style.width = 0;
      field.search.mode = CustomField.Search.SEARCH_MODES.LOCALIZED_STRING;
      dscr.addField(field);
      
      
      
      
      
      CustomImageField fieldImage = new CustomImageField();
      fieldImage.visible = true;
      fieldImage.name = "Изображение";
      fieldImage.db = "image";
      fieldImage.isEditable = true;
      fieldImage.style.width = 40;
      fieldImage.style.height = 40;
      fieldImage.isImageInTable = true;
      dscr.addField(fieldImage);
      
      

      
      
      field = new CustomField();
      field.visible = true;
      field.name = "Цена";
      field.db = "price";
      field.isEditable = true;
      field.isMust = true;
      field.style.width = 70;
      field.search.mode = CustomField.Search.SEARCH_MODES.INTEGER;
      field.search.row = 1;
      dscr.addField(field);
      
      

      
      field = new CustomField();
      field.visible = true;
      field.name = "Кол-во/Объем";
      field.db = "weight2";
      field.isEditable = true;
      field.isMust = true;
      field.style.width = 70;
      field.search.mode = CustomField.Search.SEARCH_MODES.NONE;
      field.search.row = 1;
      dscr.addField(field);
      


      field = new CustomField();
      field.visible = true;
      field.name = "Доставка";
      field.db = "delivery";
      field.isEditable = true;
      field.style.width = 60;
      field.isSortable = true;
      field.search.mode = CustomField.Search.SEARCH_MODES.BOOLEAN_ONLY_TRUE; 
      dscr.addField(field);
      
      
      
      
      if(application.isAdmin){
         ccf = new CustomDatabaseComboField();
         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);
      }
      
      
      
      
      
      
      
      CustomDateField 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 = 40;
      field.isSortable = true;
      field.search.mode = CustomField.Search.SEARCH_MODES.BOOLEAN_ONLY_TRUE; 
      field.search.row = 2;
      dscr.addField(field);
      

      
      Constraint constraint = new Constraint();
      
      
      if(application.isAdmin){
      }
      else{
         constraint.criteria.add(new Constraint.Criterion(MAbstractDataElement.F_OWNER_ID, application.UID));
      }
      
      
      
      DBListPanel<MCourse> panel = new DBListPanel<MCourse>(application,
                                                            MCourse.class,
                                                            dscr,
                                                            Dimension.getFull(application),
                                                            setMode,
                                                            constraint);
      panel.addPanel(new ExtraPanelImageUploader(panel, fieldImage), false);
      //panelCourse.addPanel(new ExtraPanelImageViewer(panelCourse, fieldImage, 50), true);
      panel.addPanel(new ExtraPanelMany2Many(application,
                                             "Ингредиенты ...",
                                             MIngredient.class,
                                             "ingredient",
                                             AccessConstants.none(),
                                             panel), false);
      
		
		return panel;
	}
   
   
   
   
   
   
   
   
   
   
   
   
   public static CustomDescriptor buildSelector(){     
      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 = 50;
      field.isSortable = true;
      field.search.row = 0;
      dscr.addField(field);
      
      
      
      
      CustomFixedComboField ccf = new CustomFixedComboField();
      ccf.visible = true;
      ccf.name = "Категория";
      ccf.db = "category";
      ccf.isEditable = true;
      ccf.style.width = 100;
      ccf.isMust = true;
      dscr.addField(ccf);
      

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

      
      
      
      field = new CustomField();
      field.visible = true;
      //field.searchable = CustomField.SEARCH_MODES.INTEGER;
      
      field.name = "Описание";
      field.db = "description";
      field.isEditable = true;
      field.style.width = 0;
      field.search.mode = CustomField.Search.SEARCH_MODES.LOCALIZED_STRING;
      dscr.addField(field);
      
      
      
      
      
      CustomImageField fieldImage = new CustomImageField();
      fieldImage.visible = true;
      fieldImage.name = "Изображение";
      fieldImage.db = "image";
      fieldImage.isEditable = true;
      fieldImage.style.width = 40;
      fieldImage.style.height = 40;
      fieldImage.isImageInTable = true;
      dscr.addField(fieldImage);
      
      
      
      field = new CustomField();
      field.visible = true;
      field.name = "Цена";
      field.db = "price";
      field.isEditable = true;
      field.isMust = true;
      field.style.width = 70;
      field.search.mode = CustomField.Search.SEARCH_MODES.INTEGER_RANGE;
      field.search.row = 1;
      dscr.addField(field);
      

      
      
      
      return dscr;
   }












   @Override
   public DBSingle<MCourse> 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 = 50;
      field.isSortable = true;
      field.search.row = 0;
      dscr.addField(field);
      


      
      
      
      CustomDatabaseComboField cdcf = new CustomDatabaseComboField();
      cdcf.visible = true;
      cdcf.name = "Заведение";
      cdcf.db = "CID";
      cdcf.isEditable = true;
      cdcf.style.width = 110;
      cdcf.isMust = true;
      cdcf.search.row = 1;
      
      if(application.isAdmin){
      }
      else{
         cdcf.constraint.criteria.add(new Constraint.Criterion(MAbstractDataElement.F_OWNER_ID, application.UID));         
      }
      
      dscr.addField(cdcf);
      
      
      
      
      
      
//      CustomRelationField crf = new CustomRelationField(MCafe.class, "КАФЕ (ID)");
//      crf.visible = false;
//      crf.name = "КАФЕ (ID)";
//      crf.db = "CID";
//      crf.isEditable = false;
//      crf.style.width = 30;
//      crf.isMust = true;
//      crf.search.mode = CustomField.Search.SEARCH_MODES.INTEGER;
//      crf.search.row = 1;
//      dscr.addField(crf);
//      
//      
//      
//      
//      crf = new CustomRelationField(MCafe.class, "КАФЕ (ID)");
//      crf.visible = true;
//      crf.name = "Тип";
//      crf.db = "cafe_type";
//      crf.isEditable = false;
//      crf.style.width = 100;
//      crf.isMust = true;
//      crf.search.mode = CustomField.Search.SEARCH_MODES.STRING;
//      crf.search.row = 1;
//      dscr.addField(crf);
//      
//      
//      crf = new CustomRelationField(MCafe.class, "КАФЕ (ID)");
//      crf.visible = true;
//      crf.name = "Кафе";
//      crf.db = "cafe_name";
//      crf.isEditable = false;
//      crf.style.width = 150;
//      crf.isMust = true;
//      crf.search.mode = CustomField.Search.SEARCH_MODES.STRING;
//      crf.search.row = 1;
//      dscr.addField(crf);
      
      
      
      
      
      
      CustomDatabaseComboField ccf = new CustomDatabaseComboField();
      ccf.visible = true;
      ccf.name = "Категория";
      ccf.db = "category";
      ccf.isEditable = true;
      ccf.style.width = 100;
      ccf.isMust = true;
      dscr.addField(ccf);
      

      
      
      field = new CustomField();
      field.visible = true;
      field.name = "Блюдо";
      field.db = "name";
      field.isEditable = true;
      field.style.width = 150;
      field.isMust = true;
      field.search.mode = CustomField.Search.SEARCH_MODES.LOCALIZED_STRING;
      dscr.addField(field);
      
      
      
      

      
      
      
      field = new CustomField();
      field.visible = true;
      //field.searchable = CustomField.SEARCH_MODES.INTEGER;
      
      field.name = "Описание";
      field.db = "description";
      field.isEditable = true;
      field.style.width = 0;
      field.search.mode = CustomField.Search.SEARCH_MODES.LOCALIZED_STRING;
      dscr.addField(field);
      
      
      
      
      
      CustomImageField fieldImage = new CustomImageField();
      fieldImage.visible = true;
      fieldImage.name = "Изображение";
      fieldImage.db = "image";
      fieldImage.isEditable = true;
      fieldImage.style.width = 40;
      fieldImage.style.height = 40;
      fieldImage.isImageInTable = true;
      dscr.addField(fieldImage);
      
      

      
      
      field = new CustomField();
      field.visible = true;
      field.name = "Цена";
      field.db = "price";
      field.isEditable = true;
      field.isMust = true;
      field.style.width = 70;
      field.search.mode = CustomField.Search.SEARCH_MODES.INTEGER;
      field.search.row = 1;
      dscr.addField(field);
      
      

      
      field = new CustomField();
      field.visible = true;
      field.name = "Кол-во/Объем";
      field.db = "weight2";
      field.isEditable = true;
      field.isMust = true;
      field.style.width = 70;
      field.search.mode = CustomField.Search.SEARCH_MODES.NONE;
      field.search.row = 1;
      dscr.addField(field);
      


      field = new CustomField();
      field.visible = true;
      field.name = "Доставка";
      field.db = "delivery";
      field.isEditable = true;
      field.style.width = 60;
      field.isSortable = true;
      field.search.mode = CustomField.Search.SEARCH_MODES.BOOLEAN_ONLY_TRUE; 
      dscr.addField(field);
      
      
      
      
      if(application.isAdmin){
         ccf = new CustomDatabaseComboField();
         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);
      }
      
      
      
      
      
      
      
      CustomDateField 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 = 40;
      field.isSortable = true;
      field.search.mode = CustomField.Search.SEARCH_MODES.BOOLEAN_ONLY_TRUE; 
      field.search.row = 2;
      dscr.addField(field);
      
      
      DBSingle<MCourse> panel = new DBSingle<MCourse>(application,
                                                      MCourse.class,
                                                      ID,
                                                      dscr,
                                                      Dimension.getFull(application),
                                                      setMode
                                                     );

      
      return panel;
   }


}

