芝麻web文件管理V1.00
编辑当前文件:/home/pulsehostuk9/www/wp-content/plugins/leco-client-portal/src/admin.js
import './cmb2/types/multiple-urls'; import './cmb2/types/due-date'; jQuery( document ).ready( function ( $ ) { if ( $( '#leco_cp_client' ).length > 0 ) { $( 'select#leco_cp_client' ).select2(); } $( document ).on( 'click', '.leco_cp_save, #leco_cp_save', function ( e ) { $( '#publish' ).click(); e.preventDefault(); } ); $( '#leco_cp_template' ).on( 'change', function () { $( this ).next( '.button' ).remove(); $( this ).next( '.button-primary' ).remove(); if ( '0' !== $( this ).val() ) { var data = { action: 'leco_cp_get_permalink', post_id: $( this ).val(), _wpnonce: lecoCPAdminVars._wpnonce, }, $this = $( this ); $.post( ajaxurl, data, function ( data ) { if ( -1 != data ) { $( '
Preview
' ).insertAfter( $this ); } } ); $( '
' ).insertAfter( $( this ) ); $( '#leco_cp_custom_branding, #leco_cp_info' ).hide(); } else { $( '#leco_cp_custom_branding, #leco_cp_info' ).show(); } } ); function pjsHideThree( psjv ) { if ( psjv === 'hide' ) { $( '.cmb2-id-leco-cp-current-phase, .cmb2-id-leco-cp-next-phase, .cmb2-id-leco-cp-completion-date' ).hide(); } else { $( '.cmb2-id-leco-cp-current-phase, .cmb2-id-leco-cp-next-phase, .cmb2-id-leco-cp-completion-date' ).show(); } } if ( $( '#leco_cp_show_project_status' ).length > 0 ) { var pjs = $( '#leco_cp_show_project_status' ), psjv = pjs.val(); pjsHideThree( psjv ); pjs.on( 'change', function () { var show = $( this ).val(); pjsHideThree( show ); } ); } function switchModule( field, moduleType ) { if ( field.hasClass( 'module-type-group' ) ) { field.children( '.module-type' ).hide(); field.children( '.module-type-' + moduleType ).show(); } else { field.find( '.module-type' ).hide(); field.find( '.module-type-' + moduleType ).show(); } } $( '.module-type-select' ).each( function () { var moduleType = $( this ).find( 'select' ).val(), field = $( this ).parent( '.module-type-group' ); setModuleType( moduleType, field ); } ); function setModuleType( moduleType, field ) { var contentPage = field .children( '.module-type-content-page' ) .find( '.cmb2_select' ); switch ( moduleType ) { case 'content_page': field.children( '.module-type-files' ).hide(); field.children( '.module-type-private-files' ).hide(); field.children( '.module-type-url' ).hide(); field.children( '.module-type-multiple-urls' ).hide(); field.children( '.module-type-client-uploads' ).hide(); var addNew = contentPage.next( '.add-new-content-page' ), post_id = contentPage.val(), isDisabled = false, data = {}, selectElem = field.children( '.module-type-content-page' ); if ( lecoCPAdminVars.supportComments === '1' ) { disableContentPagesHaveComments( contentPage, selectElem ); } if ( post_id !== '0' ) { data = { action: 'leco_cp_get_permalink', post_id: post_id, permalink: lecoCPAdminVars.permalink, _wpnonce: lecoCPAdminVars._wpnonce, }; $.post( ajaxurl, data, function ( data ) { if ( -1 != data ) { contentPage .nextAll( '.preview-content-page' ) .remove(); contentPage .nextAll( '.edit-content-page' ) .remove(); $( '
Preview
' ) .insertAfter( contentPage.next( '.add-new-content-page' ) ) .after( '
Edit
' ); } } ); } if ( ! isDisabled ) { if ( ! addNew.length ) { var display = post_id !== '0' ? 'display:none' : ''; contentPage.after( '
Add Now
' ); } } break; default: contentPageOptionRestore( contentPage ); switchModule( field, moduleType ); } } function disableContentPagesHaveComments( contentPage, selectElem ) { contentPage.children( 'option' ).each( function () { var $this = $( this ); if ( $this.attr( 'selected' ) !== 'selected' ) { var data = { action: 'leco_cp_content_page_has_comment', post_id: $this.attr( 'value' ), _wpnonce: lecoCPAdminVars._wpnonce, }; $.post( ajaxurl, data, function ( data ) { if ( parseInt( data ) > 0 && data !== $( '#post_ID' ).val() ) { $this.attr( 'disabled', 'disabled' ); } selectElem.show(); // Add button to create new content page. if ( ! selectElem.find( '.add-new-content-page' ).length ) { contentPage.after( '
Add Now
' ); } } ); } } ); } function getModuleTitle( elem ) { var title = $( elem ) .next( '.cmb-field-list' ) .children( ':first-child' ) .find( 'input.regular-text' ) .val(), currentTitle = $( elem ).html(); if ( $( elem ).children().length > 1 ) { var originalTitle = $( elem ).children( ':first-child' )[ 0 ].outerHTML; $( elem ).html( originalTitle + '
- ' + title + '
' ); } else { $( elem ).html( currentTitle + '
- ' + title + '
' ); } } $( '.cmb-group-title' ).each( function ( i, elem ) { if ( i > 0 ) { getModuleTitle( elem ); } } ); function formatState( state ) { if ( ! state.id ) { return state.text; } var $state = $( '
' + state.text + '
' ); return $state; } function format( state ) { if ( ! state.id ) { return state.text; } var $state = $( '
' + state.text + '
' ); return $state; } function contentPageOptionRestore( contentPage ) { contentPage.val( '0' ); contentPage.nextAll( '.preview-content-page' ).remove(); contentPage.nextAll( '.edit-content-page' ).remove(); } var lecoCPSelect2Option = { templateResult: format, templateSelection: format, width: '40%', }; $( '.select2-icon' ).select2( lecoCPSelect2Option ); $( document ) // Apply select2 on cloned rows .on( 'cmb2_add_row', function ( evt, row ) { row.find( 'span.select2' ).remove(); row.find( 'select.select2-icon' ) .removeClass( 'select2-hidden-accessible' ) .select2( lecoCPSelect2Option ); switchModule( row, 'url' ); } ) .on( 'cmb_init', function () { $( '.cmb-remove-row-button, .cmb-remove-group-row' ).on( 'click', function ( e ) { var msg = ''; if ( 'leco_cp_phases_repeat' === $( this ).data( 'selector' ) ) { msg = 'Remove this phase will DELETE all its modules.\r\nAre you sure?'; } else { msg = 'Are you sure to remove this module?'; } var r = confirm( msg ); if ( ! r ) { e.stopImmediatePropagation(); } } ); } ) .on( 'cmb2_remove_row', '.cmb-repeatable-group', function () { this.children.forEach( function ( child ) { var groupTitle = child.querySelector( '.cmb-group-title' ); if ( groupTitle !== null ) { getModuleTitle( groupTitle ); } } ); } ) .on( 'cmb_media_modal_init', function ( evt, media ) { if ( media.field.indexOf( 'private_files' ) !== -1 ) { var cmb = window.CMB2, handlers = window.CMB2.mediaHandlers, isList = media.isList, id = media.fieldData.mediaid; // borrowed from Download Monitor media.frames[ id ].on( 'ready', function () { media.frames[ id ].uploader.options.uploader.params.type = 'leco_private_file'; } ); media.frames[ id ].on( 'select', function () { var selection = media.frames[ id ] .state() .get( 'selection' ); var type = isList ? 'list' : 'single'; // replace selection urls. for ( var i = 0; i < selection.models.length; i++ ) { selection.models[ i ].attributes.url = lecoCPAdminVars.permalink + 'file/' + btoa( $( '#post_ID' ).val() + '|' + selection.models[ i ].id ) + '/' + selection.models[ i ].attributes.filename; } if ( cmb.attach_id && isList ) { $( '[data-ifd="' + cmb.attach_id + '"]' ) .parents( 'li' ) .replaceWith( handlers.list( selection, true ) ); } else { handlers[ type ]( selection ); } cmb.trigger( 'cmb_media_modal_select', selection, media ); } ); } } ) .on( 'cmb_media_modal_open', function ( evt, selection, media ) { if ( media.field.indexOf( 'private_files' ) !== -1 ) { var handlers = window.CMB2.mediaHandlers, id = media.fieldData.mediaid; media.frames[ id ].off( 'select', handlers.selectFile ); } } ) .on( 'click', '.cmb-shift-rows', function ( evt ) { var $this = $( this ); var $from = $this.parents( '.cmb-repeatable-grouping' ); var $goto = $this.hasClass( 'move-up' ) ? $from.prev( '.cmb-repeatable-grouping' ) : $from.next( '.cmb-repeatable-grouping' ); getModuleTitle( $from.find( '.cmb-group-title' ) ); getModuleTitle( $goto.find( '.cmb-group-title' ) ); $( '.select2-icon' ).select2( lecoCPSelect2Option ); var gotoModuleType = $goto .find( '.module-type-select' ) .find( 'select' ) .val(), gotoField = $goto .find( '.module-type-select' ) .parent( '.module-type-group' ); var fromModuleType = $from .find( '.module-type-select' ) .find( 'select' ) .val(), fromField = $from .find( '.module-type-select' ) .parent( '.module-type-group' ); setModuleType( gotoModuleType, gotoField ); setModuleType( fromModuleType, fromField ); } ) .on( 'change', '.module-type-select select', function () { var moduleType = $( this ).val(), field = $( this ).parents( '.module-type-group' ), contentPage = field .children( '.module-type-content-page' ) .find( '.cmb2_select' ); switch ( moduleType ) { case 'content_page': field.children( '.module-type-url' ).hide(); field.children( '.module-type-multiple-urls' ).hide(); field.children( '.module-type-files' ).hide(); field.children( '.module-type-private-files' ).hide(); field.children( '.module-type-client-uploads' ).hide(); var selectElem = field.children( '.module-type-content-page' ); if ( lecoCPAdminVars.supportComments === '1' ) { disableContentPagesHaveComments( contentPage, selectElem ); } else { selectElem.show(); if ( ! selectElem.find( '.add-new-content-page' ).length ) { contentPage.after( '
Add Now
' ); } else { selectElem.find( '.add-new-content-page' ).show(); selectElem.find( '.preview-content-page' ).remove(); selectElem.find( '.edit-content-page' ).remove(); } } break; default: contentPageOptionRestore( contentPage ); switchModule( field, moduleType ); } } ) .on( 'change', '.module-type-content-page select', function () { if ( '0' !== $( this ).val() ) { var addNew = $( this ).next( '.add-new-content-page' ), data = { action: 'leco_cp_get_permalink', post_id: $( this ).val(), permalink: lecoCPAdminVars.permalink, _wpnonce: lecoCPAdminVars._wpnonce, }, $this = $( this ); addNew.hide(); $.post( ajaxurl, data, function ( data ) { if ( -1 != data ) { $this.nextAll( '.preview-content-page' ).remove(); $this.nextAll( '.edit-content-page' ).remove(); $( '
Preview
' ) .insertAfter( addNew ) .after( '
Edit
' ); } } ); } else { $( this ).next( '.add-new-content-page' ).show(); $( this ).nextAll( '.preview-content-page' ).remove(); $( this ).nextAll( '.edit-content-page' ).remove(); } } ) .on( 'click', '.module-type-content-page .add-new-content-page', function ( e ) { e.preventDefault(); $( this ).html( 'Adding...' ); var permalink = lecoCPAdminVars.permalink, fieldList = $( this ).closest( '.cmb-field-list' ), title = fieldList .find( '.module-title' ) .find( 'input' ) .val(), content = fieldList .find( '.module-desc' ) .find( 'textarea' ) .val(), data = { action: 'leco_cp_add_content_page', title: title, content: content, post_id: $( '#post_ID' ).val(), _wpnonce: lecoCPAdminVars._wpnonce, }, $this = $( this ); $.post( ajaxurl, data, function ( data ) { if ( -1 != data ) { data = JSON.parse( data ); // Update select option $this .prev( 'select' ) .children( 'option' ) .removeAttr( 'selected' ); // Append new option to ALL content page fields $( '.module-type-content-page select' ).append( '
' + title + '
' ); $this .prev( 'select' ) .children( 'option' ) .last() .attr( 'selected', 'selected' ); $this.after( '
You just create a new content page - ' + title + '!
' ); $( '.just-created-content-page' ).fadeOut( 1000, 'linear' ); $this.html( 'Add New' ); $this.hide(); $( '
Preview
' ) .insertAfter( $this ) .after( '
Edit
' ); } } ); } ) .on( 'click', '.leco-cp-notice.is-dismissible .notice-dismiss', function () { var notice_el = $( this ).closest( '.leco-cp-notice' ); var notice = notice_el.attr( 'id' ); var notice_nonce = notice_el.attr( 'data-nonce' ); $.post( ajaxurl, { action: 'leco_cp_dismiss_notice', nonce: notice_nonce, notice: notice, } ); } ) .on( 'change', '.leco-cp-module-status select', function () { if ( $( '#leco_cp_public_portal' ).val() === 'no' && lecoCPAdminVars.clients !== '' ) { if ( -1 !== lecoCPAdminVars.notifications.indexOf( 'moduleActivated' ) && $( this ).val() === 'active' ) { var cf = confirm( 'Would you like to notify your client(s) that this module has been activated?' ); if ( cf ) { // The ID is like this: "leco_cp_part_2_module_3_status" var module = $( this ).attr( 'id' ).split( '_' ), phase = module[ 3 ], key = module[ 5 ], data = { action: 'leco_cp_mark_as_active', post_id: $( '#post_ID' ).val(), phase: phase, key: key, _wpnonce: lecoCPAdminVars._wpnonce, }; $.post( ajaxurl, data, function ( data ) { if ( ! Number.isInteger( parseInt( data ) ) ) { console.log( 'Module activated notifications error: ' + data ); } } ); } } else if ( -1 !== lecoCPAdminVars.notifications.indexOf( 'moduleCompleted' ) && $( this ).val() === 'completed' ) { var cf = confirm( 'Would you like to notify your client(s) that this module has been completed?' ); if ( cf ) { // The ID is like this: "leco_cp_part_2_module_3_status" var module = $( this ).attr( 'id' ).split( '_' ), phase = parseInt( module[ 3 ] ) + 1, // +1 to make it work with frontend scripts. key = parseInt( module[ 5 ] ) + 1, data = { action: 'leco_cp_mark_as_complete', post_id: $( '#post_ID' ).val(), phase: phase, key: key, _wpnonce: lecoCPAdminVars._wpnonce, }; $.post( ajaxurl, data, function ( data ) { if ( ! Number.isInteger( parseInt( data ) ) ) { console.log( 'Module completed notifications error: ' + data ); } } ); } } } } ); $( '#leco_cp_public_portal' ).on( 'change', function () { if ( 'yes' === $( this ).val() ) { var r = confirm( 'Are you sure you want to make this portal public?\r\n\r\nPublic means it’s visible to anybody with the URL. Please don’t share any passwords or private information in a public portal.' ); if ( r ) { $( this ).val( 'yes' ); } else { $( this ).val( 'no' ); } } } ); if ( typeof typenow !== 'undefined' && typenow === 'leco_content_page' && lecoCPAdminVars.supportComments === '1' ) { if ( $( '.leco-project-link.private' ).length > 0 && $( '.leco-project-link' ).length > 1 ) { $( '#comment_status' ).attr( 'disabled', 'disabled' ); } } } );