]> wagnertech.de Git - mfinanz.git/blobdiff - js/requirement_spec.js
jQuery UI: Update auf 10.1.3
[mfinanz.git] / js / requirement_spec.js
index 2d86dec899f9cdd770779afd3d8c6c97ae73edab..535c34eabeb5bbe29911b424d5bc65d03e9df9e7 100644 (file)
@@ -102,6 +102,59 @@ 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 ------------------------------
 // -------------------------------------------------------------------------
@@ -178,15 +231,6 @@ 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+)$/);
@@ -243,6 +287,20 @@ 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
+    });
+  });
+};
+
 // --------------------------------------------------------------------------------
 // ------------------------------ sections and items ------------------------------
 // --------------------------------------------------------------------------------
@@ -336,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 -------------------------------
 // -------------------------------------------------------------------------
@@ -394,7 +469,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()
@@ -660,6 +741,9 @@ ns.create_context_menus = function(is_template) {
       , 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)
   });
 
@@ -693,6 +777,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)
   });