diff options
| author | LV-426 <lv-426@taproot.org.il> | 2015-05-18 17:01:52 +0300 |
|---|---|---|
| committer | LV-426 <lv-426@taproot.org.il> | 2015-05-18 18:33:11 +0300 |
| commit | 16a056303efba94281d82ed963b92fce9c3d9daf (patch) | |
| tree | ddf4878a7437389d86063d79bf50d90e527b0539 /src | |
| parent | 3cdd6106fafd467da8014c61fd06b2d153629a35 (diff) | |
rz_core: rzdoc__open(): handle rzdoc 404, use of status-bar requires model/view refactoring
Diffstat (limited to 'src')
| -rw-r--r-- | src/client/rz_core.js | 69 |
1 files changed, 55 insertions, 14 deletions
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 = $('<span>'); + create_btn.text('Create document'); + create_btn.addClass('status-bar__btn_rzdoc_create_post_404'); + + close_btn = $('<div>x</div>'); + close_btn.addClass('toolbar__close_btn'); + + status_bar_body = $('<div>'); + 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() { |
