X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=js%2Frequirement_spec.js;h=5078971672bf65dd6fa592413f9727c0c1e6f0d9;hb=1c14fb86cf1b40ea0a91701d62a1a77b3146026c;hp=00e4319a012402df0e61f0f5453db0e13493265f;hpb=2c92b5acfbbc7486730ec7feec509abbdcbc7ebc;p=kivitendo-erp.git diff --git a/js/requirement_spec.js b/js/requirement_spec.js index 00e4319a0..507897167 100644 --- a/js/requirement_spec.js +++ b/js/requirement_spec.js @@ -102,12 +102,69 @@ ns.tree_node_clicked = function(event) { }, kivi.eval_json_result); }; +ns.setup_tooltip_for_tree_node = function(li) { + $(li).find('a').prop('title', $(li).prop('title')).tooltip(); + $(li).prop('title', ''); +}; + +ns.tree_loaded = function(event) { + var id = $('#tree').data('initially_selected_node'); + if (id) + $.jstree._reference("#tree").select_node(id, true); + + $('#tree li[title!=""]').each(function(idx, elt) { + ns.setup_tooltip_for_tree_node(elt); + }); +}; + +ns.tree_node_created = function(event, data) { + console.info("created ", data); + if (data && data.rslt && data.rslt.obj) + ns.setup_tooltip_for_tree_node(data.rslt.obj); +}; + +ns.initialize_requirement_spec = function(data) { + $('#tree').data('initially_selected_node', data.initially_selected_node); + + $('#tree') + .bind('create_node.jstree', ns.tree_node_created) + .bind('move_node.jstree', ns.tree_node_moved) + .bind('click.jstree', ns.tree_node_clicked) + .bind('loaded.jstree', ns.tree_loaded) + .jstree({ + core: { + animation: 0, + initially_open: data.initially_open, + }, + json_data: { + data: data.tree_data + }, + crrm: { + move: { + check_move: ns.tree_check_move, + open_move: true + } + }, + themes: { + theme: "requirement-spec" + }, + plugins: [ "themes", "json_data", "ui", "crrm", "dnd" ] + }); + + ns.create_context_menus(data.is_template); + $('#requirement_spec_tabs').on("tabsbeforeactivate", ns.tabs_before_activate); +}; + // ------------------------------------------------------------------------- // ------------------------------ text blocks ------------------------------ // ------------------------------------------------------------------------- ns.find_text_block_id = function(clicked_elt) { var id = $(clicked_elt).attr('id'); + + if (/^text-block-picture-\d+$/.test(id)) + id = $(clicked_elt).closest('.text-block-context-menu').attr('id'); + // console.log("id: " + id); if (/^text-block-\d+$/.test(id)) { // console.log("find_text_block_id: case 1: " + id.substr(11)); @@ -174,13 +231,74 @@ ns.ask_delete_text_block = function(key, opt) { return true; }; -ns.text_block_input_key_down = function(event) { - if(event.keyCode == 13) { - event.preventDefault(); - var prefix = $(this).attr('id').match("^edit_function_block_\\d+")[0]; - $("#" + prefix + "_submit").click(); - return false; - } +ns.find_text_block_picture_id = function(clicked_elt) { + var id = $(clicked_elt).attr('id'); + var match = id.match(/^text-block-picture-(\d+)$/); + if (match) + return match[1] * 1; + + return undefined; +}; + +ns.add_edit_text_block_picture_ajax_call = function(key, opt) { + var title = key == 'add_picture' ? kivi.t8('Add picture to text block') : kivi.t8('Edit picture'); + + kivi.popup_dialog({ url: 'controller.pl', + data: { action: 'RequirementSpecTextBlock/ajax_' + key, + id: ns.find_text_block_id(opt.$trigger), + picture_id: ns.find_text_block_picture_id(opt.$trigger) }, + dialog: { title: title }}); + + return true; +}; + +ns.standard_text_block_picture_ajax_call = function(key, opt) { + var data = { + action: "RequirementSpecTextBlock/ajax_" + key + , id: ns.find_text_block_picture_id(opt.$trigger) + }; + + if (key == 'download_picture') + $.download("controller.pl", data); + else + $.post("controller.pl", data, kivi.eval_json_result); + + return true; +}; + +ns.ask_delete_text_block_picture = function(key, opt) { + if (confirm(kivi.t8("Are you sure?"))) + ns.standard_text_block_picture_ajax_call(key, opt); + return true; +}; + +ns.handle_text_block_picture_popup_menu_markings = function(opt, add) { + var id = ns.find_text_block_picture_id(opt.$trigger); + if (id) + $('#text-block-picture-' + id ).toggleClass('selected', add); + return true; +}; + +ns.text_block_picture_popup_menu_shown = function(opt) { + return ns.handle_text_block_picture_popup_menu_markings(opt, true); +}; + +ns.text_block_picture_popup_menu_hidden = function(opt) { + return ns.handle_text_block_picture_popup_menu_markings(opt, false); +}; + +ns.make_text_block_picture_lists_sortable = function() { + kivi.run_once_for(".requirement-spec-text-block-picture-list", 'make-text-block-picture-list-sortable', function($elt) { + $elt.sortable({ + stop: function(event, ui) { + $.post('controller.pl?action=RequirementSpecTextBlock/reorder_pictures', { + 'picture_id[]': $($elt.sortable('toArray')).map(function(idx, str) { return str.replace('text-block-picture-', ''); }).toArray() + }); + return ui; + } + , distance: 5 + }); + }); }; // -------------------------------------------------------------------------------- @@ -276,6 +394,23 @@ ns.item_popup_menu_hidden = function(opt) { return ns.handle_item_popup_menu_markings(opt, false); }; +ns.submit_function_block = function(event, shift_in_out) { + event.preventDefault(); + + var prefix = $(this).attr('id').match("^(?:edit|new)_function_block_[\\d_]+\\d")[0]; + var action = $('#' + prefix + '_id').val() ? 'update' : 'create'; + kivi.submit_ajax_form('controller.pl?action=RequirementSpecItem/ajax_' + action, '#' + prefix + '_form', { shift_in_out: !!shift_in_out }); + + return false; +}; + +ns.init_function_block_keypress_events = function(form_id) { + $("#" + form_id + " INPUT[type=text]").bind("keypress", "return", ns.submit_function_block); + + $('#' + form_id + ' INPUT[type=text],#' + form_id + ' TEXTAREA,#' + form_id + ' INPUT[type=button]') + .bind('keypress', 'shift+return', function(event) { return ns.submit_function_block.apply(this, [ event, true ]); }); +}; + // ------------------------------------------------------------------------- // ------------------------------- templates ------------------------------- // ------------------------------------------------------------------------- @@ -309,9 +444,13 @@ ns.standard_basic_settings_ajax_call = function(key, opt) { if (key == 'cancel') { if (confirm(kivi.t8('Do you really want to cancel?'))) { $('#basic_settings').show(); - $('#basic_settings_form').remove(); + $('#basic_settings_form,#project_link_form').remove(); } return true; + + } else if (key == 'save') { + $('#basic_settings_form_submit').click(); + return true; } var data = 'action=RequirementSpec/ajax_' + key + '&id=' + encodeURIComponent($('#requirement_spec_id').val()); @@ -334,7 +473,13 @@ ns.standard_time_cost_estimate_ajax_call = function(key, opt) { return true; } - var data = "action=RequirementSpec/ajax_" + key + "_time_and_cost_estimate&"; + var add_data = ''; + if (key == 'save_keep_open') { + key = 'save'; + add_data = 'keep_open=1&'; + } + + var data = "action=RequirementSpec/ajax_" + key + "_time_and_cost_estimate&" + add_data; if (key == 'save') data += $('#edit_time_cost_estimate_form').serialize() @@ -543,6 +688,14 @@ ns.create_context_menus = function(is_template) { , delete_reqspec: { name: kivi.t8('Delete template'), icon: "delete", callback: kivi.requirement_spec.delete_reqspec } }; + $.contextMenu({ + selector: '.basic-settings-context-menu', + items: $.extend({ + heading: { name: kivi.t8('Basic settings actions'), className: 'context-menu-heading' } + , edit: { name: kivi.t8('Edit'), icon: "edit", callback: kivi.requirement_spec.standard_basic_settings_ajax_call } + }, general_actions) + }); + } else { // if (is_template) var general_actions = { sep98: "---------" @@ -564,15 +717,28 @@ ns.create_context_menus = function(is_template) { }, general_actions) }); + $.contextMenu({ + selector: '.basic-settings-context-menu', + items: $.extend({ + heading: { name: kivi.t8('Basic settings actions'), className: 'context-menu-heading' } + , edit: { name: kivi.t8('Edit'), icon: "edit", callback: kivi.requirement_spec.standard_basic_settings_ajax_call } + , edit_project_link: { name: kivi.t8('Edit project link'), callback: kivi.requirement_spec.standard_basic_settings_ajax_call } + }, general_actions) + }); + + $.contextMenu({ + selector: '.edit-project-link-context-menu', + items: $.extend({ + heading: { name: kivi.t8('Project link actions'), className: 'context-menu-heading' } + , save: { name: kivi.t8('Save'), icon: "save", callback: kivi.requirement_spec.standard_basic_settings_ajax_call } + , cancel: { name: kivi.t8('Cancel'), icon: "close", callback: kivi.requirement_spec.standard_basic_settings_ajax_call } + }, general_actions) + }); + var paste_template_actions = { }; } // if (is_template) ... else ... - var events = { - show: kivi.requirement_spec.text_block_popup_menu_shown - , hide: kivi.requirement_spec.text_block_popup_menu_hidden - }; - $.contextMenu({ selector: '.text-block-context-menu', events: { @@ -584,6 +750,7 @@ ns.create_context_menus = function(is_template) { , add: { name: kivi.t8('Add text block'), icon: "add", callback: kivi.requirement_spec.standard_text_block_ajax_call } , edit: { name: kivi.t8('Edit text block'), icon: "edit", callback: kivi.requirement_spec.standard_text_block_ajax_call, disabled: kivi.requirement_spec.disable_edit_text_block_commands } , delete: { name: kivi.t8('Delete text block'), icon: "delete", callback: kivi.requirement_spec.ask_delete_text_block, disabled: kivi.requirement_spec.disable_edit_text_block_commands } + , add_picture: { name: kivi.t8('Add picture to text block'), icon: "add-picture", callback: kivi.requirement_spec.add_edit_text_block_picture_ajax_call, disabled: kivi.requirement_spec.disable_edit_text_block_commands } , sep1: "---------" , flag: { name: kivi.t8('Toggle marker'), icon: "flag", callback: kivi.requirement_spec.standard_text_block_ajax_call, disabled: kivi.requirement_spec.disable_edit_text_block_commands } , sep2: "---------" @@ -593,10 +760,20 @@ ns.create_context_menus = function(is_template) { }); $.contextMenu({ - selector: '.basic-settings-context-menu', + selector: '.text-block-picture-context-menu', + events: { + show: kivi.requirement_spec.text_block_picture_popup_menu_shown + , hide: kivi.requirement_spec.text_block_picture_popup_menu_hidden + }, items: $.extend({ - heading: { name: kivi.t8('Basic settings actions'), className: 'context-menu-heading' } - , edit: { name: kivi.t8('Edit'), icon: "edit", callback: kivi.requirement_spec.standard_basic_settings_ajax_call } + heading: { name: kivi.t8('Text block picture actions'), className: 'context-menu-heading' } + , add_picture: { name: kivi.t8('Add picture'), icon: "add-picture", callback: kivi.requirement_spec.add_edit_text_block_picture_ajax_call } + , edit_picture: { name: kivi.t8('Edit picture'), icon: "edit", callback: kivi.requirement_spec.add_edit_text_block_picture_ajax_call } + , delete_picture: { name: kivi.t8('Delete picture'), icon: "delete", callback: kivi.requirement_spec.ask_delete_text_block_picture } + , download_picture: { name: kivi.t8('Download picture'), icon: "download", callback: kivi.requirement_spec.standard_text_block_picture_ajax_call } + , sep2: "---------" + , copy_picture: { name: kivi.t8('Copy'), icon: "copy", callback: kivi.requirement_spec.standard_text_block_picture_ajax_call } + , paste_picture: { name: kivi.t8('Paste'), icon: "paste", callback: kivi.requirement_spec.standard_text_block_picture_ajax_call } }, general_actions) }); @@ -622,6 +799,7 @@ ns.create_context_menus = function(is_template) { items: $.extend({ heading: { name: kivi.t8('Time/cost estimate actions'), className: 'context-menu-heading' } , save: { name: kivi.t8('Save'), icon: "save", callback: kivi.requirement_spec.standard_time_cost_estimate_ajax_call } + , save_keep_open: { name: kivi.t8('Save and keep open'), icon: "save", callback: kivi.requirement_spec.standard_time_cost_estimate_ajax_call } , cancel: { name: kivi.t8('Cancel'), icon: "close", callback: kivi.requirement_spec.standard_time_cost_estimate_ajax_call } }, general_actions) }); @@ -671,7 +849,7 @@ ns.create_context_menus = function(is_template) { items: general_actions }); - events = { + var events = { show: kivi.requirement_spec.item_popup_menu_shown , hide: kivi.requirement_spec.item_popup_menu_hidden };