enhanced wiki editors with change detection and saving confirmation
This commit is contained in:
parent
a9571712a3
commit
9e0f3ff474
@ -288,180 +288,6 @@ class Wiki extends Controller
|
|||||||
return $this->_edit_wiki ($projectid, $name, 'update', $this->VIEW_EDITX);
|
return $this->_edit_wiki ($projectid, $name, 'update', $this->VIEW_EDITX);
|
||||||
}
|
}
|
||||||
|
|
||||||
function delete ($projectid = '', $name = '')
|
|
||||||
{
|
|
||||||
$this->load->helper ('form');
|
|
||||||
$this->load->library ('form_validation');
|
|
||||||
$this->load->model ('ProjectModel', 'projects');
|
|
||||||
$this->load->model ('WikiModel', 'wikis');
|
|
||||||
|
|
||||||
$login = $this->login->getUser ();
|
|
||||||
if ($login['id'] == '')
|
|
||||||
redirect ("main/signin/" . $this->converter->AsciiTohex(current_url()));
|
|
||||||
$data['login'] = $login;
|
|
||||||
|
|
||||||
$name = $this->converter->HexToAscii ($name);
|
|
||||||
|
|
||||||
$project = $this->projects->get ($projectid);
|
|
||||||
if ($project === FALSE)
|
|
||||||
{
|
|
||||||
$data['message'] = 'DATABASE ERROR';
|
|
||||||
$this->load->view ($this->VIEW_ERROR, $data);
|
|
||||||
}
|
|
||||||
else if ($project === NULL)
|
|
||||||
{
|
|
||||||
$data['message'] =
|
|
||||||
$this->lang->line('MSG_NO_SUCH_PROJECT') .
|
|
||||||
" - {$projectid}";
|
|
||||||
$this->load->view ($this->VIEW_ERROR, $data);
|
|
||||||
}
|
|
||||||
else if (!$login['sysadmin?'] &&
|
|
||||||
$this->projects->projectHasMember($project->id, $login['id']) === FALSE)
|
|
||||||
{
|
|
||||||
$data['project'] = $project;
|
|
||||||
$data['message'] = sprintf (
|
|
||||||
$this->lang->line('MSG_PROJECT_MEMBERSHIP_REQUIRED'), $projectid);
|
|
||||||
$this->load->view ($this->VIEW_ERROR, $data);
|
|
||||||
}
|
|
||||||
else if ($this->wikihelper->_is_reserved ($name, FALSE))
|
|
||||||
{
|
|
||||||
$data['project'] = $project;
|
|
||||||
$data['message'] = sprintf (
|
|
||||||
$this->lang->line('WIKI_MSG_RESERVED_WIKI_NAME'), $name);
|
|
||||||
$this->load->view ($this->VIEW_ERROR, $data);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ($project->public !== 'Y' && $login['id'] == '')
|
|
||||||
{
|
|
||||||
// non-public projects require sign-in.
|
|
||||||
redirect ("main/signin/" . $this->converter->AsciiTohex(current_url()));
|
|
||||||
}
|
|
||||||
|
|
||||||
$data['message'] = '';
|
|
||||||
$data['project'] = $project;
|
|
||||||
|
|
||||||
$this->form_validation->set_rules ('wiki_confirm', 'confirm', 'alpha');
|
|
||||||
$this->form_validation->set_error_delimiters('<span class="form_field_error">','</span>');
|
|
||||||
|
|
||||||
if($this->input->post('wiki'))
|
|
||||||
{
|
|
||||||
$wiki = new stdClass();
|
|
||||||
$wiki->projectid = $this->input->post('wiki_projectid');
|
|
||||||
$wiki->name = $this->input->post('wiki_name');
|
|
||||||
$data['wiki_confirm'] = $this->input->post('wiki_confirm');
|
|
||||||
|
|
||||||
if ($this->form_validation->run())
|
|
||||||
{
|
|
||||||
if ($data['wiki_confirm'] == 'yes')
|
|
||||||
{
|
|
||||||
$result = $this->wikis->delete ($login['id'], $wiki);
|
|
||||||
if ($result === FALSE)
|
|
||||||
{
|
|
||||||
$data['message'] = 'DATABASE ERROR';
|
|
||||||
$data['wiki'] = $wiki;
|
|
||||||
$this->load->view ($this->VIEW_DELETE, $data);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
redirect ("wiki/home/{$project->id}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
redirect ("wiki/show/{$project->id}/" .
|
|
||||||
$this->converter->AsciiToHex($wiki->name));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$data['message'] = $this->lang->line('MSG_FORM_INPUT_INCOMPLETE');
|
|
||||||
$data['wiki'] = $wiki;
|
|
||||||
$this->load->view ($this->VIEW_DELETE, $data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$wiki = $this->wikis->get ($login['id'], $project, $name);
|
|
||||||
if ($wiki === FALSE)
|
|
||||||
{
|
|
||||||
$data['message'] = 'DATABASE ERROR';
|
|
||||||
$this->load->view ($this->VIEW_ERROR, $data);
|
|
||||||
}
|
|
||||||
else if ($wiki === NULL)
|
|
||||||
{
|
|
||||||
$data['message'] = $this->lang->line('WIKI_MSG_NO_SUCH_PAGE') . " - {$name}";
|
|
||||||
$this->load->view ($this->VIEW_ERROR, $data);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$data['wiki_confirm'] = 'no';
|
|
||||||
$data['wiki'] = $wiki;
|
|
||||||
$this->load->view ($this->VIEW_DELETE, $data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function _upload_attachments ($id)
|
|
||||||
{
|
|
||||||
$attno = 0;
|
|
||||||
$count = count($_FILES);
|
|
||||||
|
|
||||||
$attachments = array ();
|
|
||||||
|
|
||||||
for ($i = 0; $i < $count; $i++)
|
|
||||||
{
|
|
||||||
$field_name = "{$id}_{$i}";
|
|
||||||
|
|
||||||
if (array_key_exists($field_name, $_FILES) &&
|
|
||||||
$_FILES[$field_name]['name'] != '')
|
|
||||||
{
|
|
||||||
$fname = $_FILES[$field_name]['name'];
|
|
||||||
if (strpbrk($fname, CODEPOT_DISALLOWED_LETTERS_IN_FILENAME) !== FALSE)
|
|
||||||
{
|
|
||||||
while ($attno > 0)
|
|
||||||
@unlink ($attachments[$attno--]['fullencpath']);
|
|
||||||
return array(FALSE,$this->lang->line('WIKI_MSG_ATTACHMENT_NAME_NO_COLON'));
|
|
||||||
}
|
|
||||||
|
|
||||||
$ext = substr ($fname, strrpos ($fname, '.') + 1);
|
|
||||||
|
|
||||||
// delete all \" instances ...
|
|
||||||
$_FILES[$field_name]['type'] =
|
|
||||||
str_replace('\"', '', $_FILES[$field_name]['type']);
|
|
||||||
// delete all \\ instances ...
|
|
||||||
$_FILES[$field_name]['type'] =
|
|
||||||
str_replace('\\', '', $_FILES[$field_name]['type']);
|
|
||||||
|
|
||||||
//$config['allowed_types'] = $ext;
|
|
||||||
$config['allowed_types'] = '*';
|
|
||||||
$config['upload_path'] = CODEPOT_ATTACHMENT_DIR;
|
|
||||||
$config['max_size'] = CODEPOT_MAX_UPLOAD_SIZE;
|
|
||||||
$config['encrypt_name'] = TRUE;
|
|
||||||
|
|
||||||
$this->upload->initialize ($config);
|
|
||||||
|
|
||||||
if (!$this->upload->do_upload ($field_name))
|
|
||||||
{
|
|
||||||
while ($attno > 0)
|
|
||||||
@unlink ($attachments[$attno--]['fullencpath']);
|
|
||||||
return array(FALSE,$this->upload->display_errors('',''));
|
|
||||||
}
|
|
||||||
|
|
||||||
$upload = $this->upload->data ();
|
|
||||||
|
|
||||||
$attachments[$attno++] = array (
|
|
||||||
'name' => $fname,
|
|
||||||
'encname' => $upload['file_name'],
|
|
||||||
'fullencpath' => $upload['full_path']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return array(TRUE,$attachments);
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////
|
||||||
// Handling of attached files share the (almost) same code
|
// Handling of attached files share the (almost) same code
|
||||||
// between issue.php and wiki.php. It would be way better
|
// between issue.php and wiki.php. It would be way better
|
||||||
|
@ -136,5 +136,5 @@ $lang['MSG_SIGNIN_FAILURE'] = 'Cannot sign in';
|
|||||||
|
|
||||||
$lang['MSG_PROJECT_MEMBERSHIP_REQUIRED'] = 'You have to be a member of the %s project to perform this task';
|
$lang['MSG_PROJECT_MEMBERSHIP_REQUIRED'] = 'You have to be a member of the %s project to perform this task';
|
||||||
$lang['MSG_FORM_INPUT_INCOMPLETE'] = 'Your input is incomplete';
|
$lang['MSG_FORM_INPUT_INCOMPLETE'] = 'Your input is incomplete';
|
||||||
$lang['MSG_DISCARD_CHANGES?'] = 'Do you want to discard chagnes?';
|
$lang['MSG_DISCARD_CHANGES?'] = 'Do you want to discard changes?';
|
||||||
?>
|
?>
|
||||||
|
@ -8,4 +8,7 @@ $lang['WIKI_MSG_NAME_DISALLOWED_CHARS'] = 'Wiki name contains disallowed charact
|
|||||||
$lang['WIKI_MSG_NO_PAGES_AVAILABLE'] = 'No wiki pages available';
|
$lang['WIKI_MSG_NO_PAGES_AVAILABLE'] = 'No wiki pages available';
|
||||||
$lang['WIKI_MSG_NO_SUCH_PAGE'] = 'No such wiki page';
|
$lang['WIKI_MSG_NO_SUCH_PAGE'] = 'No such wiki page';
|
||||||
$lang['WIKI_MSG_RESERVED_WIKI_NAME'] = 'Wiki name containing a reserved word - %s';
|
$lang['WIKI_MSG_RESERVED_WIKI_NAME'] = 'Wiki name containing a reserved word - %s';
|
||||||
|
|
||||||
|
$lang['WIKI_MSG_SAVE_DESPITE_NO_CHANGES?'] = "There seems to be no changes. Do you still want to save?";
|
||||||
|
$lang['WIKI_MSG_SAVE_IN_PROGRESS'] = 'Saving in progress, Please wait';
|
||||||
?>
|
?>
|
||||||
|
@ -133,6 +133,6 @@ $lang['MSG_SIGNIN_FAILURE'] = 'Cannot sign in';
|
|||||||
|
|
||||||
$lang['MSG_PROJECT_MEMBERSHIP_REQUIRED'] = 'You have to be a member of the %s project to perform this task';
|
$lang['MSG_PROJECT_MEMBERSHIP_REQUIRED'] = 'You have to be a member of the %s project to perform this task';
|
||||||
$lang['MSG_FORM_INPUT_INCOMPLETE'] = 'Your input is incomplete';
|
$lang['MSG_FORM_INPUT_INCOMPLETE'] = 'Your input is incomplete';
|
||||||
$lang['MSG_DISCARD_CHANGES?'] = 'Do you want to discard chagnes?';
|
$lang['MSG_DISCARD_CHANGES?'] = 'Do you want to discard changes?';
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
@ -8,4 +8,7 @@ $lang['WIKI_MSG_NAME_DISALLOWED_CHARS'] = '위키이름에 허용되지 않는
|
|||||||
$lang['WIKI_MSG_NO_PAGES_AVAILABLE'] = '사용할 수 있는 위키 페이지가 없습니다';
|
$lang['WIKI_MSG_NO_PAGES_AVAILABLE'] = '사용할 수 있는 위키 페이지가 없습니다';
|
||||||
$lang['WIKI_MSG_NO_SUCH_PAGE'] = '위키 페이지를 찾을수 없습니다';
|
$lang['WIKI_MSG_NO_SUCH_PAGE'] = '위키 페이지를 찾을수 없습니다';
|
||||||
$lang['WIKI_MSG_RESERVED_WIKI_NAME'] = '%s은(는) 사용할 수 없는 위키이름입니다';
|
$lang['WIKI_MSG_RESERVED_WIKI_NAME'] = '%s은(는) 사용할 수 없는 위키이름입니다';
|
||||||
|
|
||||||
|
$lang['WIKI_MSG_SAVE_DESPITE_NO_CHANGES?'] = '변경된 내용이 없는것 같습니다. 그래도 저장하겠습니까?';
|
||||||
|
$lang['WIKI_MSG_SAVE_IN_PROGRESS'] = '저장중이니 잠시 기다려 주세요';
|
||||||
?>
|
?>
|
||||||
|
@ -31,7 +31,6 @@ www_DATA = \
|
|||||||
taskbar.php \
|
taskbar.php \
|
||||||
user_home.php \
|
user_home.php \
|
||||||
user_settings.php \
|
user_settings.php \
|
||||||
wiki_delete.php \
|
|
||||||
wiki_edit.php \
|
wiki_edit.php \
|
||||||
wiki_editx.php \
|
wiki_editx.php \
|
||||||
wiki_home.php \
|
wiki_home.php \
|
||||||
|
@ -176,7 +176,6 @@ www_DATA = \
|
|||||||
taskbar.php \
|
taskbar.php \
|
||||||
user_home.php \
|
user_home.php \
|
||||||
user_settings.php \
|
user_settings.php \
|
||||||
wiki_delete.php \
|
|
||||||
wiki_edit.php \
|
wiki_edit.php \
|
||||||
wiki_editx.php \
|
wiki_editx.php \
|
||||||
wiki_home.php \
|
wiki_home.php \
|
||||||
|
@ -233,7 +233,6 @@ foreach ($urls as $url)
|
|||||||
|
|
||||||
if ($log['action'] != 'revpropchange')
|
if ($log['action'] != 'revpropchange')
|
||||||
{
|
{
|
||||||
|
|
||||||
print '<div class="codepot-plain-text-view">';
|
print '<div class="codepot-plain-text-view">';
|
||||||
print '<pre>';
|
print '<pre>';
|
||||||
$sm = strtok (trim ($x['message']), "\r\n");
|
$sm = strtok (trim ($x['message']), "\r\n");
|
||||||
|
@ -1,90 +0,0 @@
|
|||||||
<html>
|
|
||||||
|
|
||||||
<head>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
|
||||||
|
|
||||||
<script type="text/javascript" src="<?php print base_url_make('/js/codepot.js')?>"></script>
|
|
||||||
<link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/common.css')?>" />
|
|
||||||
<link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/wiki.css')?>" />
|
|
||||||
<link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/font-awesome.min.css')?>" />
|
|
||||||
|
|
||||||
|
|
||||||
<script type="text/javascript" src="<?php print base_url_make('/js/jquery.min.js')?>"></script>
|
|
||||||
<script type="text/javascript" src="<?php print base_url_make('/js/jquery-ui.min.js')?>"></script>
|
|
||||||
<link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/jquery-ui.css')?>" />
|
|
||||||
|
|
||||||
<title><?php print htmlspecialchars($wiki->name)?></title>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
|
|
||||||
<div class="content" id="wiki_delete_content">
|
|
||||||
|
|
||||||
<!---------------------------------------------------------------------------->
|
|
||||||
|
|
||||||
<?php $this->load->view ('taskbar'); ?>
|
|
||||||
|
|
||||||
<!---------------------------------------------------------------------------->
|
|
||||||
|
|
||||||
<?php
|
|
||||||
$this->load->view (
|
|
||||||
'projectbar',
|
|
||||||
array (
|
|
||||||
'banner' => NULL,
|
|
||||||
|
|
||||||
'page' => array (
|
|
||||||
'type' => 'project',
|
|
||||||
'id' => 'wiki',
|
|
||||||
'project' => $project,
|
|
||||||
),
|
|
||||||
|
|
||||||
'ctxmenuitems' => array ()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
?>
|
|
||||||
|
|
||||||
<!---------------------------------------------------------------------------->
|
|
||||||
|
|
||||||
<div class="mainarea">
|
|
||||||
|
|
||||||
<?php if ($message != "") print '<div id="wiki_delete_message" class="form_message">'.htmlspecialchars($message).'</div>'; ?>
|
|
||||||
|
|
||||||
<div class="form_container">
|
|
||||||
<?php print form_open("wiki/delete/{$project->id}/".$this->converter->AsciiToHex($wiki->name))?>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<div>
|
|
||||||
<?php print form_checkbox('wiki_confirm', 'yes', set_checkbox('wiki_confirm', $wiki_confirm))?>
|
|
||||||
<?php print $this->lang->line('MSG_SURE_TO_DELETE_THIS')?> - <?php print htmlspecialchars($wiki->name)?>
|
|
||||||
<?php print form_error('wiki_confirm')?>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<?php print form_hidden('wiki_projectid', set_value('wiki_projectid', $wiki->projectid))?>
|
|
||||||
<?php print form_hidden('wiki_name', set_value('wiki_name', $wiki->name))?>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<?php print form_submit('wiki', $this->lang->line('Delete'))?>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<?php print form_close();?>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div> <!-- mainarea -->
|
|
||||||
|
|
||||||
<div class='codepot-footer-pusher'></div> <!-- for sticky footer -->
|
|
||||||
|
|
||||||
</div> <!-- wiki_delete_content -->
|
|
||||||
|
|
||||||
<!---------------------------------------------------------------------------->
|
|
||||||
|
|
||||||
<?php $this->load->view ('footer'); ?>
|
|
||||||
|
|
||||||
<!---------------------------------------------------------------------------->
|
|
||||||
|
|
||||||
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
@ -1,4 +1,6 @@
|
|||||||
<html>
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||||
|
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
@ -46,6 +48,7 @@ function show_alert (outputMsg, titleMsg)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var previewing_text = false;
|
var previewing_text = false;
|
||||||
|
|
||||||
function resize_text_editor()
|
function resize_text_editor()
|
||||||
@ -127,6 +130,8 @@ function preview_text (input_text)
|
|||||||
|
|
||||||
var populated_file_obj_for_adding = [];
|
var populated_file_obj_for_adding = [];
|
||||||
var populated_file_max_for_adding = 0;
|
var populated_file_max_for_adding = 0;
|
||||||
|
var cancelled_file_count_for_adding = 0;
|
||||||
|
var killed_file_count = 0;
|
||||||
|
|
||||||
var original_file_name_array = [
|
var original_file_name_array = [
|
||||||
<?php
|
<?php
|
||||||
@ -168,10 +173,13 @@ function populate_selected_files_for_adding ()
|
|||||||
|
|
||||||
function cancel_out_add_file (no)
|
function cancel_out_add_file (no)
|
||||||
{
|
{
|
||||||
|
if (populated_file_obj_for_adding[no] != null)
|
||||||
|
{
|
||||||
|
cancelled_file_count_for_adding++;
|
||||||
$('#wiki_edit_add_file_row_' + no).remove ();
|
$('#wiki_edit_add_file_row_' + no).remove ();
|
||||||
populated_file_obj_for_adding[no] = null;
|
populated_file_obj_for_adding[no] = null;
|
||||||
|
|
||||||
resize_text_editor ();
|
resize_text_editor ();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function kill_file (no)
|
function kill_file (no)
|
||||||
@ -183,11 +191,13 @@ function kill_file (no)
|
|||||||
{
|
{
|
||||||
n.css ('text-decoration', '');
|
n.css ('text-decoration', '');
|
||||||
n.prop ('disabled', false);
|
n.prop ('disabled', false);
|
||||||
|
killed_file_count--;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
n.css ('text-decoration', 'line-through');
|
n.css ('text-decoration', 'line-through');
|
||||||
n.prop ('disabled', true);
|
n.prop ('disabled', true);
|
||||||
|
killed_file_count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,6 +217,7 @@ function update_original_file_name_array ()
|
|||||||
|
|
||||||
populated_file_obj_for_adding = [];
|
populated_file_obj_for_adding = [];
|
||||||
populated_file_max_for_adding = 0;
|
populated_file_max_for_adding = 0;
|
||||||
|
cancelled_file_count_for_adding = 0;
|
||||||
$('#wiki_edit_add_files').empty();
|
$('#wiki_edit_add_files').empty();
|
||||||
|
|
||||||
var f_no = 0;
|
var f_no = 0;
|
||||||
@ -228,6 +239,7 @@ function update_original_file_name_array ()
|
|||||||
}
|
}
|
||||||
|
|
||||||
$('#wiki_edit_file_list').empty();
|
$('#wiki_edit_file_list').empty();
|
||||||
|
killed_file_count = 0;
|
||||||
original_file_name_array = file_name_array;
|
original_file_name_array = file_name_array;
|
||||||
for (var i = 0; i < original_file_name_array.length; i++)
|
for (var i = 0; i < original_file_name_array.length; i++)
|
||||||
{
|
{
|
||||||
@ -248,7 +260,6 @@ function update_original_file_name_array ()
|
|||||||
var wiki_text_editor = null;
|
var wiki_text_editor = null;
|
||||||
var work_in_progress = false;
|
var work_in_progress = false;
|
||||||
var wiki_original_name = '<?php print addslashes($wiki->name); ?>';
|
var wiki_original_name = '<?php print addslashes($wiki->name); ?>';
|
||||||
var wiki_new_name = '';
|
|
||||||
var wiki_original_text = <?php print codepot_json_encode($wiki->text); ?>;
|
var wiki_original_text = <?php print codepot_json_encode($wiki->text); ?>;
|
||||||
|
|
||||||
function show_in_progress_message (outputMsg, titleMsg)
|
function show_in_progress_message (outputMsg, titleMsg)
|
||||||
@ -274,41 +285,11 @@ function show_in_progress_message (outputMsg, titleMsg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$(function () {
|
function save_wiki (wiki_new_name, wiki_new_text)
|
||||||
$('#wiki_edit_files').accordion({
|
{
|
||||||
collapsible: true,
|
|
||||||
heightStyle: "content",
|
|
||||||
activate: function() { resize_text_editor(); }
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#wiki_edit_add_files_button').button().click (function () {
|
|
||||||
$('#wiki_edit_add_files').trigger('click');
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
$('#wiki_edit_add_files').change (function () {
|
|
||||||
populate_selected_files_for_adding ();
|
|
||||||
});
|
|
||||||
|
|
||||||
<?php if ($mode == 'update'): ?>
|
|
||||||
$('#wiki_edit_text_area').val (wiki_original_text);
|
|
||||||
$('#wiki_edit_doctype').val ('<?php print $wiki->doctype; ?>');
|
|
||||||
<?php endif; ?>
|
|
||||||
|
|
||||||
$("#wiki_edit_preview_button").button().click (function() {
|
|
||||||
preview_text ($('#wiki_edit_text_area').val());
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
$("#wiki_edit_save_button").button().click (function() {
|
|
||||||
if (work_in_progress) return;
|
|
||||||
|
|
||||||
if (!!window.FormData)
|
|
||||||
{
|
|
||||||
// FormData is supported
|
|
||||||
work_in_progress = true;
|
work_in_progress = true;
|
||||||
show_in_progress_message ('Saving in progress. Please wait...', 'Saving...');
|
|
||||||
|
|
||||||
wiki_new_name = $('#wiki_edit_name').val();
|
show_in_progress_message ('<?php print $this->lang->line('WIKI_MSG_SAVE_IN_PROGRESS'); ?>', wiki_new_name);
|
||||||
wiki_new_text = $('#wiki_edit_text_area').val();
|
|
||||||
|
|
||||||
var form_data = new FormData();
|
var form_data = new FormData();
|
||||||
|
|
||||||
@ -386,6 +367,74 @@ $(function () {
|
|||||||
show_alert ('Failed - ' + errmsg, "<?php print $this->lang->line('Error')?>");
|
show_alert ('Failed - ' + errmsg, "<?php print $this->lang->line('Error')?>");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function save_wiki_with_confirmation (outputMsg, titleMsg, wiki_new_name, wiki_new_text)
|
||||||
|
{
|
||||||
|
$('#wiki_edit_alert').html(outputMsg).dialog({
|
||||||
|
title: titleMsg,
|
||||||
|
resizable: true,
|
||||||
|
modal: true,
|
||||||
|
width: 'auto',
|
||||||
|
height: 'auto',
|
||||||
|
buttons: {
|
||||||
|
"OK": function () {
|
||||||
|
$(this).dialog("close");
|
||||||
|
save_wiki (wiki_new_name, wiki_new_text);
|
||||||
|
},
|
||||||
|
"Cancel": function () {
|
||||||
|
$(this).dialog("close");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
$(function () {
|
||||||
|
$('#wiki_edit_files').accordion({
|
||||||
|
collapsible: true,
|
||||||
|
heightStyle: "content",
|
||||||
|
activate: function() { resize_text_editor(); }
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#wiki_edit_add_files_button').button().click (function () {
|
||||||
|
$('#wiki_edit_add_files').trigger('click');
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
$('#wiki_edit_add_files').change (function () {
|
||||||
|
populate_selected_files_for_adding ();
|
||||||
|
});
|
||||||
|
|
||||||
|
<?php if ($mode == 'update'): ?>
|
||||||
|
$('#wiki_edit_text_area').val (wiki_original_text);
|
||||||
|
$('#wiki_edit_doctype').val ('<?php print $wiki->doctype; ?>');
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
$("#wiki_edit_preview_button").button().click (function() {
|
||||||
|
preview_text ($('#wiki_edit_text_area').val());
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
$("#wiki_edit_save_button").button().click (function() {
|
||||||
|
if (work_in_progress) return;
|
||||||
|
|
||||||
|
if (!!window.FormData)
|
||||||
|
{
|
||||||
|
// FormData is supported
|
||||||
|
var wiki_new_name = $('#wiki_edit_name').val();
|
||||||
|
var wiki_new_text = $('#wiki_edit_text_area').val();
|
||||||
|
if (populated_file_max_for_adding > cancelled_file_count_for_adding ||
|
||||||
|
killed_file_count > 0 ||
|
||||||
|
wiki_original_name != wiki_new_name ||
|
||||||
|
wiki_original_text != wiki_new_text)
|
||||||
|
{
|
||||||
|
// there are changes. just save the document
|
||||||
|
save_wiki (wiki_new_name, wiki_new_text);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// no changes detected.
|
||||||
|
save_wiki_with_confirmation ("<?php print $this->lang->line('WIKI_MSG_SAVE_DESPITE_NO_CHANGES?'); ?>", wiki_new_name, wiki_new_name, wiki_new_text);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -404,8 +453,12 @@ $(function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
$(window).on ("beforeunload", function (e) {
|
$(window).on ("beforeunload", function (e) {
|
||||||
|
var wiki_new_name = $('#wiki_edit_name').val();
|
||||||
var wiki_new_text = $('#wiki_edit_text_area').val();
|
var wiki_new_text = $('#wiki_edit_text_area').val();
|
||||||
if (wiki_original_text != wiki_new_text)
|
if (populated_file_max_for_adding > cancelled_file_count_for_adding ||
|
||||||
|
killed_file_count > 0 ||
|
||||||
|
wiki_original_name != wiki_new_name ||
|
||||||
|
wiki_original_text != wiki_new_text)
|
||||||
{
|
{
|
||||||
return '<?php print $this->lang->line('MSG_DISCARD_CHANGES?'); ?>';
|
return '<?php print $this->lang->line('MSG_DISCARD_CHANGES?'); ?>';
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
<html>
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||||
|
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
@ -77,6 +79,8 @@ function resize_editor()
|
|||||||
|
|
||||||
var populated_file_obj_for_adding = [];
|
var populated_file_obj_for_adding = [];
|
||||||
var populated_file_max_for_adding = 0;
|
var populated_file_max_for_adding = 0;
|
||||||
|
var cancelled_file_count_for_adding = 0;
|
||||||
|
var killed_file_count = 0;
|
||||||
|
|
||||||
var original_file_name_array = [
|
var original_file_name_array = [
|
||||||
<?php
|
<?php
|
||||||
@ -118,10 +122,13 @@ function populate_selected_files_for_adding ()
|
|||||||
|
|
||||||
function cancel_out_add_file (no)
|
function cancel_out_add_file (no)
|
||||||
{
|
{
|
||||||
|
if (populated_file_obj_for_adding[no] != null)
|
||||||
|
{
|
||||||
|
cancelled_file_count_for_adding++;
|
||||||
$('#wiki_edit_add_file_row_' + no).remove ();
|
$('#wiki_edit_add_file_row_' + no).remove ();
|
||||||
populated_file_obj_for_adding[no] = null;
|
populated_file_obj_for_adding[no] = null;
|
||||||
|
|
||||||
resize_editor ();
|
resize_editor ();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function kill_file (no)
|
function kill_file (no)
|
||||||
@ -133,11 +140,13 @@ function kill_file (no)
|
|||||||
{
|
{
|
||||||
n.css ('text-decoration', '');
|
n.css ('text-decoration', '');
|
||||||
n.prop ('disabled', false);
|
n.prop ('disabled', false);
|
||||||
|
killed_file_count--;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
n.css ('text-decoration', 'line-through');
|
n.css ('text-decoration', 'line-through');
|
||||||
n.prop ('disabled', true);
|
n.prop ('disabled', true);
|
||||||
|
killed_file_count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,6 +166,7 @@ function update_original_file_name_array ()
|
|||||||
|
|
||||||
populated_file_obj_for_adding = [];
|
populated_file_obj_for_adding = [];
|
||||||
populated_file_max_for_adding = 0;
|
populated_file_max_for_adding = 0;
|
||||||
|
cancelled_file_count_for_adding = 0;
|
||||||
$('#wiki_edit_add_files').empty();
|
$('#wiki_edit_add_files').empty();
|
||||||
|
|
||||||
var f_no = 0;
|
var f_no = 0;
|
||||||
@ -178,6 +188,7 @@ function update_original_file_name_array ()
|
|||||||
}
|
}
|
||||||
|
|
||||||
$('#wiki_edit_file_list').empty();
|
$('#wiki_edit_file_list').empty();
|
||||||
|
killed_file_count = 0;
|
||||||
original_file_name_array = file_name_array;
|
original_file_name_array = file_name_array;
|
||||||
for (var i = 0; i < original_file_name_array.length; i++)
|
for (var i = 0; i < original_file_name_array.length; i++)
|
||||||
{
|
{
|
||||||
@ -198,7 +209,6 @@ function update_original_file_name_array ()
|
|||||||
var wiki_text_editor = null;
|
var wiki_text_editor = null;
|
||||||
var work_in_progress = false;
|
var work_in_progress = false;
|
||||||
var wiki_original_name = '<?php print addslashes($wiki->name); ?>';
|
var wiki_original_name = '<?php print addslashes($wiki->name); ?>';
|
||||||
var wiki_new_name = '';
|
|
||||||
var wiki_original_text = <?php print codepot_json_encode($wiki->text); ?>;
|
var wiki_original_text = <?php print codepot_json_encode($wiki->text); ?>;
|
||||||
|
|
||||||
function show_in_progress_message (outputMsg, titleMsg)
|
function show_in_progress_message (outputMsg, titleMsg)
|
||||||
@ -224,6 +234,109 @@ function show_in_progress_message (outputMsg, titleMsg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function save_wiki (wiki_new_name, wiki_new_text)
|
||||||
|
{
|
||||||
|
work_in_progress = true;
|
||||||
|
show_in_progress_message ('<?php print $this->lang->line('WIKI_MSG_SAVE_IN_PROGRESS'); ?>', wiki_new_name);
|
||||||
|
|
||||||
|
var form_data = new FormData();
|
||||||
|
|
||||||
|
var f_no = 0;
|
||||||
|
for (var i = 0; i < populated_file_max_for_adding; i++)
|
||||||
|
{
|
||||||
|
var f = populated_file_obj_for_adding[i];
|
||||||
|
if (f != null)
|
||||||
|
{
|
||||||
|
form_data.append ('wiki_file_' + f_no, f);
|
||||||
|
f_no++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
form_data.append ('wiki_file_count', f_no);
|
||||||
|
|
||||||
|
f_no = 0;
|
||||||
|
for (var i = 0; i < original_file_name_array.length; i++)
|
||||||
|
{
|
||||||
|
var n = $('#wiki_edit_file_name_' + i);
|
||||||
|
if (n)
|
||||||
|
{
|
||||||
|
if (n.prop('disabled'))
|
||||||
|
{
|
||||||
|
form_data.append ('wiki_kill_file_name_' + f_no, original_file_name_array[i]);
|
||||||
|
f_no++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
form_data.append ('wiki_kill_file_count', f_no);
|
||||||
|
|
||||||
|
form_data.append ('wiki_doctype', 'H');
|
||||||
|
form_data.append ('wiki_name', wiki_new_name);
|
||||||
|
form_data.append ('wiki_original_name', wiki_original_name);
|
||||||
|
form_data.append ('wiki_text', wiki_new_text);
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: codepot_merge_path('<?php print site_url() ?>', '<?php print "/wiki/xhr_edit/{$project->id}"; ?>'),
|
||||||
|
type: 'POST',
|
||||||
|
data: form_data,
|
||||||
|
mimeType: 'multipart/form-data',
|
||||||
|
contentType: false,
|
||||||
|
processData: false,
|
||||||
|
cache: false,
|
||||||
|
|
||||||
|
success: function (data, textStatus, jqXHR) {
|
||||||
|
work_in_progress = false;
|
||||||
|
|
||||||
|
if (data == 'ok')
|
||||||
|
{
|
||||||
|
var name_changed = (wiki_original_name != wiki_new_name);
|
||||||
|
wiki_original_name = wiki_new_name;
|
||||||
|
wiki_original_text = wiki_new_text;
|
||||||
|
update_original_file_name_array ();
|
||||||
|
show_in_progress_message (null, null);
|
||||||
|
if (name_changed)
|
||||||
|
{
|
||||||
|
// reload the whole page if the name has changed.
|
||||||
|
$(location).attr ('href', codepot_merge_path('<?php print site_url(); ?>', '<?php print "/wiki/updatex/{$project->id}/"; ?>' + codepot_string_to_hex(wiki_new_name)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
show_in_progress_message (null, null);
|
||||||
|
show_alert ('<pre>' + codepot_htmlspecialchars(data) + '</pre>', "<?php print $this->lang->line('Error')?>");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
error: function (jqXHR, textStatus, errorThrown) {
|
||||||
|
work_in_progress = false;
|
||||||
|
show_in_progress_message (null, null);
|
||||||
|
var errmsg = '';
|
||||||
|
if (errmsg == '' && errorThrown != null) errmsg = errorThrown;
|
||||||
|
if (errmsg == '' && textStatus != null) errmsg = textStatus;
|
||||||
|
if (errmsg == '') errmsg = 'Unknown error';
|
||||||
|
show_alert ('Failed - ' + errmsg, "<?php print $this->lang->line('Error')?>");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function save_wiki_with_confirmation (outputMsg, titleMsg, wiki_new_name, wiki_new_text)
|
||||||
|
{
|
||||||
|
$('#wiki_edit_alert').html(outputMsg).dialog({
|
||||||
|
title: titleMsg,
|
||||||
|
resizable: true,
|
||||||
|
modal: true,
|
||||||
|
width: 'auto',
|
||||||
|
height: 'auto',
|
||||||
|
buttons: {
|
||||||
|
"OK": function () {
|
||||||
|
$(this).dialog("close");
|
||||||
|
save_wiki (wiki_new_name, wiki_new_text);
|
||||||
|
},
|
||||||
|
"Cancel": function () {
|
||||||
|
$(this).dialog("close");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
$(function () {
|
$(function () {
|
||||||
$('#wiki_edit_files').accordion({
|
$('#wiki_edit_files').accordion({
|
||||||
collapsible: true,
|
collapsible: true,
|
||||||
@ -288,94 +401,28 @@ $(function () {
|
|||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
$("#wiki_edit_save_button").button().click (function() {
|
$("#wiki_edit_save_button").button().click (function() {
|
||||||
var e = wiki_text_editor.serialize();
|
|
||||||
|
|
||||||
if (work_in_progress) return;
|
if (work_in_progress) return;
|
||||||
|
|
||||||
if (!!window.FormData)
|
if (!!window.FormData)
|
||||||
{
|
{
|
||||||
// FormData is supported
|
// FormData is supported
|
||||||
work_in_progress = true;
|
var wiki_new_name = $('#wiki_edit_name').val();
|
||||||
show_in_progress_message ('Saving in progress. Please wait...', 'Saving...');
|
var ed = wiki_text_editor.serialize();
|
||||||
|
|
||||||
wiki_new_name = $('#wiki_edit_name').val();
|
var wiki_new_text = $('#wiki_edit_text_area').val();
|
||||||
|
if (populated_file_max_for_adding > cancelled_file_count_for_adding ||
|
||||||
var form_data = new FormData();
|
killed_file_count > 0 ||
|
||||||
|
wiki_original_name != wiki_new_name ||
|
||||||
var f_no = 0;
|
wiki_original_text != ed.wiki_edit_text_editor.value)
|
||||||
for (var i = 0; i < populated_file_max_for_adding; i++)
|
|
||||||
{
|
{
|
||||||
var f = populated_file_obj_for_adding[i];
|
// there are changes. just save the document
|
||||||
if (f != null)
|
save_wiki (wiki_new_name, ed.wiki_edit_text_editor.value);
|
||||||
{
|
|
||||||
form_data.append ('wiki_file_' + f_no, f);
|
|
||||||
f_no++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
form_data.append ('wiki_file_count', f_no);
|
|
||||||
|
|
||||||
f_no = 0;
|
|
||||||
for (var i = 0; i < original_file_name_array.length; i++)
|
|
||||||
{
|
|
||||||
var n = $('#wiki_edit_file_name_' + i);
|
|
||||||
if (n)
|
|
||||||
{
|
|
||||||
if (n.prop('disabled'))
|
|
||||||
{
|
|
||||||
form_data.append ('wiki_kill_file_name_' + f_no, original_file_name_array[i]);
|
|
||||||
f_no++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
form_data.append ('wiki_kill_file_count', f_no);
|
|
||||||
|
|
||||||
form_data.append ('wiki_doctype', 'H');
|
|
||||||
form_data.append ('wiki_name', wiki_new_name);
|
|
||||||
form_data.append ('wiki_original_name', wiki_original_name);
|
|
||||||
form_data.append ('wiki_text', e.wiki_edit_text_editor.value);
|
|
||||||
|
|
||||||
$.ajax({
|
|
||||||
url: codepot_merge_path('<?php print site_url() ?>', '<?php print "/wiki/xhr_edit/{$project->id}"; ?>'),
|
|
||||||
type: 'POST',
|
|
||||||
data: form_data,
|
|
||||||
mimeType: 'multipart/form-data',
|
|
||||||
contentType: false,
|
|
||||||
processData: false,
|
|
||||||
cache: false,
|
|
||||||
|
|
||||||
success: function (data, textStatus, jqXHR) {
|
|
||||||
work_in_progress = false;
|
|
||||||
|
|
||||||
if (data == 'ok')
|
|
||||||
{
|
|
||||||
var name_changed = (wiki_original_name != wiki_new_name);
|
|
||||||
wiki_original_name = wiki_new_name;
|
|
||||||
wiki_original_text = e.wiki_edit_text_editor.value;
|
|
||||||
update_original_file_name_array ();
|
|
||||||
show_in_progress_message (null, null);
|
|
||||||
if (name_changed)
|
|
||||||
{
|
|
||||||
// reload the whole page if the name has changed.
|
|
||||||
$(location).attr ('href', codepot_merge_path('<?php print site_url(); ?>', '<?php print "/wiki/updatex/{$project->id}/"; ?>' + codepot_string_to_hex(wiki_new_name)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
show_in_progress_message (null, null);
|
// no changes detected.
|
||||||
show_alert ('<pre>' + codepot_htmlspecialchars(data) + '</pre>', "<?php print $this->lang->line('Error')?>");
|
save_wiki_with_confirmation ("<?php print $this->lang->line('WIKI_MSG_SAVE_DESPITE_NO_CHANGES?'); ?>", wiki_new_name, wiki_new_name, ed.wiki_edit_text_editor.value);
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
|
||||||
error: function (jqXHR, textStatus, errorThrown) {
|
|
||||||
work_in_progress = false;
|
|
||||||
show_in_progress_message (null, null);
|
|
||||||
var errmsg = '';
|
|
||||||
if (errmsg == '' && errorThrown != null) errmsg = errorThrown;
|
|
||||||
if (errmsg == '' && textStatus != null) errmsg = textStatus;
|
|
||||||
if (errmsg == '') errmsg = 'Unknown error';
|
|
||||||
show_alert ('Failed - ' + errmsg, "<?php print $this->lang->line('Error')?>");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -394,8 +441,13 @@ $(function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
$(window).on ("beforeunload", function (e) {
|
$(window).on ("beforeunload", function (e) {
|
||||||
|
var wiki_new_name = $('#wiki_edit_name').val();
|
||||||
var ed = wiki_text_editor.serialize();
|
var ed = wiki_text_editor.serialize();
|
||||||
if (wiki_original_text != ed.wiki_edit_text_editor.value)
|
|
||||||
|
if (populated_file_max_for_adding > cancelled_file_count_for_adding ||
|
||||||
|
killed_file_count > 0 ||
|
||||||
|
wiki_original_name != wiki_new_name ||
|
||||||
|
wiki_original_text != ed.wiki_edit_text_editor.value)
|
||||||
{
|
{
|
||||||
return '<?php print $this->lang->line('MSG_DISCARD_CHANGES?'); ?>';
|
return '<?php print $this->lang->line('MSG_DISCARD_CHANGES?'); ?>';
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user