U
    {h                     @   sD   d dl mZ d dlmZ d dlmZ ddlmZ G dd deZdS )	    )format_lazy)gettext_lazy)Page   )
FieldPanelc                       sL   e Zd ZdZddddgd fdd
Z fd	d
ZG dd dejZ  ZS )TitleFieldPanela  
    Prepares the default widget attributes that are used on Page title fields.
    Can be used outside of pages to easily enable the slug field sync functionality.

    :param apply_if_live: (optional) If ``True``, the built in slug sync behaviour will apply irrespective of the published state.
        The default is ``False``, where the slug sync will only apply when the instance is not live (or does not have a live property).
    :param classname: (optional) A CSS class name to add to the panel's HTML element. Default is ``"title"``.
    :param placeholder: (optional) If a value is provided, it will be used as the field's placeholder, if ``False`` is provided no placeholder will be shown.
        If ``True``, a placeholder value of ``"Title*"`` will be used or ``"Page Title*"`` if the model is a ``Page`` model.
        The default is ``True``. If a widget is provided with a placeholder, the widget's value will be used instead.
    :param targets: (optional) This allows you to override the default target of the field named `slug` on the form.
        Accepts a list of field names, default is ``["slug"]``.
        Note that the slugify/urlify behaviour relies on usage of the ``wagtail.admin.widgets.slug`` widget on the slug field.
    FtitleTZslug)apply_if_live	classnameplaceholdertargetsc                   s,   ||d< || _ || _|| _t j|| d S )Nr
   )r	   r   r   super__init__)selfr	   r
   r   r   argskwargs	__class__ n/var/www/dating/data/www/fatepal.com/env/lib/python3.8/site-packages/wagtail/admin/panels/title_field_panel.pyr      s
    	zTitleFieldPanel.__init__c                    s   t   | j| j| jdS )N)r	   r   r   )r   clone_kwargsr	   r   r   r   r   r   r   r   (   s
    zTitleFieldPanel.clone_kwargsc                       sJ   e Zd ZddddgZd fdd	Zdd	 Zd
d Zdd Zdd Z  Z	S )zTitleFieldPanel.BoundPanelzfocus->w-sync#checkzblur->w-sync#applyzchange->w-sync#applyzkeyup->w-sync#applyNc                    s2   | j j}|r&| js&|jjjf |   t |S )N)	bound_fieldfieldZ	read_onlywidgetattrsupdate	get_attrsr   get_context_data)r   Zparent_contextr   r   r   r   r   8   s    
z+TitleFieldPanel.BoundPanel.get_context_datac                    s    j } jjj}i }|jdddg}dtd||d<   rl|jddg j	 }dtd||d<  fdd|j
D }dtd||d	<   }|rd
|jkr||d
< |S )zy
            Generates a dict of widget attributes to be updated on the widget
            before rendering.
            zdata-controllerNzw-sync zdata-actionc                    s"   g | ]}| j jkr |qS r   )formfieldsget_target_selector).0targetr   r   r   
<listcomp>P   s   z8TitleFieldPanel.BoundPanel.get_attrs.<locals>.<listcomp>z, zdata-w-sync-target-valuer   )panelr   r   r   r   getjoinfilterget_should_applyapply_actionsr   get_placeholder)r   r&   r   r   Zcontrollersactionsr   r   r   r   r   r   >   s     

z$TitleFieldPanel.BoundPanel.get_attrsc                 C   sF   | j j}|sdS |dkrBtd}t| j jtr6td}td|dS |S )z
            If placeholder is falsey, return None. Otherwise allow a valid placeholder
            to be resolved.
            NTZTitlez
Page titlez{title}*)r   )r&   r   r   
issubclassmodelr   r   )r   r   r   r   r   r   r,   ]   s    z*TitleFieldPanel.BoundPanel.get_placeholderc                 C   s2   | j jrdS | j}|sdS |jo*t|dd}| S )zb
            Check that the title field should apply the sync with the target fields.
            TliveF)r&   r	   instancepkgetattr)r   r1   Zis_liver   r   r   r*   q   s    z+TitleFieldPanel.BoundPanel.get_should_applyc                 C   s   | j | }d|j S )zL
            Prepare a selector for an individual target field.
            #)r    Zid_for_label)r   r$   r   r   r   r   r"      s    
z.TitleFieldPanel.BoundPanel.get_target_selector)N)
__name__
__module____qualname__r+   r   r   r,   r*   r"   __classcell__r   r   r   r   
BoundPanel0   s   r9   )	r5   r6   r7   __doc__r   r   r   r9   r8   r   r   r   r   r   	   s   r   N)	Zdjango.utils.textr   Zdjango.utils.translationr   Zwagtail.modelsr   Zfield_panelr   r   r   r   r   r   <module>   s   