private function form_template($list, $action, $button_text = NULL) { $form_args = array('context' => 'podlove_list', 'hidden' => array('list' => $list->id, 'action' => $action)); \Podlove\Form\build_for($list, $form_args, function ($form) { $wrapper = new \Podlove\Form\Input\TableWrapper($form); $list = $form->object; $wrapper->string('slug', array('label' => __('ID', 'podlove'), 'html' => array('class' => 'regular-text required'), 'description' => sprintf(__('For referencing in templates: %s', 'podlove'), '<code>{{ network.lists({id: "example"}).title }}</code>'))); $wrapper->string('title', array('label' => __('Title', 'podlove'), 'html' => array('class' => 'regular-text required'))); $wrapper->string('subtitle', array('label' => __('Subtitle', 'podlove'), 'html' => array('class' => 'regular-text'))); $wrapper->text('description', array('label' => __('Summary', 'podlove'), 'description' => __('', 'podlove'), 'html' => array('rows' => 3, 'cols' => 40, 'class' => 'autogrow'))); $wrapper->image('logo', array('label' => __('Logo', 'podlove'), 'description' => __('JPEG or PNG.', 'podlove'), 'html' => array('class' => 'regular-text'), 'image_width' => 300, 'image_height' => 300)); $wrapper->string('url', array('label' => __('List URL', 'podlove'), 'description' => __('', 'podlove'), 'html' => array('class' => 'regular-text'))); $wrapper->callback('podcasts', array('label' => __('Podcasts', 'podlove'), 'callback' => function () use($list) { $form_base_name = "podlove_list"; ?> <div id="podcast_lists"> <table class="podlove_alternating" border="0" cellspacing="0"> <thead> <tr> <th><?php echo __('Source', 'podlove'); ?> </th> <th><?php echo __('Podcast/URL', 'podlove'); ?> </th> <th style="width: 60px"><?php echo __('Remove', 'podlove'); ?> </th> <th style="width: 30px"></th> </tr> </thead> <tbody class="podcasts_table_body" style="min-height: 50px;"> <tr class="podcasts_table_body_placeholder" style="display: none;"> <td><em><?php echo __('No Podcasts were added yet.', 'podlove'); ?> </em></td> </tr> </tbody> </table> <div id="add_new_podcasts_wrapper"> <input class="button" id="add_new_podcast" value="+" type="button" /> </div> <script type="text/template" id="podcast-row-template"> <tr class="media_file_row podlove-podcast-table" data-id="{{id}}"> <td class="podlove-podcast-column"> <select name="<?php echo $form_base_name; ?> [podcasts][{{id}}][type]" class="podlove-podcast-dropdown"> <option value="wplist" selected><?php echo __('WordPress Network', 'podlove'); ?> </option> </select> </td> <td class="podlove-podcast-value"></td> <td> <span class="podcast_remove"> <i class="clickable podlove-icon-remove"></i> </span> </td> <td class="move column-move"><i class="reorder-handle podlove-icon-reorder"></i></td> </tr> </script> <script type="text/template" id="podcast-select-type-wplist"> <select name="<?php echo $form_base_name; ?> [podcasts][{{id}}][podcast]" class="podlove-podcast chosen-image"> <option>— <?php echo __('Select Podcast', 'podlove'); ?> —</option> <?php foreach (Network::podcasts() as $blog_id => $podcast) { if ($podcast->title) { printf("<option value='%s' data-img-src='%s'>%s</option>\n", $blog_id, $podcast->cover_art()->setWidth(45)->url(), $podcast->title); } } ?> </select> </script> </div> <script type="text/javascript"> var PODLOVE = PODLOVE || {}; (function($) { var i = 0; var existing_podcasts = <?php echo is_null($list->podcasts) ? "[]" : $list->podcasts; ?> ; var podcasts = []; function update_chosen() { $(".chosen").chosen(); $(".chosen-image").chosenImage(); } function podcast_dropdown_handler() { $('select.podlove-podcast-dropdown').change(function() { row = $(this).closest("tr"); podcast_source = $(this).val(); // Check for empty podcast / for new field if (podcast_source === '') { row.find(".podlove-podcast-value").html(""); // Empty podcast column and hide edit button row.find(".podlove-podcast-edit").hide(); return; } if (!row.find(".podlove-podcast").length) { template_id = "#podcast-select-type-" + podcast_source; template = $( template_id ).html(); template = template.replace(/\{\{id\}\}/g, row.data('id') ); row.find(".podlove-podcast-value").html( template ); update_chosen(); i++; // continue using "i" which was already used to add the existing contributions } }); } $(document).ready(function() { $("#podcast_lists table").podloveDataTable({ rowTemplate: "#podcast-row-template", deleteHandle: ".podcast_remove", sortableHandle: ".reorder-handle", addRowHandle: "#add_new_podcast", data: existing_podcasts, dataPresets: podcasts, onRowLoad: function(o) { template_id = "#podcast-select-type-" + o.entry.type; template = $( template_id ).html(); row_as_object = $(o.row) row_as_object.find(".podlove-podcast-value").html( template ); row_as_object.find('select.podlove-podcast-dropdown option[value="' + o.entry.type + '"]').attr('selected', 'selected'); switch ( o.entry.type ) { default: case 'wplist': row_as_object.find('select.podlove-podcast option[value="' + o.entry.podcast + '"]').attr('selected', true); break; } o.row = row_as_object[0].outerHTML.replace(/\{\{id\}\}/g, i); i++; }, onRowAdd: function(o) { o.row = o.row.replace(/\{\{id\}\}/g, i); row = $(".podcasts_table_body tr:last .podlove-podcast-dropdown").focus(); podcast_dropdown_handler(); update_chosen(); row.change(); }, onRowDelete: function(tr) { } }); }); }(jQuery)); </script> <?php })); }); }