1. Chris Perkins
  2. c5t

Source

c5t / c5t / core / templates / page / edit.mak

<%inherit file="local:templates.master"/>
<%namespace file="local:templates.util.editor" import="head"/>
<%! from c5t.core.lib.helpers import make_template_list, get_pages_id_name, get_all_tags %>
<script type="text/javascript">
function validateSlug(){
  $('#page_parent_id\\:error').html('');
  page_id = $('#page_id').val();
  page_slug = $('#current_page_slug').val();
  parent_page_id  = $('#page_parent option:selected').val();

  var response = $.ajax({
   type: "POST",
   dataType: 'text',
   url: "validate_slug",
   async: false,
   data: {page_slug:page_slug, parent_page_id:parent_page_id, page_id:page_id}, 
  }).responseText;

   if(response == ''){
     return true;
   }
   else{   
     $('#page_parent_id\\:error').html(response);
     return false;
   }
}
</script>

<%def name="title()">Editing: ${page.title}</%def>

${tmpl_context.form.display(value=page) | n}

%if type(page).__name__ == 'Page':
  <h3>Page parent</h3>																				     
  <input type="hidden" id="current_page_slug" value="${page.slug}"/>									     
  <form action="./pageparent" method="POST" id="pageparent" onsubmit="return validateSlug();">		     
  	<input type="hidden" name="page_id" id="page_id" value="${page._id}"/>							     
  	<%																								     
  	(page_ids,page_names) = get_pages_id_name(page._id)												     
  	page_count = len(page_ids)																		     
  	%>																								     
  	<select name="page_parent" id="page_parent">													     
  	<option value="top">Top Level</option>															     
  	%for i in range(0, page_count): 																     
      <option ${page_ids[i] == page.parent_id and 'selected=selected' or ''} value="${page_ids[i]}">${page_names[i]}</option>
  	%endfor																							     
  	</select> 																						     
  	<input type="submit" value="Update Parent Page"/>												     
  </form><span id="page_parent_id:error"></span>														     
%endif

<h3>Status</h3>
<form action="./publish" method="POST" id="status">
    <input type="hidden" name="page_id" value="${page._id}"/>
    <select name="status">
    %for status in ('draft', 'reviewed', 'published', 'removed', 'public'):
        <option ${page.status == status and 'selected="selected"' or '' | n} value="${status}">${status}</option>
    %endfor
    </select>
    <input type="submit" value="Set Status"/>
</form>

<h2>Files</h2>
%for file_ in page.files:
<form method="POST" action="${file_.private_path()}" id="files">
  <span style="font-size:1.1em;cursor:pointer;" onclick="edit_file('${file_._id}','')">[edit]</span>
<!--  <span id="f${file_._id}pp">${'Display' if file_.public else 'Hide'}</span> -->
    <a id="f${file_._id}a" href="${file_.fileurl or file_.private_path()}" title="${file_.description}">${file_.text or file_.title}</a>
      (Tags:
      %if file_.tags:
         <span id="f${file_._id}t">${",".join(file_.tags)}</span>
      %else:
         <span id="f${file_._id}t"></span>
      %endif

    )
    <input type="hidden" name="_method" value="DELETE" />
    <input class="delete" value="delete" type="submit"
        onclick="return confirm('Are you sure you want to delete this file?');" />
</form>
<input type="hidden" id="f${file_._id}name" value="${file_.title}"/>
<div id="f${file_._id}" style="display:none;">
<table><tr>
<td>Tags</td><td><ul id="f${file_._id}_th" class="tagHandler"></ul></td>
</tr><tr>
<td>Title</td><td><input type="text" id="f${file_._id}_title" value="${file_.text or file_.title}" /></td>
</tr><tr>
<td>Description</td>
<td><input type="text" id="f${file_._id}_desc" value="${file_.description}" /></td>
</tr><tr>
  %if file_.fileurl:
<td>File url</td><td><input type="text" id="f${file_._id}_url" value="${file_.fileurl}" /></td>
  %else:
<td>File</td><td>${file_.title}</td>  
  %endif
<!-- </tr><tr>  
<td>Public</td><td><input type="checkbox" ${'checked="checked"' if file_.public else ''} id="f${file_._id}_pub" name="public"></td> -->
</tr></table>
   <button onclick="save_file_update('${file_._id}')">Save</button>
</div>
%endfor
<br/>

<h3>Add File</h3>
<form action="./files" method="POST" enctype="multipart/form-data" id="upload">
  <table>
    <tr>
      <td><label for="label">Title</label></td>
      <td><input type="text" name="label"/></td>
    </tr>
    <tr>
      <td><label for="description">Description</label></td>
      <td><input type="text" name="description"/></td>
    </tr>
    <tr>
    <tr id="add_url">
      <td><label for="fileurl">File url</label></td>
      <td><input type="text" id="fileurl" name="fileurl"/><a onclick="change_file();"> Upload file</a> <span class="error_msg" id="fileurl_error"></span></td>
    </tr>
    <tr id="add_file">
      <td><label for="data">File</label></td>
      <td><input type="file" id="data" name="data"/><a onclick="change_file();"> Add url</a> <span  class="error_msg" id="data_error"></span></td></td>
    </tr>
        <tr>
      <td><label for="filetags">Tags</label></td>
      <td><input type="hidden" id="filetags" name="filetags"/><ul id="file_tag_handler" class="tagHandler"></ul></td>
    </tr>
 <!-- <tr>
      <td><label for="public">Public</label></td>
      <td><input type="checkbox" name="public"/></td>
    </tr>   not being used -->
    <tr>
      <td>&nbsp;</td>
      <td><input type="submit" value="Add"/></td>
    </tr>
  </table>
</form>


<h3>Delete Page</h3>
<form method="POST" action="edit_post_delete" class="button-to" id="main">
<input type="hidden" name="_method" value="DELETE" />
<input type="hidden" name="page_id" value="${page._id}" />
<input type="hidden" name="page_type" value="${type(page).__name__}" />
<input onclick="return confirm('Are you sure you want to delete ${page.title}?');" value="Delete" type="submit" />
</form>
<% all_tags = get_all_tags() %>
<script type="text/javascript" src="/javascript/jquery/jquery.taghandler.min.js"></script>
<script type="text/javascript">
  $("#tags").hide();
  $("#tags").parent().html('<ul id="tag_handler" class="tagHandler"></ul>'+$("#tags").parent().html());
  current_tags_ar = $("#tags").val().split(', ');
  if(current_tags_ar == '' || current_tags_ar == '[]'){
    $("#tag_handler").tagHandler({
       availableTags: ${all_tags|n},
       autocomplete: true
    });
   }else{
    $("#tag_handler").tagHandler({
       assignedTags: current_tags_ar,
       availableTags: ${all_tags|n},
       autocomplete: true
    });
   }
  
  $("#main").submit(function () {
    var tagNames = new Array();
    $("#tag_handler li.tagItem").each(function () {
        tagNames.push($(this).html().trim());
    });
    $("#tags").val(tagNames);
  });
/* Add File tag handler */  
  $("#file_tag_handler").tagHandler({
    availableTags: ${all_tags|n},
    autocomplete: true
  });
  
  $("#upload").submit(function () {
    if($('#fileurl').is(":visible")==true){
      file_url = $('#fileurl').val();  
      if(!(file_url.indexOf('/') == 0 || file_url.indexOf('http://') == 0)){
         $('#fileurl_error').text('A url must either begin with a / (for files on this server) or http:// (for files not on this server).');
         return false;
      }
    }else{
      if($('#data').val()==''){
        $('#data_error').text('Select a file to upload.');
        return false;
      }
    }
    var tagNames = new Array();
    $("#file_tag_handler li.tagItem").each(function () {
        tagNames.push($(this).html().trim());
    });
    $("#filetags").val(tagNames);
  });  
/* End of Add File tag handler */  
/* Edit attached file */
function edit_file(filediv){
  $('#f'+filediv).toggle();
  $('#f'+filediv+'tags').val($('#f'+filediv+'t').text());
  current_tags_ar= '';
  if($('#f'+filediv+'t').text()!=''){current_tags_ar = $('#f'+filediv+'t').text().split(',');}
  
    $("#f"+filediv+"_th").tagHandler({
    assignedTags: current_tags_ar,
    availableTags: ${all_tags|n},
    autocomplete: true
  });
}
function save_file_update(filediv){
    input_check = true;
    file_url = '';
    if($('#f'+filediv+'_url').is(":visible")==true){
       file_url = $('#f'+filediv+'_url').val();
       if(file_url.indexOf('/') != 0 && file_url.indexOf('http://') != 0){
          input_check = false;
          alert('A url must either begin with a / (for files on this server) or http:// (for files not on this server).');
       }
    }
    if(input_check){
       var tagNames_ar = new Array();
       $("#f"+filediv+"_th li.tagItem").each(function () {
           tagNames_ar.push($(this).html().trim());
       });
       tagNames =tagNames_ar.toString(',')
       file_title = $('#f'+filediv+'_title').val();
       file_desc = $('#f'+filediv+'_desc').val();
   /*  file_public = $('#f'+filediv+'_pub').is(':checked'); */
      var ainfo = $.ajax({
       type: "POST",
       url: "update_file",
       data: {file_id : filediv, file_tags: tagNames, ftitle: file_title, fdesc:file_desc, furl:file_url
             /*  ,fpub:file_public */
             },
       success: function(data) {
         if(file_title == ''){
             file_title = $('#f'+filediv+'name').val();
         }
         $('#f'+filediv+'a').text(file_title);
         if(file_url.indexOf('/') == 0){
           full_file_url = 'http://'+document.domain+file_url
         }else{
           full_file_url = file_url
         }
       /* if(file_public){
            $('#f'+filediv+'pp').text('Display');
         }else{
           $('#f'+filediv+'pp').text('Hide');
         } // update display/hide on save */
         $('#f'+filediv+'a').attr("href", full_file_url);
         $('#f'+filediv+'a').attr("title", file_desc);
         $('#f'+filediv).toggle();
      }
      });
      $('#f'+filediv+'t').text(tagNames);
   }
}

$('#add_url').toggle();

function change_file(){
  $('#add_file').toggle();
  $('#add_url').toggle();
  $('#data').val('');
  $('#fileurl_error').text('');
  $('#fileurl').val('');
  $('#data_error').text('');
}
/* End of Edit attached file */
/* Start auto slug*/
$('#title').blur(function () {
  if($('#slug').val()==''){  // auto slug only when slug field is empty
    var auto_slug = $('#title').val().trim();
    auto_slug = auto_slug.replace(/[^a-zA-Z0-9-\s]/g,"").toLowerCase();
    auto_slug = auto_slug.replace(/\s/g,'-');
    while (auto_slug.indexOf( "--" ) != -1){
      auto_slug = auto_slug.replace( "--", "-" )
    }
    $('#slug').val(auto_slug);
  }
});
/* End of auto slug*/
</script>