diff --git a/codepot/src/codepot/controllers/wiki.php b/codepot/src/codepot/controllers/wiki.php index 43d9f0af..f75b93fe 100644 --- a/codepot/src/codepot/controllers/wiki.php +++ b/codepot/src/codepot/controllers/wiki.php @@ -288,180 +288,6 @@ class Wiki extends Controller 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('',''); - - 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 // between issue.php and wiki.php. It would be way better diff --git a/codepot/src/codepot/language/english/common_lang.php b/codepot/src/codepot/language/english/common_lang.php index feee77bc..e44136d9 100644 --- a/codepot/src/codepot/language/english/common_lang.php +++ b/codepot/src/codepot/language/english/common_lang.php @@ -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_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?'; ?> diff --git a/codepot/src/codepot/language/english/wiki_lang.php b/codepot/src/codepot/language/english/wiki_lang.php index 3f120b7f..1c64a9a8 100644 --- a/codepot/src/codepot/language/english/wiki_lang.php +++ b/codepot/src/codepot/language/english/wiki_lang.php @@ -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_SUCH_PAGE'] = 'No such wiki page'; $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'; ?> diff --git a/codepot/src/codepot/language/indonesian/common_lang.php b/codepot/src/codepot/language/indonesian/common_lang.php index 6a087e70..a8cdd553 100644 --- a/codepot/src/codepot/language/indonesian/common_lang.php +++ b/codepot/src/codepot/language/indonesian/common_lang.php @@ -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_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?'; ?> diff --git a/codepot/src/codepot/language/korean/wiki_lang.php b/codepot/src/codepot/language/korean/wiki_lang.php index 9c35dd68..881f7944 100644 --- a/codepot/src/codepot/language/korean/wiki_lang.php +++ b/codepot/src/codepot/language/korean/wiki_lang.php @@ -8,4 +8,7 @@ $lang['WIKI_MSG_NAME_DISALLOWED_CHARS'] = '위키이름에 허용되지 않는 $lang['WIKI_MSG_NO_PAGES_AVAILABLE'] = '사용할 수 있는 위키 페이지가 없습니다'; $lang['WIKI_MSG_NO_SUCH_PAGE'] = '위키 페이지를 찾을수 없습니다'; $lang['WIKI_MSG_RESERVED_WIKI_NAME'] = '%s은(는) 사용할 수 없는 위키이름입니다'; + +$lang['WIKI_MSG_SAVE_DESPITE_NO_CHANGES?'] = '변경된 내용이 없는것 같습니다. 그래도 저장하겠습니까?'; +$lang['WIKI_MSG_SAVE_IN_PROGRESS'] = '저장중이니 잠시 기다려 주세요'; ?> diff --git a/codepot/src/codepot/views/Makefile.am b/codepot/src/codepot/views/Makefile.am index aec2ac1c..ee5bcdff 100644 --- a/codepot/src/codepot/views/Makefile.am +++ b/codepot/src/codepot/views/Makefile.am @@ -31,7 +31,6 @@ www_DATA = \ taskbar.php \ user_home.php \ user_settings.php \ - wiki_delete.php \ wiki_edit.php \ wiki_editx.php \ wiki_home.php \ diff --git a/codepot/src/codepot/views/Makefile.in b/codepot/src/codepot/views/Makefile.in index 4ad3c45d..43ee5023 100644 --- a/codepot/src/codepot/views/Makefile.in +++ b/codepot/src/codepot/views/Makefile.in @@ -176,7 +176,6 @@ www_DATA = \ taskbar.php \ user_home.php \ user_settings.php \ - wiki_delete.php \ wiki_edit.php \ wiki_editx.php \ wiki_home.php \ diff --git a/codepot/src/codepot/views/project_home.php b/codepot/src/codepot/views/project_home.php index 599e74c3..966fdf88 100644 --- a/codepot/src/codepot/views/project_home.php +++ b/codepot/src/codepot/views/project_home.php @@ -233,7 +233,6 @@ foreach ($urls as $url) if ($log['action'] != 'revpropchange') { - print '
'; print '
';
 					$sm = strtok (trim ($x['message']), "\r\n");
diff --git a/codepot/src/codepot/views/wiki_delete.php b/codepot/src/codepot/views/wiki_delete.php
deleted file mode 100644
index fb6e3811..00000000
--- a/codepot/src/codepot/views/wiki_delete.php
+++ /dev/null
@@ -1,90 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-<?php print htmlspecialchars($wiki->name)?>
-
-
-
-
-
- - - -load->view ('taskbar'); ?> - - - -load->view ( - 'projectbar', - array ( - 'banner' => NULL, - - 'page' => array ( - 'type' => 'project', - 'id' => 'wiki', - 'project' => $project, - ), - - 'ctxmenuitems' => array () - ) -); -?> - - - -
- -'.htmlspecialchars($message).'
'; ?> - -
-id}/".$this->converter->AsciiToHex($wiki->name))?> - -
-
- - lang->line('MSG_SURE_TO_DELETE_THIS')?> - name)?> - -
-
- -
- projectid))?> - name))?> -
- -
- lang->line('Delete'))?> -
- - -
- -
- - - -
- - - -load->view ('footer'); ?> - - - - - - - diff --git a/codepot/src/codepot/views/wiki_edit.php b/codepot/src/codepot/views/wiki_edit.php index 0e261e0d..89e5c17a 100644 --- a/codepot/src/codepot/views/wiki_edit.php +++ b/codepot/src/codepot/views/wiki_edit.php @@ -1,4 +1,6 @@ - + + + @@ -46,6 +48,7 @@ function show_alert (outputMsg, titleMsg) }); } + var previewing_text = false; function resize_text_editor() @@ -127,6 +130,8 @@ function preview_text (input_text) var populated_file_obj_for_adding = []; var populated_file_max_for_adding = 0; +var cancelled_file_count_for_adding = 0; +var killed_file_count = 0; var original_file_name_array = [ name); ?>'; -var wiki_new_name = ''; var wiki_original_text = text); ?>; function show_in_progress_message (outputMsg, titleMsg) @@ -274,6 +285,111 @@ function show_in_progress_message (outputMsg, titleMsg) } } +function save_wiki (wiki_new_name, wiki_new_text) +{ + work_in_progress = true; + + show_in_progress_message ('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', $('#wiki_edit_doctype').val()); + 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('', '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('', 'id}/"; ?>' + codepot_string_to_hex(wiki_new_name))); + } + } + else + { + show_in_progress_message (null, null); + show_alert ('
' + codepot_htmlspecialchars(data) + '
', "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, "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, @@ -304,88 +420,21 @@ $(function () { if (!!window.FormData) { // FormData is supported - work_in_progress = true; - show_in_progress_message ('Saving in progress. Please wait...', 'Saving...'); - - wiki_new_name = $('#wiki_edit_name').val(); - wiki_new_text = $('#wiki_edit_text_area').val(); - - var form_data = new FormData(); - - var f_no = 0; - for (var i = 0; i < populated_file_max_for_adding; i++) + 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) { - var f = populated_file_obj_for_adding[i]; - if (f != null) - { - form_data.append ('wiki_file_' + f_no, f); - f_no++; - } + // there are changes. just save the document + save_wiki (wiki_new_name, wiki_new_text); } - form_data.append ('wiki_file_count', f_no); - - f_no = 0; - for (var i = 0; i < original_file_name_array.length; i++) + else { - 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++; - } - } + // no changes detected. + save_wiki_with_confirmation ("lang->line('WIKI_MSG_SAVE_DESPITE_NO_CHANGES?'); ?>", wiki_new_name, wiki_new_name, wiki_new_text); } - form_data.append ('wiki_kill_file_count', f_no); - - form_data.append ('wiki_doctype', $('#wiki_edit_doctype').val()); - 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('', '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('', 'id}/"; ?>' + codepot_string_to_hex(wiki_new_name))); - } - } - else - { - show_in_progress_message (null, null); - show_alert ('
' + codepot_htmlspecialchars(data) + '
', "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, "lang->line('Error')?>"); - } - }); } else { @@ -404,8 +453,12 @@ $(function () { }); $(window).on ("beforeunload", function (e) { + var wiki_new_name = $('#wiki_edit_name').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 'lang->line('MSG_DISCARD_CHANGES?'); ?>'; } diff --git a/codepot/src/codepot/views/wiki_editx.php b/codepot/src/codepot/views/wiki_editx.php index eac45776..25b23919 100644 --- a/codepot/src/codepot/views/wiki_editx.php +++ b/codepot/src/codepot/views/wiki_editx.php @@ -1,4 +1,6 @@ - + + + @@ -77,6 +79,8 @@ function resize_editor() var populated_file_obj_for_adding = []; var populated_file_max_for_adding = 0; +var cancelled_file_count_for_adding = 0; +var killed_file_count = 0; var original_file_name_array = [ name); ?>'; -var wiki_new_name = ''; var wiki_original_text = text); ?>; 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 ('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('', '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('', 'id}/"; ?>' + codepot_string_to_hex(wiki_new_name))); + } + } + else + { + show_in_progress_message (null, null); + show_alert ('
' + codepot_htmlspecialchars(data) + '
', "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, "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, @@ -288,94 +401,28 @@ $(function () { $("#wiki_edit_save_button").button().click (function() { - var e = wiki_text_editor.serialize(); - if (work_in_progress) return; if (!!window.FormData) { // FormData is supported - work_in_progress = true; - show_in_progress_message ('Saving in progress. Please wait...', 'Saving...'); + var wiki_new_name = $('#wiki_edit_name').val(); + var ed = wiki_text_editor.serialize(); - wiki_new_name = $('#wiki_edit_name').val(); - - var form_data = new FormData(); - - var f_no = 0; - for (var i = 0; i < populated_file_max_for_adding; i++) + 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 != ed.wiki_edit_text_editor.value) { - var f = populated_file_obj_for_adding[i]; - if (f != null) - { - form_data.append ('wiki_file_' + f_no, f); - f_no++; - } + // there are changes. just save the document + save_wiki (wiki_new_name, ed.wiki_edit_text_editor.value); } - form_data.append ('wiki_file_count', f_no); - - f_no = 0; - for (var i = 0; i < original_file_name_array.length; i++) + else { - 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++; - } - } + // no changes detected. + save_wiki_with_confirmation ("lang->line('WIKI_MSG_SAVE_DESPITE_NO_CHANGES?'); ?>", wiki_new_name, wiki_new_name, ed.wiki_edit_text_editor.value); } - 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('', '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('', 'id}/"; ?>' + codepot_string_to_hex(wiki_new_name))); - } - } - else - { - show_in_progress_message (null, null); - show_alert ('
' + codepot_htmlspecialchars(data) + '
', "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, "lang->line('Error')?>"); - } - }); } else { @@ -394,8 +441,13 @@ $(function () { }); $(window).on ("beforeunload", function (e) { + var wiki_new_name = $('#wiki_edit_name').val(); 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 'lang->line('MSG_DISCARD_CHANGES?'); ?>'; }