From 16a056303efba94281d82ed963b92fce9c3d9daf Mon Sep 17 00:00:00 2001 From: LV-426 Date: Mon, 18 May 2015 17:01:52 +0300 Subject: rz_core: rzdoc__open(): handle rzdoc 404, use of status-bar requires model/view refactoring --- src/client/rz_core.js | 69 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 55 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/client/rz_core.js b/src/client/rz_core.js index 5fbb6f07..2b3458d7 100644 --- a/src/client/rz_core.js +++ b/src/client/rz_core.js @@ -322,23 +322,64 @@ function rzdoc__create_and_open(rzdoc_name) { * - do nothing if name of current rzdoc equals requested rzdoc */ function rzdoc__open(rzdoc_name) { + + function on_success() { + get_search().clear(); + main_graph_view.zen_mode__cancel(); + window.history.replaceState(null, page_title(rzdoc_name), url_for_doc(rzdoc_name) + location.search); + + var rzdoc_bar = $('#rzdoc-bar_doc-label'); + var rzdoc_bar__doc_lable = $('#rzdoc-bar_doc-label'); + rzdoc_bar.fadeToggle(500, 'swing', function() { + rzdoc_bar__doc_lable.text(rzdoc_name); + rzdoc_bar.fadeToggle(500); + }); + + rz_mesh.emit__rzdoc_subscribe(rzdoc_name); + console.log('rzdoc: opened rzdoc : \'' + rzdoc_name + '\''); + }; + + function on_error(xhr, status, err_thrown) { + var close_btn, + create_btn, + status_bar_body, + rzdoc_name, + status_bar; + + rzdoc_name = xhr.responseJSON.data.rzdoc_name; + + create_btn = $(''); + create_btn.text('Create document'); + create_btn.addClass('status-bar__btn_rzdoc_create_post_404'); + + close_btn = $('
x
'); + close_btn.addClass('toolbar__close_btn'); + + status_bar_body = $('
'); + status_bar_body.text('Rhizi could not find a document titled \'' + rzdoc_name + '\'.'); + status_bar_body.addClass('status-bar__body'); + status_bar_body.append(create_btn); + + status_bar = $('#status-bar'); // reset + status_bar.children().remove(); + status_bar.append(close_btn); + status_bar.append(status_bar_body); + + create_btn.click(function() { + rzdoc__create_and_open(rzdoc_name); + status_bar.hide(); + }); + close_btn.click(function() { + status_bar.hide(); + }); + + status_bar.show(); + } + rz_config.rzdoc_cur__name = rzdoc_name; main_graph.clear(); edit_graph.clear(); - main_graph.load_from_backend(); - get_search().clear(); - main_graph_view.zen_mode__cancel(); - window.history.replaceState(null, page_title(rzdoc_name), url_for_doc(rzdoc_name) + location.search); - - var rzdoc_bar = $('#rzdoc-bar_doc-label'); - var rzdoc_bar__doc_lable = $('#rzdoc-bar_doc-label'); - rzdoc_bar.fadeToggle(500, 'swing', function() { - rzdoc_bar__doc_lable.text(rzdoc_name); - rzdoc_bar.fadeToggle(500); - }); - - rz_mesh.emit__rzdoc_subscribe(rzdoc_name); - console.log('rzdoc: opened rzdoc : \'' + rzdoc_name + '\''); + main_graph.load_from_backend(on_success, on_error); } function rzdoc__current__get_name() { -- cgit v1.3.1