Changeset 1080 for trunk/common


Ignore:
Timestamp:
12/14/09 19:14:17 (2 years ago)
Author:
bogdan2412
Message:

Admin interface for adding/renaming/deleting algorithm tags.

This interface can be seen at /admin/task_tags.

In addition, added proper tag validation in task_edit controller.

We were using a version of MochiKit? with some modules stripped out so that it would be smaller.
I needed MochiKit?.Selector, so I downloaded the full version. If anybody knows what modules we stripped out before, please tell me.

Added a new inline_form.js file which will prove useful when designing other interfaces with inline rename.

Review URL: http://reviewboard.infoarena.ro/r/119/

Location:
trunk/common
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/common/db/tags.php

    r1079 r1080  
    66// Get list of all tag names, filtered by type and parent 
    77function tag_get_all($types = null, $parent = null) { 
    8     $query = "SELECT name, type, parent FROM ia_tags"; 
     8    $query = "SELECT id, name, type, parent FROM ia_tags"; 
    99    $where = array(); 
    1010    if (!is_null($types)) { 
     
    9797} 
    9898 
     99// Updates name, type or parent for a tag specified by it's id 
     100function tag_update_by_id($tag_id, $tag) { 
     101    $query = sprintf( 
     102        "UPDATE ia_tags SET name = %s, type = %s, parent = %s WHERE id = %s", 
     103        db_quote($tag["name"]), db_quote($tag["type"]), 
     104        db_quote($tag["parent"]), db_quote($tag_id)); 
     105    db_query($query); 
     106    return db_affected_rows() == 1; 
     107} 
     108 
     109// Delete a tag identified by it's id 
     110function tag_delete_by_id($tag_id) { 
     111    db_query(sprintf( 
     112        "DELETE FROM ia_tags WHERE parent = %s", db_quote($tag_id) 
     113    )); 
     114    db_query(sprintf("DELETE FROM ia_tags WHERE id = %s", db_quote($tag_id))); 
     115    return db_affected_rows() == 1; 
     116} 
     117 
    99118// Build ugly where clause to be used in subqueries 
    100119function tag_build_where($obj, $tag_ids, $parent_table = null) { 
  • trunk/common/tags.php

    r1079 r1080  
    1717} 
    1818 
    19 function tag_validate($data, &$errors) { 
    20     $tags = getattr($data, 'tags'); 
     19function tag_validate($data, &$errors, $key = null, $parent_key = null) { 
     20    if (is_null($key)) { 
     21        $tag_key = 'tags'; 
     22    } else { 
     23        $tag_key = 'tag_'.$key; 
     24    } 
     25    $tags = getattr($data, $tag_key); 
    2126    if (is_null($tags)) { 
    2227        return; 
     
    2530    foreach ($tags as $tag) { 
    2631        if (!is_tag_name($tag)) { 
    27             $errors['tags'] = "Cel putin un tag este gresit"; 
     32            $errors[$tag_key] = "Cel putin un tag este gresit"; 
    2833            return; 
     34        } 
     35    } 
     36    if (count($tags) > 0 && !is_null($parent_key)) { 
     37        $parent_tag = getattr($data, 'tag_'.$parent_key, ""); 
     38        if (count(tag_split($parent_tag)) != 1) { 
     39            $errors['tag_'.$parent_key] = sprintf("Trebuie specificat exact 
     40                un tag '%s' pentru a specifica taguri '%s'", $parent_key, $key); 
    2941        } 
    3042    } 
Note: See TracChangeset for help on using the changeset viewer.