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

public class TabNews extends AbstractTab{
   private static final long serialVersionUID = -6879996703990744601L;






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

   @Override
   public DBListPanel<MNews> 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);




      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);




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




      CustomImageField fieldLogo = new CustomImageField();
      fieldLogo.visible = true;
      fieldLogo.name = "Изображение";
      fieldLogo.db = "image";
      fieldLogo.isEditable = true;
      fieldLogo.style.width = 40;
      fieldLogo.style.height = 40;
      fieldLogo.isImageInTable = true;
      dscr.addField(fieldLogo);



      CustomFixedComboField ccf = new CustomFixedComboField();
      ccf.visible = true;
      ccf.name = "Объект";
      ccf.db = "CID";
      ccf.isEditable = true;
      ccf.style.width = 100;
      ccf.isMust = true;
      ccf.search.row = 1;
      dscr.addField(ccf);


      
      field = new CustomField();
      field.visible = true;
      field.name = "На главной";
      field.db = "showMainScreen";
      field.isEditable = true;
      field.style.width = 100;
      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 = "showNews";
      field.isEditable = true;
      field.style.width = 100;
      field.isSortable = true;
      field.search.mode = CustomField.Search.SEARCH_MODES.BOOLEAN_ONLY_TRUE;
      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);
      }





      CustomDateField dateField = new CustomDateField();
      dateField.visible = true;
      dateField.name = "Известить";
      dateField.db = "date_notification";
      dateField.isEditable = true;
      dateField.style.width = 120;
      dateField.isSortable = true;
      dateField.search.mode = CustomField.Search.SEARCH_MODES.DATE_RANGE;
      dateField.search.row = 1;
      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 = 1;
      dscr.addField(field);


      Constraint constraint = new Constraint();

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



      DBListPanel<MNews> panel = new DBListPanel<MNews>(application,
                                          MNews.class,
                                          dscr,
                                          Dimension.getFull(application),
                                          setMode,
                                          constraint);
      panel.addPanel(new ExtraPanelImageUploader(panel, fieldLogo), false);


      return panel;
   }


   
   


   @Override
   public DBSingle build(int ID){
      // TODO Auto-generated method stub
      return null;
   }
}

