Changeset 1077 for trunk


Ignore:
Timestamp:
12/13/09 19:17:05 (2 years ago)
Author:
savin.tiberiu@…
Message:

Editing and adding tags to a task.
Reviewed: http://reviewboard.infoarena.ro/r/108/

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/common/tags.php

    r1069 r1077  
    55 
    66function tag_split($tag_data) { 
    7     $tags = explode(",", trim($tag_data)); 
     7    $tags = explode(",", $tag_data); 
     8    array_walk($tags, 'trim'); 
    89    $result = array(); 
    910    foreach ($tags as &$tag) { 
     
    3031} 
    3132 
    32 function tag_build_list($obj, $obj_id, $type) { 
     33function tag_build_list($obj, $obj_id, $type, $remove_prefix = true) { 
    3334    $tag_list = tag_get($obj, $obj_id, $type); 
    3435    $tag_names = array(); 
    3536    foreach ($tag_list as $tag) { 
    36         $tag_names[] = $tag['tag_name']; 
     37        if ($remove_prefix) { 
     38            $tag_parts = explode('@', $tag['tag_name']); 
     39            $tag_names[] = trim($tag_parts[ count($tag_parts) - 1 ]); 
     40        } else { 
     41            $tag_names[] = $tag['tag_name']; 
     42        } 
    3743    } 
    3844    return implode(", ", $tag_names); 
    3945} 
    4046 
    41 function tag_update($obj, $obj_id, $type, $tag_data) { 
     47function tag_update($obj, $obj_id, $type, $tag_data, $tag_prefix = "") { 
    4248    tag_clear($obj, $obj_id, $type); 
    4349    $tag_data = tag_split($tag_data); 
    4450    foreach ($tag_data as $tag_name) { 
    45         $tag_id = tag_assign_id(array("name" => $tag_name, "type" => $type)); 
     51        $tag_id = tag_assign_id(array("name" => $tag_prefix.$tag_name, "type" => $type)); 
    4652        tag_add($obj, $obj_id, $tag_id); 
    4753    } 
  • trunk/www/controllers/task.php

    r1069 r1077  
    6565 
    6666    // Tag data 
    67     $values['tags'] = request('tags', tag_build_list("task", $task_id, "tag")); 
     67    $tag_types = Array('author', 'contest', 'year', 'round', 'age_group', 'method', 'algorithm'); 
     68    $tag_parents = Array('year' => 'contest', 'round' => 'year', 'age_group' => 'contest'); 
     69 
     70    // FIXME: tags that have children such as contest, year or round should have only one tag 
     71    foreach ($tag_types as $type) { 
     72        $remove_prefix = isset($tag_parents[$type]); 
     73        $values['tag_'.$type] = request('tag_'.$type, tag_build_list('task', $task_id, $type, $remove_prefix)); 
     74        $prefix['tag_'.$type] = ''; 
     75        if (isset($tag_parents[$type])) { 
     76            $parent_type = $tag_parents[$type]; 
     77            $prefix['tag_'.$type] = $prefix['tag_'.$parent_type].$values['tag_'.$parent_type]."@"; 
     78        } 
     79    } 
    6880 
    6981    // Task owner 
     
    138150 
    139151            if (identity_can('task-tag', $new_task)) { 
    140                 tag_update("task", $new_task['id'], "tag", $values['tags']); 
     152                foreach ($tag_types as $type) { 
     153                    tag_update('task', $new_task['id'], $type, $values['tag_'.$type], $prefix['tag_'.$type]); 
     154                } 
    141155            } 
    142156 
  • trunk/www/views/account.php

    r934 r1077  
    6868    <ul class="form"> 
    6969    <?php if (identity_can('user-tag', $view['user'])) { ?> 
    70         <?= tag_format_input_box(fval('tags')) ?> 
     70        <?= tag_format_input_box(array("label" => "Tag-uri", "name" => "tags"), fval('tags')) ?> 
    7171    <?php } ?> 
    7272        </li> 
  • trunk/www/views/round_edit.php

    r1009 r1077  
    9393   <?= view_form_field_li($form_fields['start_time'], 'start_time') ?> 
    9494   <?php if ($can_tag) { ?> 
    95       <?= tag_format_input_box(fval('tags')) ?> 
     95      <?= tag_format_input_box(array("label" => "Tag-uri", "name" => "tags"), fval('tags')) ?> 
    9696   <?php } ?> 
    9797   <?= view_form_field_li($form_fields['tasks'], 'tasks') ?> 
  • trunk/www/views/tags_header.php

    r1069 r1077  
    99// Format a tag input box 
    1010// FIXME: Width parameter does not work, I hate CSS 
    11 function tag_format_input_box($value = null, $width = "50", $name = "tags") { 
    12     $esc_name = html_escape($name); 
     11function tag_format_input_box($field, $value = null, $width = "50", $name = "tags") { 
     12    $esc_name = html_escape($field['name']); 
    1313    $esc_width = html_escape($width); 
    1414    // presume $value is html-escaped 
    1515 
    16     $output = '<li><label for="form_'.$esc_name.'">Tag-uri</label>'; 
     16    $output = '<li><label for="form_'.$esc_name.'">'.$field['label'].'</label>'; 
    1717    $output .= ferr_span($name); 
    1818    $output .= '<input class="wickEnabled" type="text" name="'.$esc_name. 
     
    2525    } 
    2626    $output .= ' />'; 
    27     $output .= '<script type="text/javascript" language="JavaScript" src="'. 
    28                 html_escape(url_static("js/wick.js")).'"></script>'; 
     27//    $output .= '<script type="text/javascript" language="JavaScript" src="'. 
     28//                html_escape(url_static("js/wick.js")).'"></script>'; 
    2929    $output .= "</li>"; 
    3030    return $output; 
  • trunk/www/views/task_edit.php

    r1055 r1077  
    125125           <?= view_form_field_li($form_fields['hidden'], 'hidden') ?> 
    126126        <?php } ?> 
    127         <?php if (identity_can('task-tag', $task)) { ?> 
    128            <?= tag_format_input_box(fval('tags')) ?> 
    129         <?php } ?> 
    130     </ul> 
     127   </ul> 
    131128    </fieldset> 
     129 
     130    <?php if (identity_can('task-tag', $task)) { 
     131        $tag_fields = Array('author' => Array("label" => "Autor", 
     132                                                "name" => "tag_author"), 
     133                            'contest' => Array("label" => "Concurs", 
     134                                                "name" => "tag_contest"), 
     135                            'year' => Array("label" => "Anul", 
     136                                            "name" => "tag_year"), 
     137                            'round' => Array("label" => "Runda", 
     138                                            "name" => "tag_round"), 
     139                            'age_group' => Array("label" => "Grupa de varsta", 
     140                                        "name" => "tag_age_group"), 
     141                            'method' => Array("label" => "Metoda de programare", 
     142                                        "name" => "tag_method"), 
     143                            'algorithm' => Array("label" => "Algoritm", 
     144                                        "name" => "tag_algorithm") 
     145                        ); 
     146    ?> 
     147        <fieldset> 
     148            <legend>Taguri</legend> 
     149            <ul class="form"> 
     150                <?= tag_format_input_box($tag_fields['author'], fval('tag_author')); ?> 
     151                <?= tag_format_input_box($tag_fields['contest'], fval('tag_contest')); ?> 
     152                <?= tag_format_input_box($tag_fields['year'], fval('tag_year')); ?> 
     153                <?= tag_format_input_box($tag_fields['round'], fval('tag_round')); ?> 
     154                <?= tag_format_input_box($tag_fields['age_group'], fval('tag_age_group')); ?> 
     155                <?= tag_format_input_box($tag_fields['method'], fval('tag_method')); ?> 
     156                <?= tag_format_input_box($tag_fields['algorithm'], fval('tag_algorithm')); ?> 
     157            </ul> 
     158        </fieldset> 
     159    <?php } ?> 
     160 
    132161 
    133162<?php 
  • trunk/www/views/textblock_edit.php

    r964 r1077  
    4545 
    4646    <?php if (identity_can('textblock-tag', $view['page'])) { ?> 
    47        <?= tag_format_input_box(fval('tags')) ?> 
     47       <?= tag_format_input_box(array("label" => "Tag-uri", "name" => "tags"), fval('tags')) ?> 
    4848    <?php } ?> 
    4949 
Note: See TracChangeset for help on using the changeset viewer.