View Issue Details

IDProjectCategoryView StatusLast Update
0009911mantisbtfeaturepublic2018-03-31 19:58
Reportergiallu Assigned Tovboctor  
PrioritynormalSeverityminorReproducibilityN/A
Status closedResolutionduplicate 
Summary0009911: Description templates
Description

A nice feature to have (BugZilla has it) is a template for the Description field.
Basically, this means the bug_report page would open with some predefined text, guiding the user to compose an useful and meaningful report (I know, wishful thinking...)

I guess this should be customizable, probably on a per-project basis.

It shouldn't be too hard to implement either...

Tagsredesign
Attached Files
description_template.patch (36,248 bytes)   
From 8e13b38a7db4efe39f8da346ecf16fe6be01ed82 Mon Sep 17 00:00:00 2001
From: Kenson Man <kenson.idv.hk@gmail.com>
Date: Sun, 2 Jun 2013 22:39:39 +0800
Subject: [PATCH 1/6] Create the related schema successfully

---
 admin/schema.php |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/admin/schema.php b/admin/schema.php
index d2b6940..ac8a1a0 100644
--- a/admin/schema.php
+++ b/admin/schema.php
@@ -198,7 +198,8 @@ $upgrade[] = Array('CreateTableSQL',Array(db_get_table('mantis_news_table'),"
 $upgrade[] = Array('CreateTableSQL',Array(db_get_table('mantis_project_category_table'),"
   project_id 		 I  UNSIGNED NOTNULL PRIMARY DEFAULT '0',
   category 		C(64) NOTNULL PRIMARY DEFAULT \" '' \",
-  user_id 		 I  UNSIGNED NOTNULL DEFAULT '0'
+  user_id 		 I  UNSIGNED NOTNULL DEFAULT '0',
+  desc_template         C(250) NOTNULL DEFAULT \" '' \"
 ",Array('mysql' => 'ENGINE=MyISAM DEFAULT CHARSET=utf8', 'pgsql' => 'WITHOUT OIDS')));
 $upgrade[] = Array('CreateTableSQL',Array(db_get_table('mantis_project_file_table'),"
   id 			 I  UNSIGNED NOTNULL PRIMARY AUTOINCREMENT,
@@ -397,7 +398,8 @@ $upgrade[] = Array( 'CreateTableSQL', Array( db_get_table( 'mantis_category_tabl
 	project_id		I		UNSIGNED NOTNULL DEFAULT '0',
 	user_id			I		UNSIGNED NOTNULL DEFAULT '0',
 	name			C(128)	NOTNULL DEFAULT \" '' \",
-	status			I		UNSIGNED NOTNULL DEFAULT '0'
+	status			I		UNSIGNED NOTNULL DEFAULT '0',
+	desc_template           C(256)  NOTNULL DEFAULT \" '' \"
 	", Array( 'mysql' => 'ENGINE=MyISAM DEFAULT CHARSET=utf8', 'pgsql' => 'WITHOUT OIDS' ) ) );
 $upgrade[] = Array( 'CreateIndexSQL', Array( 'idx_category_project_name', db_get_table( 'mantis_category_table' ), 'project_id, name', array( 'UNIQUE' ) ) );
 $upgrade[] = Array( 'InsertData', Array( db_get_table( 'mantis_category_table' ), "
-- 
1.7.10.2 (Apple Git-33)


From d7312cadf15237656e10ffc16ec2672e4e925140 Mon Sep 17 00:00:00 2001
From: Kenson Man <kenson.idv.hk@gmail.com>
Date: Sun, 2 Jun 2013 23:50:31 +0800
Subject: [PATCH 2/6] Just modify/added the template input field

---
 core/category_api.php                |   17 ++++++++++-------
 lang/strings_chinese_simplified.txt  |    1 +
 lang/strings_chinese_traditional.txt |    1 +
 lang/strings_english.txt             |    1 +
 manage_proj_cat_add.php              |    3 ++-
 manage_proj_cat_edit_page.php        |    9 +++++++++
 manage_proj_edit_page.php            |    1 +
 manage_proj_page.php                 |   11 ++++++++++-
 8 files changed, 35 insertions(+), 9 deletions(-)

diff --git a/core/category_api.php b/core/category_api.php
index e188d85..dfd6e84 100644
--- a/core/category_api.php
+++ b/core/category_api.php
@@ -105,10 +105,11 @@ function category_exists( $p_category_id ) {
  * Add a new category to the project
  * @param int $p_project_id Project id
  * @param string $p_name Category Name
+ * @param string $p_desc_template Description template
  * @return int Category ID
  * @access public
  */
- function category_add( $p_project_id, $p_name ) {
+ function category_add( $p_project_id, $p_name, $p_desc_template ) {
 	$c_project_id = db_prepare_int( $p_project_id );
 
 	if( is_blank( $p_name ) ) {
@@ -121,10 +122,10 @@ function category_exists( $p_category_id ) {
 	$t_category_table = db_get_table( 'mantis_category_table' );
 
 	$query = "INSERT INTO $t_category_table
-					( project_id, name )
+					( project_id, name, desc_template )
 				  VALUES
-					( " . db_param() . ', ' . db_param() . ' )';
-	db_query_bound( $query, array( $c_project_id, $p_name ) );
+					( " . db_param() . ', ' . db_param() . ', ' . db_param() . ' )';
+	db_query_bound( $query, array( $c_project_id, $p_name, $p_desc_template ) );
 
 	# db_query errors on failure so:
 	return db_insert_id( $t_category_table );
@@ -134,11 +135,12 @@ function category_exists( $p_category_id ) {
  * Update the name and user associated with the category
  * @param int $p_category_id Category id
  * @param string $p_name Category Name
+ * @param string $p_desc_template Description template
  * @param int $p_assigned_to User ID that category is assigned to
  * @return bool
  * @access public
  */
- function category_update( $p_category_id, $p_name, $p_assigned_to ) {
+ function category_update( $p_category_id, $p_name, $p_desc_template, $p_assigned_to ) {
 	if( is_blank( $p_name ) ) {
 		error_parameters( lang_get( 'category' ) );
 		trigger_error( ERROR_EMPTY_FIELD, ERROR );
@@ -154,9 +156,10 @@ function category_exists( $p_category_id ) {
 
 	$query = "UPDATE $t_category_table
 				  SET name=" . db_param() . ',
-					user_id=' . db_param() . '
+					user_id=' . db_param() . ',
+					desc_template=' . db_param() . '
 				  WHERE id=' . db_param();
-	db_query_bound( $query, array( $p_name, $c_assigned_to, $c_category_id ) );
+	db_query_bound( $query, array( $p_name, $c_assigned_to, $p_desc_template, $c_category_id ) );
 
 	# Add bug history entries if we update the category's name
 	if( $t_old_category['name'] != $p_name ) {
diff --git a/lang/strings_chinese_simplified.txt b/lang/strings_chinese_simplified.txt
index c4bda42..0008a67 100644
--- a/lang/strings_chinese_simplified.txt
+++ b/lang/strings_chinese_simplified.txt
@@ -516,6 +516,7 @@ $s_update_simple_link = '简易更新';
 $s_updating_bug_advanced_title = '正在更新问题信息';
 $s_id = '编号';
 $s_category = '分类';
+$s_category_desc_template = '描述模板';
 $s_severity = '严重性';
 $s_reproducibility = '出现频率';
 $s_date_submitted = '报告日期';
diff --git a/lang/strings_chinese_traditional.txt b/lang/strings_chinese_traditional.txt
index 2bf02e6..6ce0417 100644
--- a/lang/strings_chinese_traditional.txt
+++ b/lang/strings_chinese_traditional.txt
@@ -509,6 +509,7 @@ $s_update_simple_link = '簡易更新';
 $s_updating_bug_advanced_title = '更新問題資訊';
 $s_id = '編號';
 $s_category = '類別';
+$s_category_desc_template='描述模板'
 $s_severity = '嚴重性';
 $s_reproducibility = '出現頻率';
 $s_date_submitted = '回報日期';
diff --git a/lang/strings_english.txt b/lang/strings_english.txt
index c14081b..3215386 100644
--- a/lang/strings_english.txt
+++ b/lang/strings_english.txt
@@ -634,6 +634,7 @@ $s_steps_to_reproduce = 'Steps To Reproduce';
 $s_update_information_button = 'Update Information';
 $s_sticky_issue = 'Sticky Issue';
 $s_profile = 'Profile';
+$s_category_desc_template = 'Description Template';
 
 # bug_update_page.php
 $s_updating_bug_simple_title = 'Updating Issue Information';
diff --git a/manage_proj_cat_add.php b/manage_proj_cat_add.php
index 455651b..c900656 100644
--- a/manage_proj_cat_add.php
+++ b/manage_proj_cat_add.php
@@ -33,6 +33,7 @@
 
 	$f_project_id	= gpc_get_int( 'project_id' );
 	$f_name			= gpc_get_string( 'name' );
+	$f_desc_template = gpc_get_string('desc_template');
 
 	access_ensure_project_level( config_get( 'manage_project_threshold' ), $f_project_id );
 
@@ -51,7 +52,7 @@
 
 		$t_name = trim( $t_name );
 		if ( category_is_unique( $f_project_id, $t_name ) ) {
-			category_add( $f_project_id, $t_name );
+			category_add( $f_project_id, $t_name, $f_desc_template );
 		} else if ( 1 == $t_category_count ) {
 			# We only error out on duplicates when a single value was
 			#  given.  If multiple values were given, we just add the
diff --git a/manage_proj_cat_edit_page.php b/manage_proj_cat_edit_page.php
index 08b320e..1a761bb 100644
--- a/manage_proj_cat_edit_page.php
+++ b/manage_proj_cat_edit_page.php
@@ -36,6 +36,7 @@
 	$t_assigned_to = $t_row['user_id'];
 	$t_project_id = $t_row['project_id'];
 	$t_name = $t_row['name'];
+	$t_desc_template = $t_row['desc_template'];
 
 	access_ensure_project_level( config_get( 'manage_project_threshold' ), $t_project_id );
 
@@ -66,6 +67,14 @@
 </tr>
 <tr <?php echo helper_alternate_class() ?>>
 	<td class="category">
+		<?php echo lang_get( 'category_desc_template' ) ?>
+	</td>
+	<td>
+		<textarea name="desc_template" row="3" cols="20"><?php echo string_attribute( $t_desc_template ) ?></textarea>
+	</td>
+</tr>
+<tr <?php echo helper_alternate_class() ?>>
+	<td class="category">
 		<?php echo lang_get( 'assigned_to' ) ?>
 	</td>
 	<td>
diff --git a/manage_proj_edit_page.php b/manage_proj_edit_page.php
index fd23a15..acd8b41 100644
--- a/manage_proj_edit_page.php
+++ b/manage_proj_edit_page.php
@@ -379,6 +379,7 @@ if ( access_has_global_level ( config_get( 'delete_project_threshold' ) ) ) { ?>
 			<?php echo form_security_field( 'manage_proj_cat_add' ) ?>
 			<input type="hidden" name="project_id" value="<?php echo $f_project_id ?>" />
 			<input type="text" name="name" size="32" maxlength="128" />
+			<textarea name="desc_template" row="3" cols="20"></textarea>
 			<input type="submit" class="button" value="<?php echo lang_get( 'add_category_button' ) ?>" />
 		</form>
 	</td>
diff --git a/manage_proj_page.php b/manage_proj_page.php
index dd333e8..7468d2a 100644
--- a/manage_proj_page.php
+++ b/manage_proj_page.php
@@ -221,7 +221,16 @@
 		<form method="post" action="manage_proj_cat_add.php">
 			<?php echo form_security_field( 'manage_proj_cat_add' ) ?>
 			<input type="hidden" name="project_id" value="<?php echo ALL_PROJECTS ?>" />
-			<input type="text" name="name" size="32" maxlength="128" />
+			<div style="vertical-align:top">
+				<div style="display:inline-block; vertical-align:top">
+					<div><?php echo lang_get ('category') ?></div>
+					<input type="text" name="name" size="32" maxlength="128" />
+				</div>
+				<div style="display:inline-block; vertical-align:top">
+					<div><?php echo lang_get ('category_desc_template') ?></div>
+					<textarea rows="3" cols="32" name="desc_template"></textarea>
+				</div>
+			</div>
 			<input type="submit" class="button" value="<?php echo lang_get( 'add_category_button' ) ?>" />
 		</form>
 	</td>
-- 
1.7.10.2 (Apple Git-33)


From f6e6cd9824e6e18e43156f353417029df13e54d4 Mon Sep 17 00:00:00 2001
From: Kenson Man <kenson.idv.hk@gmail.com>
Date: Mon, 3 Jun 2013 16:23:25 +0800
Subject: [PATCH 3/6] Alter the manipulation api of category, and also update
 the layout

---
 api/soap/mc_project_api.php |    3 ++-
 core/category_api.php       |   23 +++++++++++++++++++++++
 manage_proj_cat_update.php  |    3 ++-
 3 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/api/soap/mc_project_api.php b/api/soap/mc_project_api.php
index 6dd29f5..bd61315 100644
--- a/api/soap/mc_project_api.php
+++ b/api/soap/mc_project_api.php
@@ -272,9 +272,10 @@ function mc_project_rename_category_by_name( $p_username, $p_password, $p_projec
 
         // find the id of the category
         $p_category_id = category_get_id_by_name( $p_category_name, $p_project_id );
+	$p_desc_template = category_get_field( $p_category_id, 'desc_template');
 
         // update the category
-        return category_update( $p_category_id, $p_category_name_new, $p_assigned_to );
+        return category_update( $p_category_id, $p_category_name_new, $p_desc_template, $p_assigned_to );
 }
 
 /**
diff --git a/core/category_api.php b/core/category_api.php
index dfd6e84..85f6e96 100644
--- a/core/category_api.php
+++ b/core/category_api.php
@@ -610,3 +610,26 @@ function category_full_name( $p_category_id, $p_show_project = true, $p_current_
 		return $t_row['name'];
 	}
 }
+
+/**
+ * Retrieve the desc_template according to the category-id
+ */
+function category_get_desc_template_by_id( $p_category_name, $p_project_id, $p_trigger_errors = true ){ 
+	$t_category_table = db_get_table( 'mantis_category_table' );
+	$t_project_name = project_get_name( $p_project_id );
+
+	$t_query = "SELECT desc_template FROM $t_category_table
+				WHERE name=" . db_param() . " AND project_id=" . db_param();
+	$t_result = db_query_bound( $t_query, array( $p_category_name, (int) $p_project_id ) );
+	$t_count = db_num_rows( $t_result );
+	if( 1 > $t_count ) {
+		if( $p_trigger_errors ) {
+			error_parameters( $p_category_name, $t_project_name );
+			trigger_error( ERROR_CATEGORY_NOT_FOUND_FOR_PROJECT, ERROR );
+		} else {
+			return false;
+		}
+	}
+
+	return db_result( $t_result );
+}
diff --git a/manage_proj_cat_update.php b/manage_proj_cat_update.php
index 7d80b9e..7421ebe 100644
--- a/manage_proj_cat_update.php
+++ b/manage_proj_cat_update.php
@@ -35,6 +35,7 @@
 	$f_project_id		= gpc_get_int( 'project_id', ALL_PROJECTS );
 	$f_name				= trim( gpc_get_string( 'name' ) );
 	$f_assigned_to		= gpc_get_int( 'assigned_to', 0 );
+	$f_desc_template        = trim(gpc_get_string('desc_template'));
 
 	access_ensure_project_level( config_get( 'manage_project_threshold' ), $f_project_id );
 
@@ -51,7 +52,7 @@
 		category_ensure_unique( $t_project_id, $f_name );
 	}
 
-	category_update( $f_category_id, $f_name, $f_assigned_to );
+	category_update( $f_category_id, $f_name, $f_desc_template, $f_assigned_to );
 
 	form_security_purge( 'manage_proj_cat_update' );
 
-- 
1.7.10.2 (Apple Git-33)


From c3f44f3233f3e80b13c06f7d00daaf9d236f9c09 Mon Sep 17 00:00:00 2001
From: Kenson Man <kenson.idv.hk@gmail.com>
Date: Mon, 3 Jun 2013 17:35:42 +0800
Subject: [PATCH 4/6] Add the javascript for the desc-template

---
 bug_report_page.php |   14 ++++++++++++--
 core/print_api.php  |   20 ++++++++++++++++++++
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/bug_report_page.php b/bug_report_page.php
index f7cfdff..b1622da 100644
--- a/bug_report_page.php
+++ b/bug_report_page.php
@@ -197,7 +197,7 @@
 			<?php if ( $t_changed_project ) {
 				echo "[" . project_get_field( $t_bug->project_id, 'name' ) . "] ";
 			} ?>
-			<select <?php echo helper_get_tab_index() ?> name="category_id">
+			<select <?php echo helper_get_tab_index() ?> id="categoryIdFld" name="category_id" onchange="category_id_changed(this.options.selectedIndex)">
 				<?php
 					print_category_option_list( $f_category_id );
 				?>
@@ -480,7 +480,8 @@
 			<span class="required">*</span><?php print_documentation_link( 'description' ) ?>
 		</td>
 		<td>
-			<textarea <?php echo helper_get_tab_index() ?> name="description" cols="80" rows="10"><?php echo string_textarea( $f_description ) ?></textarea>
+			<textarea id="descTemplateTextArea" <?php echo helper_get_tab_index() ?> name="description" cols="80" rows="10"><?php echo string_textarea( $f_description ) ?></textarea>
+			<?php print_category_desc_templates($t_project_id) ?>
 		</td>
 	</tr>
 
@@ -623,6 +624,15 @@
 	window.document.report_bug_form.category_id.focus();
 -->
 </script>
+<!-- desc-template -->
+<script type="text/javascript" language="JavaScript"><!--
+	var category_id_changed=function( int_selectedIndex ){
+		if(int_selectedIndex<1)return;
+		var str_selectedValue=document.getElementById('categoryIdFld').options[int_selectedIndex].value;
+		var str_descTemplate=document.getElementById("desc_template_for_category_"+str_selectedValue).innerHTML;
+		document.getElementById('descTemplateTextArea').value=str_descTemplate;
+	};
+//--></script>
 <?php  }
 if ( $tpl_show_due_date ) {
 	date_finish_calendar( 'due_date', 'trigger' );
diff --git a/core/print_api.php b/core/print_api.php
index 6a36002..1903b29 100644
--- a/core/print_api.php
+++ b/core/print_api.php
@@ -718,6 +718,26 @@ function print_category_option_list( $p_category_id = 0, $p_project_id = null )
 }
 
 /**
+ *  Print all available category's desc-template into the invisible <div>. 
+ *  It will be used when the category field has been changed, the description content will be replaced by the text of those <div> tag.
+ *  @param p_project_id int The project id
+ */
+function print_category_desc_templates ($p_project_id = null){
+	if( null === $p_project_id ) {
+		$t_project_id = helper_get_current_project();
+	} else {
+		$t_project_id = $p_project_id;
+	}
+	$cat_arr = category_get_all_rows( $t_project_id, null, true );
+
+	foreach( $cat_arr as $t_category_row ) {
+		$t_category_id = $t_category_row['id'];
+		echo "<div id=\"desc_template_for_category_$t_category_id\" style=\"display:none\">";
+		echo $t_category_row['desc_template'] . '</div>';
+	}
+}
+
+/**
  *	Now that categories are identified by numerical ID, we need an old-style name
  *	based option list to keep existing filter functionality.
  *	@param string $p_category_name The selected category
-- 
1.7.10.2 (Apple Git-33)


From 645604df4f32be6e84ffd9f8731c7d7a909e23df Mon Sep 17 00:00:00 2001
From: Kenson Man <kenson.idv.hk@gmail.com>
Date: Mon, 3 Jun 2013 18:07:08 +0800
Subject: [PATCH 5/6] Configuration support for "use_desc_template"

---
 bug_report_page.php           |    5 +++--
 manage_proj_cat_edit_page.php |    3 ++-
 manage_proj_page.php          |    5 ++++-
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/bug_report_page.php b/bug_report_page.php
index b1622da..dab9f6b 100644
--- a/bug_report_page.php
+++ b/bug_report_page.php
@@ -481,7 +481,7 @@
 		</td>
 		<td>
 			<textarea id="descTemplateTextArea" <?php echo helper_get_tab_index() ?> name="description" cols="80" rows="10"><?php echo string_textarea( $f_description ) ?></textarea>
-			<?php print_category_desc_templates($t_project_id) ?>
+			<?php if( ON == config_get( 'use_desc_template', ON)) print_category_desc_templates($t_project_id) ?>
 		</td>
 	</tr>
 
@@ -625,6 +625,7 @@
 -->
 </script>
 <!-- desc-template -->
+<?php if ( ON == config_get( 'use_desc_template', ON ) ) { ?>
 <script type="text/javascript" language="JavaScript"><!--
 	var category_id_changed=function( int_selectedIndex ){
 		if(int_selectedIndex<1)return;
@@ -633,7 +634,7 @@
 		document.getElementById('descTemplateTextArea').value=str_descTemplate;
 	};
 //--></script>
-<?php  }
+<?php  }}
 if ( $tpl_show_due_date ) {
 	date_finish_calendar( 'due_date', 'trigger' );
 }
diff --git a/manage_proj_cat_edit_page.php b/manage_proj_cat_edit_page.php
index 1a761bb..fa299f0 100644
--- a/manage_proj_cat_edit_page.php
+++ b/manage_proj_cat_edit_page.php
@@ -65,6 +65,7 @@
 		<input type="text" name="name" size="32" maxlength="128" value="<?php echo string_attribute( $t_name ) ?>" />
 	</td>
 </tr>
+<?php if( ON==config_get('use_desc_template', ON)) {?>
 <tr <?php echo helper_alternate_class() ?>>
 	<td class="category">
 		<?php echo lang_get( 'category_desc_template' ) ?>
@@ -72,7 +73,7 @@
 	<td>
 		<textarea name="desc_template" row="3" cols="20"><?php echo string_attribute( $t_desc_template ) ?></textarea>
 	</td>
-</tr>
+</tr><?php } ?>
 <tr <?php echo helper_alternate_class() ?>>
 	<td class="category">
 		<?php echo lang_get( 'assigned_to' ) ?>
diff --git a/manage_proj_page.php b/manage_proj_page.php
index 7468d2a..cae8822 100644
--- a/manage_proj_page.php
+++ b/manage_proj_page.php
@@ -223,13 +223,16 @@
 			<input type="hidden" name="project_id" value="<?php echo ALL_PROJECTS ?>" />
 			<div style="vertical-align:top">
 				<div style="display:inline-block; vertical-align:top">
-					<div><?php echo lang_get ('category') ?></div>
+					<?php if( ON == config_get( 'use_desc_template', ON ) ) ?>
+						<div><?php echo lang_get('category') ?></div>
 					<input type="text" name="name" size="32" maxlength="128" />
 				</div>
+				<?php if ( ON == config_get( 'use_desc_template', ON ) ) { ?>
 				<div style="display:inline-block; vertical-align:top">
 					<div><?php echo lang_get ('category_desc_template') ?></div>
 					<textarea rows="3" cols="32" name="desc_template"></textarea>
 				</div>
+				<?php } ?>
 			</div>
 			<input type="submit" class="button" value="<?php echo lang_get( 'add_category_button' ) ?>" />
 		</form>
-- 
1.7.10.2 (Apple Git-33)


From a96c885308d3fba00a482a97627812ad5261666e Mon Sep 17 00:00:00 2001
From: Kenson Man <kenson.idv.hk@gmail.com>
Date: Mon, 3 Jun 2013 22:08:52 +0800
Subject: [PATCH 6/6] Addiontal Information Template support

---
 admin/schema.php                     |    6 +++--
 api/soap/mc_project_api.php          |    3 ++-
 bug_report_page.php                  |   18 ++++++++++-----
 core/category_api.php                |   40 ++++++++++++++++++++++++++++------
 core/print_api.php                   |   20 +++++++++++++++++
 lang/strings_chinese_simplified.txt  |    1 +
 lang/strings_chinese_traditional.txt |    3 ++-
 lang/strings_english.txt             |    1 +
 manage_proj_cat_add.php              |    3 ++-
 manage_proj_cat_edit_page.php        |   10 +++++++++
 manage_proj_cat_update.php           |    3 ++-
 manage_proj_edit_page.php            |    3 ++-
 manage_proj_page.php                 |    9 +++++++-
 13 files changed, 100 insertions(+), 20 deletions(-)

diff --git a/admin/schema.php b/admin/schema.php
index ac8a1a0..ede823b 100644
--- a/admin/schema.php
+++ b/admin/schema.php
@@ -199,7 +199,8 @@ $upgrade[] = Array('CreateTableSQL',Array(db_get_table('mantis_project_category_
   project_id 		 I  UNSIGNED NOTNULL PRIMARY DEFAULT '0',
   category 		C(64) NOTNULL PRIMARY DEFAULT \" '' \",
   user_id 		 I  UNSIGNED NOTNULL DEFAULT '0',
-  desc_template         C(250) NOTNULL DEFAULT \" '' \"
+  desc_template         C(250) NOTNULL DEFAULT \" '' \",
+  addi_template         C(250) NOTNULL DEFAULT \" '' \"
 ",Array('mysql' => 'ENGINE=MyISAM DEFAULT CHARSET=utf8', 'pgsql' => 'WITHOUT OIDS')));
 $upgrade[] = Array('CreateTableSQL',Array(db_get_table('mantis_project_file_table'),"
   id 			 I  UNSIGNED NOTNULL PRIMARY AUTOINCREMENT,
@@ -399,7 +400,8 @@ $upgrade[] = Array( 'CreateTableSQL', Array( db_get_table( 'mantis_category_tabl
 	user_id			I		UNSIGNED NOTNULL DEFAULT '0',
 	name			C(128)	NOTNULL DEFAULT \" '' \",
 	status			I		UNSIGNED NOTNULL DEFAULT '0',
-	desc_template           C(256)  NOTNULL DEFAULT \" '' \"
+	desc_template           C(256)  NOTNULL DEFAULT \" '' \",
+	addi_template           C(256)  NOTNULL DEFAULT \" '' \"
 	", Array( 'mysql' => 'ENGINE=MyISAM DEFAULT CHARSET=utf8', 'pgsql' => 'WITHOUT OIDS' ) ) );
 $upgrade[] = Array( 'CreateIndexSQL', Array( 'idx_category_project_name', db_get_table( 'mantis_category_table' ), 'project_id, name', array( 'UNIQUE' ) ) );
 $upgrade[] = Array( 'InsertData', Array( db_get_table( 'mantis_category_table' ), "
diff --git a/api/soap/mc_project_api.php b/api/soap/mc_project_api.php
index bd61315..53fc406 100644
--- a/api/soap/mc_project_api.php
+++ b/api/soap/mc_project_api.php
@@ -273,9 +273,10 @@ function mc_project_rename_category_by_name( $p_username, $p_password, $p_projec
         // find the id of the category
         $p_category_id = category_get_id_by_name( $p_category_name, $p_project_id );
 	$p_desc_template = category_get_field( $p_category_id, 'desc_template');
+	$p_addi_template = category_get_field( $p_category_id, 'addi_template');
 
         // update the category
-        return category_update( $p_category_id, $p_category_name_new, $p_desc_template, $p_assigned_to );
+        return category_update( $p_category_id, $p_category_name_new, $p_desc_template, $p_addi_template, $p_assigned_to );
 }
 
 /**
diff --git a/bug_report_page.php b/bug_report_page.php
index dab9f6b..eeef6a7 100644
--- a/bug_report_page.php
+++ b/bug_report_page.php
@@ -502,7 +502,8 @@
 			<?php print_documentation_link( 'additional_information' ) ?>
 		</td>
 		<td>
-			<textarea <?php echo helper_get_tab_index() ?> name="additional_info" cols="80" rows="10"><?php echo string_textarea( $f_additional_info ) ?></textarea>
+			<textarea id="addiTemplateTextArea" <?php echo helper_get_tab_index() ?> name="additional_info" cols="80" rows="10"><?php echo string_textarea( $f_additional_info ) ?></textarea>
+			<?php if( ON == config_get( 'use_addi_template', ON)) print_category_addi_templates($t_project_id) ?>
 		</td>
 	</tr>
 <?php
@@ -625,16 +626,23 @@
 -->
 </script>
 <!-- desc-template -->
-<?php if ( ON == config_get( 'use_desc_template', ON ) ) { ?>
+<?php if ( (ON==config_get( 'use_desc_template', ON )) or (ON==config_get('use_addi_template', ON))) { ?>
 <script type="text/javascript" language="JavaScript"><!--
 	var category_id_changed=function( int_selectedIndex ){
 		if(int_selectedIndex<1)return;
 		var str_selectedValue=document.getElementById('categoryIdFld').options[int_selectedIndex].value;
+		//desc-template <?php if(ON==config_get('use_desc_template', ON)){ echo "\n"; ?>
 		var str_descTemplate=document.getElementById("desc_template_for_category_"+str_selectedValue).innerHTML;
-		document.getElementById('descTemplateTextArea').value=str_descTemplate;
+		document.getElementById('descTemplateTextArea').value=str_descTemplate;	
+		//end<?php } ?> 
+		//addi-template <?php if(ON==config_get('use_addi_template', ON)){ echo "\n"; ?>
+		var str_addiTemplate=document.getElementById("addi_template_for_category_"+str_selectedValue).innerHTML;
+		document.getElementById('addiTemplateTextArea').value=str_addiTemplate;	
+		//end<?php } ?>
+
 	};
-//--></script>
-<?php  }}
+//--></script> <?php } ?>
+<?php  }
 if ( $tpl_show_due_date ) {
 	date_finish_calendar( 'due_date', 'trigger' );
 }
diff --git a/core/category_api.php b/core/category_api.php
index 85f6e96..d924789 100644
--- a/core/category_api.php
+++ b/core/category_api.php
@@ -106,10 +106,11 @@ function category_exists( $p_category_id ) {
  * @param int $p_project_id Project id
  * @param string $p_name Category Name
  * @param string $p_desc_template Description template
+ * @param string $p_addi_template Additional Information template
  * @return int Category ID
  * @access public
  */
- function category_add( $p_project_id, $p_name, $p_desc_template ) {
+ function category_add( $p_project_id, $p_name, $p_desc_template, $p_addi_template ) {
 	$c_project_id = db_prepare_int( $p_project_id );
 
 	if( is_blank( $p_name ) ) {
@@ -122,10 +123,10 @@ function category_exists( $p_category_id ) {
 	$t_category_table = db_get_table( 'mantis_category_table' );
 
 	$query = "INSERT INTO $t_category_table
-					( project_id, name, desc_template )
+					( project_id, name, desc_template, addi_template )
 				  VALUES
-					( " . db_param() . ', ' . db_param() . ', ' . db_param() . ' )';
-	db_query_bound( $query, array( $c_project_id, $p_name, $p_desc_template ) );
+					( " . db_param() . ', ' . db_param() . ', ' . db_param() . ', ' . db_param() . ' )';
+	db_query_bound( $query, array( $c_project_id, $p_name, $p_desc_template, $p_addi_template ) );
 
 	# db_query errors on failure so:
 	return db_insert_id( $t_category_table );
@@ -136,11 +137,12 @@ function category_exists( $p_category_id ) {
  * @param int $p_category_id Category id
  * @param string $p_name Category Name
  * @param string $p_desc_template Description template
+ * @param string $p_addi_template Additional Information Template
  * @param int $p_assigned_to User ID that category is assigned to
  * @return bool
  * @access public
  */
- function category_update( $p_category_id, $p_name, $p_desc_template, $p_assigned_to ) {
+ function category_update( $p_category_id, $p_name, $p_desc_template, $p_addi_template, $p_assigned_to ) {
 	if( is_blank( $p_name ) ) {
 		error_parameters( lang_get( 'category' ) );
 		trigger_error( ERROR_EMPTY_FIELD, ERROR );
@@ -157,9 +159,10 @@ function category_exists( $p_category_id ) {
 	$query = "UPDATE $t_category_table
 				  SET name=" . db_param() . ',
 					user_id=' . db_param() . ',
-					desc_template=' . db_param() . '
+					desc_template=' . db_param() . ',
+					addi_template=' . db_param() . '
 				  WHERE id=' . db_param();
-	db_query_bound( $query, array( $p_name, $c_assigned_to, $p_desc_template, $c_category_id ) );
+	db_query_bound( $query, array( $p_name, $c_assigned_to, $p_desc_template, $p_addi_template, $c_category_id ) );
 
 	# Add bug history entries if we update the category's name
 	if( $t_old_category['name'] != $p_name ) {
@@ -633,3 +636,26 @@ function category_get_desc_template_by_id( $p_category_name, $p_project_id, $p_t
 
 	return db_result( $t_result );
 }
+
+/**
+ * Retrieve the addi_template according to the category-id
+ */
+function category_get_addi_template_by_id( $p_category_name, $p_project_id, $p_trigger_errors = true ){ 
+	$t_category_table = db_get_table( 'mantis_category_table' );
+	$t_project_name = project_get_name( $p_project_id );
+
+	$t_query = "SELECT addi_template FROM $t_category_table
+				WHERE name=" . db_param() . " AND project_id=" . db_param();
+	$t_result = db_query_bound( $t_query, array( $p_category_name, (int) $p_project_id ) );
+	$t_count = db_num_rows( $t_result );
+	if( 1 > $t_count ) {
+		if( $p_trigger_errors ) {
+			error_parameters( $p_category_name, $t_project_name );
+			trigger_error( ERROR_CATEGORY_NOT_FOUND_FOR_PROJECT, ERROR );
+		} else {
+			return false;
+		}
+	}
+
+	return db_result( $t_result );
+}
diff --git a/core/print_api.php b/core/print_api.php
index 1903b29..762173c 100644
--- a/core/print_api.php
+++ b/core/print_api.php
@@ -738,6 +738,26 @@ function print_category_desc_templates ($p_project_id = null){
 }
 
 /**
+ *  Print all available category's additional-information-template into the invisible <div>. 
+ *  It will be used when the category field has been changed, the addiription content will be replaced by the text of those <div> tag.
+ *  @param p_project_id int The project id
+ */
+function print_category_addi_templates ($p_project_id = null){
+	if( null === $p_project_id ) {
+		$t_project_id = helper_get_current_project();
+	} else {
+		$t_project_id = $p_project_id;
+	}
+	$cat_arr = category_get_all_rows( $t_project_id, null, true );
+
+	foreach( $cat_arr as $t_category_row ) {
+		$t_category_id = $t_category_row['id'];
+		echo "<div id=\"addi_template_for_category_$t_category_id\" style=\"display:none\">";
+		echo $t_category_row['addi_template'] . '</div>';
+	}
+}
+
+/**
  *	Now that categories are identified by numerical ID, we need an old-style name
  *	based option list to keep existing filter functionality.
  *	@param string $p_category_name The selected category
diff --git a/lang/strings_chinese_simplified.txt b/lang/strings_chinese_simplified.txt
index 0008a67..f3213c5 100644
--- a/lang/strings_chinese_simplified.txt
+++ b/lang/strings_chinese_simplified.txt
@@ -517,6 +517,7 @@ $s_updating_bug_advanced_title = '正在更新问题信息';
 $s_id = '编号';
 $s_category = '分类';
 $s_category_desc_template = '描述模板';
+$s_category_addi_template = '附注模板';
 $s_severity = '严重性';
 $s_reproducibility = '出现频率';
 $s_date_submitted = '报告日期';
diff --git a/lang/strings_chinese_traditional.txt b/lang/strings_chinese_traditional.txt
index 6ce0417..94cb489 100644
--- a/lang/strings_chinese_traditional.txt
+++ b/lang/strings_chinese_traditional.txt
@@ -509,7 +509,8 @@ $s_update_simple_link = '簡易更新';
 $s_updating_bug_advanced_title = '更新問題資訊';
 $s_id = '編號';
 $s_category = '類別';
-$s_category_desc_template='描述模板'
+$s_category_desc_template='描述模板';
+$s_category_addi_template='附註模板';
 $s_severity = '嚴重性';
 $s_reproducibility = '出現頻率';
 $s_date_submitted = '回報日期';
diff --git a/lang/strings_english.txt b/lang/strings_english.txt
index 3215386..2ac6d91 100644
--- a/lang/strings_english.txt
+++ b/lang/strings_english.txt
@@ -635,6 +635,7 @@ $s_update_information_button = 'Update Information';
 $s_sticky_issue = 'Sticky Issue';
 $s_profile = 'Profile';
 $s_category_desc_template = 'Description Template';
+$s_category_addi_template = 'Additional Information Template';
 
 # bug_update_page.php
 $s_updating_bug_simple_title = 'Updating Issue Information';
diff --git a/manage_proj_cat_add.php b/manage_proj_cat_add.php
index c900656..d170ddc 100644
--- a/manage_proj_cat_add.php
+++ b/manage_proj_cat_add.php
@@ -34,6 +34,7 @@
 	$f_project_id	= gpc_get_int( 'project_id' );
 	$f_name			= gpc_get_string( 'name' );
 	$f_desc_template = gpc_get_string('desc_template');
+	$f_addi_template = gpc_get_string('addi_template');
 
 	access_ensure_project_level( config_get( 'manage_project_threshold' ), $f_project_id );
 
@@ -52,7 +53,7 @@
 
 		$t_name = trim( $t_name );
 		if ( category_is_unique( $f_project_id, $t_name ) ) {
-			category_add( $f_project_id, $t_name, $f_desc_template );
+			category_add( $f_project_id, $t_name, $f_desc_template, $f_addi_template );
 		} else if ( 1 == $t_category_count ) {
 			# We only error out on duplicates when a single value was
 			#  given.  If multiple values were given, we just add the
diff --git a/manage_proj_cat_edit_page.php b/manage_proj_cat_edit_page.php
index fa299f0..1d8827d 100644
--- a/manage_proj_cat_edit_page.php
+++ b/manage_proj_cat_edit_page.php
@@ -37,6 +37,7 @@
 	$t_project_id = $t_row['project_id'];
 	$t_name = $t_row['name'];
 	$t_desc_template = $t_row['desc_template'];
+	$t_addi_template = $t_row['addi_template'];
 
 	access_ensure_project_level( config_get( 'manage_project_threshold' ), $t_project_id );
 
@@ -74,6 +75,15 @@
 		<textarea name="desc_template" row="3" cols="20"><?php echo string_attribute( $t_desc_template ) ?></textarea>
 	</td>
 </tr><?php } ?>
+<?php if( ON==config_get('use_addi_template', ON)) {?>
+<tr <?php echo helper_alternate_class() ?>>
+	<td class="category">
+		<?php echo lang_get( 'category_addi_template' ) ?>
+	</td>
+	<td>
+		<textarea name="addi_template" row="3" cols="20"><?php echo string_attribute( $t_addi_template ) ?></textarea>
+	</td>
+</tr><?php } ?>
 <tr <?php echo helper_alternate_class() ?>>
 	<td class="category">
 		<?php echo lang_get( 'assigned_to' ) ?>
diff --git a/manage_proj_cat_update.php b/manage_proj_cat_update.php
index 7421ebe..54d2bbe 100644
--- a/manage_proj_cat_update.php
+++ b/manage_proj_cat_update.php
@@ -36,6 +36,7 @@
 	$f_name				= trim( gpc_get_string( 'name' ) );
 	$f_assigned_to		= gpc_get_int( 'assigned_to', 0 );
 	$f_desc_template        = trim(gpc_get_string('desc_template'));
+	$f_addi_template        = trim(gpc_get_string('addi_template'));
 
 	access_ensure_project_level( config_get( 'manage_project_threshold' ), $f_project_id );
 
@@ -52,7 +53,7 @@
 		category_ensure_unique( $t_project_id, $f_name );
 	}
 
-	category_update( $f_category_id, $f_name, $f_desc_template, $f_assigned_to );
+	category_update( $f_category_id, $f_name, $f_desc_template, $f_addi_template, $f_assigned_to );
 
 	form_security_purge( 'manage_proj_cat_update' );
 
diff --git a/manage_proj_edit_page.php b/manage_proj_edit_page.php
index acd8b41..191bc9a 100644
--- a/manage_proj_edit_page.php
+++ b/manage_proj_edit_page.php
@@ -379,7 +379,8 @@ if ( access_has_global_level ( config_get( 'delete_project_threshold' ) ) ) { ?>
 			<?php echo form_security_field( 'manage_proj_cat_add' ) ?>
 			<input type="hidden" name="project_id" value="<?php echo $f_project_id ?>" />
 			<input type="text" name="name" size="32" maxlength="128" />
-			<textarea name="desc_template" row="3" cols="20"></textarea>
+			<?php if( ON==config_get('use_desc_template', ON)) {?><textarea name="desc_template" row="3" cols="20"></textarea><?php } ?>
+			<?php if( ON==config_get('use_addi_template', ON)) {?><textarea name="addi_template" row="3" cols="20"></textarea><?php } ?>
 			<input type="submit" class="button" value="<?php echo lang_get( 'add_category_button' ) ?>" />
 		</form>
 	</td>
diff --git a/manage_proj_page.php b/manage_proj_page.php
index cae8822..83ec6c5 100644
--- a/manage_proj_page.php
+++ b/manage_proj_page.php
@@ -223,8 +223,9 @@
 			<input type="hidden" name="project_id" value="<?php echo ALL_PROJECTS ?>" />
 			<div style="vertical-align:top">
 				<div style="display:inline-block; vertical-align:top">
-					<?php if( ON == config_get( 'use_desc_template', ON ) ) ?>
+					<?php if((ON==config_get('use_desc_template', ON)) or (ON==config_get('use_addi_template', ON))){ ?>
 						<div><?php echo lang_get('category') ?></div>
+					<?php } ?>
 					<input type="text" name="name" size="32" maxlength="128" />
 				</div>
 				<?php if ( ON == config_get( 'use_desc_template', ON ) ) { ?>
@@ -233,6 +234,12 @@
 					<textarea rows="3" cols="32" name="desc_template"></textarea>
 				</div>
 				<?php } ?>
+				<?php if ( ON == config_get( 'use_addi_template', ON ) ) { ?>
+				<div style="display:inline-block; vertical-align:top">
+					<div><?php echo lang_get ('category_addi_template') ?></div>
+					<textarea rows="3" cols="32" name="addi_template"></textarea>
+				</div>
+				<?php } ?>
 			</div>
 			<input type="submit" class="button" value="<?php echo lang_get( 'add_category_button' ) ?>" />
 		</form>
-- 
1.7.10.2 (Apple Git-33)

description_template.patch (36,248 bytes)   

Relationships

duplicate of 0024158 closedvboctor Support providing a default value for issue description 

Activities

yudi_set

yudi_set

2009-08-13 04:19

reporter   ~0022718

Hi,
Any update on this issue?

It would be great if we can have this feature.
Thank you.

dhx

dhx

2009-08-13 06:08

reporter   ~0022719

I disagree with this feature on the basis that the description field should not be a form that users fill out. In most cases you'd want to maintain the orthogonality of information provided by the user, which is why MantisBT offers custom fields (and plenty of built-in ones too). I know we don't have a full length text custom field yet, but that is something we can add without a huge amount of effort (I think).

I'd be happy with an optional bit of information that is shown at the top of the bug reporting page to inform users of what they should do, how to fill in a good bug report, etc. But I don't think the description field should be filled with a template when reporting a bug... that is what fields are for.

yudi_set

yudi_set

2009-08-13 11:37

reporter   ~0022720

That would be a good idea.

But please let me explain a little bit.
At my workplace, we are currently using Mantis more as a helpdesk support system.
We used it for bugtracking, problem support and also to handle user request for setup.

So, for example the users may select 'New Email Account Request' from the category, then they would have to fill in certain details (name, preferred email address, role, department, etc) so that the admin can setup the email account requested.
It will make more sense, if we can provide the required items in the Description field and then the user can follow along to fill it.

So, the Description field would be opened with something like this:
New Email Account Request

Name:
Preferred email address:
Department:
Role:

And then the user can fill in the necessary details without have to go back & forth between the user & the administrator (to remind the user just to fill in the details).

Yes, we can use the the custom field.
But we have only one project (like the current setting on this bugtracker),and many issues are not related to new email account request.
Thus, will make this custom not too effective as a solution.

Hope my explaination can help to convey the reason behind the request.
Thank you.

giallu

giallu

2009-08-14 03:47

reporter   ~0022723

As yudi_set shown, there are plenty of use cases for this feature; basically, each time you need some loosely structured info from a user you can guide him with some specific text.

to yudi_set: the status of this is that someone need to sit down and implement the feature... have you got some spare time? :P

yudi_set

yudi_set

2009-08-14 11:12

reporter   ~0022732

Hi giallu,

What an honour :-)
But I'm a newbie to PHP.
Not very sure if I'm up for this kind of task.

But I'm willing to learn.
Can point me where to start?

I just found AutoFill plugin (http://deboutv.free.fr/mantis/plugin.php?plugin=AutoFill).
But it doesn't fill the Description field.
Instead it adds a note with the predefined text.

Thank you.

kensonman

kensonman

2013-06-03 11:39

reporter   ~0037044

Hi all,

I had implemented the related features (description-template and additional-information-template). The patch is attached.

This is the first time I attent the development on open-source project, if there have anything I missed, please kindly to let me know. Thanks.

It will be great if you can let me know when my patch is merged into the master development branch.

Thanks you.

anayrat

anayrat

2017-02-01 10:23

reporter   ~0055441

Any news on this feature? It'll be usefull like : https://help.github.com/articles/creating-an-issue-template-for-your-repository/

vboctor

vboctor

2018-03-24 02:28

manager   ~0059304

A PR for this is submitted as part of 0024158.