Changeset 11346

Show
Ignore:
Timestamp:
07/24/07 16:41:07 (1 year ago)
Author:
adrenalin
Message:

Added delete option for file attachments.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/midcom/midcom.admin.styleeditor/config/config.inc

    r5455 r11346  
    11'text_types' => array 
    22( 
    3     'text/css'        => 'cascading style sheet', 
    4     'text/javascript' => 'javascript', 
    5     'text/plain'      => 'plain text', 
    6     'text/xml'        => 'xml', 
     3    'text/css'                 => 'cascading style sheet', 
     4    'text/javascript'          => 'javascript', 
     5    'application/x-javascript' => 'javascript', 
     6    'text/plain'               => 'plain text', 
     7    'text/xml'                 => 'xml', 
     8    'text/html'                => 'html', 
    79), 
  • trunk/midcom/midcom.admin.styleeditor/handler/file.php

    r11341 r11346  
    138138            MIDCOM_NAV_NAME => $_MIDCOM->i18n->get_string('style attachments', 'midcom.admin.styleeditor'), 
    139139        ); 
    140  
     140         
    141141        switch ($handler_id) 
    142142        { 
    143             case '____mfa-styleeditor-file_edit': 
     143            case '____mfa-asgard_midcom.admin.styleeditor-file_edit': 
    144144                $tmp[] = Array 
    145145                ( 
    146146                    MIDCOM_NAV_URL => "__mfa/asgard_midcom.admin.styleeditor/files/{$this->_request_data['filename']}/", 
    147                     MIDCOM_NAV_NAME => sprintf($_MIDCOM->i18n->get_string('edit file %s', 'midcom.admin.styleeditor'), $this->_request_data['filename']), 
     147                    MIDCOM_NAV_NAME => $this->_request_data['filename'], 
     148                ); 
     149                break; 
     150            case '____mfa-asgard_midcom.admin.styleeditor-file_delete': 
     151                $tmp[] = array 
     152                ( 
     153                    MIDCOM_NAV_URL => "__mfa/asgard_midcom.admin.styleeditor/files/{$this->_request_data['filename']}/", 
     154                    MIDCOM_NAV_NAME => sprintf($_MIDCOM->i18n->get_string('%s', 'midcom.admin.styleeditor'), $this->_request_data['filename']), 
     155                ); 
     156                $tmp[] = array 
     157                ( 
     158                    MIDCOM_NAV_URL => "__mfa/asgard_midcom.admin.styleeditor/files/{$this->_request_data['filename']}/delete/", 
     159                    MIDCOM_NAV_NAME => $_MIDCOM->i18n->get_string('delete', 'midcom'), 
    148160                ); 
    149161                break; 
     
    295307        $qb = midcom_baseclasses_database_attachment::new_query_builder(); 
    296308        $qb->add_constraint('parentguid', '=', $this->_style->guid); 
     309         
    297310        $qb->add_constraint('name', '=', $filename); 
     311         
    298312        $files = $qb->execute(); 
    299313        if (empty($files)) 
     
    340354        else 
    341355        { 
    342             $_MIDCOM->relocate("__mfa/asgard_midcom.admin.styleeditor/files/{$filename}"); 
     356            $_MIDCOM->relocate("__mfa/asgard_midcom.admin.styleeditor/files/{$filename}/"); 
    343357        } 
    344358         
     
    405419     * Handler method for listing style elements for the currently used component topic 
    406420     * 
    407      * @access private 
     421     * @access public 
    408422     * @param string $handler_id Name of the used handler 
    409423     * @param mixed $args Array containing the variable arguments passed to the handler 
     
    439453            if ($filename != $data['filename']) 
    440454            { 
    441                 $_MIDCOM->relocate("__mfa/asgard_midcom.admin.styleeditor/files/{$filename}"); 
     455                $_MIDCOM->relocate("__mfa/asgard_midcom.admin.styleeditor/files/{$filename}/"); 
    442456            } 
    443457        } 
     
    452466        // Skip the page styles 
    453467        $_MIDCOM->skip_page_style = true; 
     468         
     469        // Add the codepress syntax highlight 
     470        $_MIDCOM->add_jsfile(MIDCOM_STATIC_URL . '/midcom.helper.datamanager2/codepress/codepress.js'); 
    454471         
    455472        // Add the page title 
     
    502519        midcom_show_style('midgard_admin_asgard_footer');     
    503520    } 
     521     
     522    /** 
     523     * Handler method for confirming file deleting for the requested file 
     524     * 
     525     * @access public 
     526     * @param string $handler_id Name of the used handler 
     527     * @param mixed $args Array containing the variable arguments passed to the handler 
     528     * @param mixed $data Data passed to the show method 
     529     * @return boolean Indicating successful request 
     530     */ 
     531    function _handler_delete($handler_id, $args, &$data) 
     532    { 
     533        $this->_load_config(); 
     534        $data['filename'] = $args[0]; 
     535        if (!$this->_load_style()) 
     536        { 
     537            return false; 
     538        } 
     539        $this->_topic->require_do('midcom.admin.styleeditor:template_management'); 
     540        $this->_style->require_do('midgard:attachments'); 
     541         
     542        $this->_file = $this->_get_file($data['filename']); 
     543        if (!$this->_file) 
     544        { 
     545            return false; 
     546        } 
     547         
     548        // Require delete privilege 
     549        $this->_file->require_do('midgard:delete'); 
     550         
     551        if (isset($_POST['f_cancel'])) 
     552        { 
     553            $_MIDCOM->uimessages->add($_MIDCOM->i18n->get_string('midcom.admin.styleeditor', 'midcom.admin.styleeditor'), $_MIDCOM->i18n->get_string('delete cancelled', 'midcom.admin.styleeditor')); 
     554            $_MIDCOM->relocate("__mfa/asgard_midcom.admin.styleeditor/files/{$data['filename']}/"); 
     555            // This will exit 
     556        } 
     557         
     558        if (isset($_POST['f_confirm'])) 
     559        { 
     560            if ($this->_file->delete()) 
     561            { 
     562                $_MIDCOM->uimessages->add($_MIDCOM->i18n->get_string('midcom.admin.styleeditor', 'midcom.admin.styleeditor'), sprintf($_MIDCOM->i18n->get_string('file %s deleted', 'midcom.admin.styleeditor'), $data['filename'])); 
     563                $_MIDCOM->relocate("__mfa/asgard_midcom.admin.styleeditor/files/"); 
     564                // This will exit 
     565            } 
     566             
     567             
     568        } 
     569         
     570        $_MIDCOM->bind_view_to_object($this->_file); 
     571         
     572        // Ensure we get the correct styles 
     573        $_MIDCOM->style->prepend_component_styledir('midgard.admin.asgard'); 
     574        $_MIDCOM->style->prepend_component_styledir('midcom.admin.styleeditor'); 
     575         
     576        $this->_update_breadcrumb($handler_id); 
     577         
     578        // Skip the page styles 
     579        $_MIDCOM->skip_page_style = true; 
     580         
     581        // Add the page title 
     582        $data['view_title'] = sprintf($_MIDCOM->i18n->get_string('delete file %s', 'midcom.admin.styleeditor'), "'{$args[0]}'"); 
     583         
     584        // Set the Asgard toolbar 
     585        $data['asgard_toolbar'] = new midcom_helper_toolbar(); 
     586         
     587        $data['asgard_toolbar']->add_item 
     588        ( 
     589            array 
     590            ( 
     591                MIDCOM_TOOLBAR_URL => "__mfa/asgard_midcom.admin.styleeditor/create/", 
     592                MIDCOM_TOOLBAR_LABEL => $_MIDCOM->i18n->get_string('create a new element', 'midcom.admin.styleeditor'), 
     593                MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/text-x-generic-template.png', 
     594            ) 
     595        );         
     596        $data['asgard_toolbar']->add_item 
     597        ( 
     598            array 
     599            ( 
     600                MIDCOM_TOOLBAR_URL => "__mfa/asgard_midcom.admin.styleeditor/files/", 
     601                MIDCOM_TOOLBAR_LABEL => $_MIDCOM->i18n->get_string('style attachments', 'midcom.admin.styleeditor'), 
     602                MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/attach.png', 
     603            ) 
     604        ); 
     605         
     606        return true; 
     607    } 
     608     
     609    /** 
     610     * Show the delete request 
     611     *  
     612     * @access private 
     613     * @param string $handler_id Name of the used handler 
     614     * @param mixed $data Data passed to the show method 
     615     */ 
     616    function _show_delete($handler_id, &$data) 
     617    { 
     618        midcom_show_style('midgard_admin_asgard_header'); 
     619        midcom_show_style('midgard_admin_asgard_middle'); 
     620         
     621        $data['file'] =& $this->_file; 
     622        $data['text_types'] = $this->_config->get('text_types'); 
     623        midcom_show_style('midcom-admin-styleeditor-files-delete'); 
     624        midcom_show_style('midgard_admin_asgard_footer');     
     625    } 
     626     
    504627} 
    505628?> 
  • trunk/midcom/midcom.admin.styleeditor/locale/default.en.txt

    r11341 r11346  
    127127Style element %s created 
    128128---STRINGEND 
     129 
     130---STRING delete file %s 
     131Delete file '%s' 
     132---STRINGEND 
     133 
     134---STRING confirm delete of file %s 
     135Confirm delete of file '%s' 
     136---STRINGEND 
     137 
     138---STRING delete cancelled 
     139Delete cancelled 
     140---STRINGEND 
     141 
     142---STRING file %s deleted 
     143File '%s' deleted 
     144---STRINGEND 
  • trunk/midcom/midcom.admin.styleeditor/style/midcom-admin-styleeditor-files-file.php

    r11341 r11346  
    11<h1><?php echo sprintf($_MIDCOM->i18n->get_string('edit file %s', 'midcom.admin.styleeditor'), $data['filename']); ?></h1> 
    22 
    3 <form method="post" enctype="multipart/form-data"
     3<form method="post" enctype="multipart/form-data" action="&(_MIDGARD['uri']:h);" onsubmit="midcom_admin_styleeditor_file_edit.toggleEditor();"
    44    <fieldset> 
    55        <legend><?php echo $_MIDCOM->i18n->get_string('upload file', 'midcom.admin.styleeditor'); ?></legend> 
     
    1010    if (array_key_exists($data['file']->mimetype, $data['text_types'])) 
    1111    { 
     12        switch(preg_replace('/.+?\//', '', $data['file']->mimetype)) 
     13        { 
     14            case 'css': 
     15                $codepress_type = 'css'; 
     16                break; 
     17             
     18            case 'html': 
     19                $codepress_type = 'html'; 
     20                break; 
     21             
     22            case 'x-javascript': 
     23            case 'javascript': 
     24                $codepress_type = 'javascript'; 
     25                break; 
     26             
     27            default: 
     28                $codepress_type = 'text'; 
     29        } 
     30         
    1231        // Show file for editing only if it is a text file 
    1332        ?> 
     
    2342            <label> 
    2443                <span><?php echo $_MIDCOM->i18n->get_string('file contents', 'midcom.admin.styleeditor'); ?></span> 
    25                 <textarea name="midcom_admin_styleeditor_contents" cols="60" rows="30" wrap="none"><?php 
     44                <textarea name="midcom_admin_styleeditor_contents" cols="60" rows="30" wrap="none" id="midcom_admin_styleeditor_file_edit" class="&(codepress_type); codepress"><?php 
    2645                    $f = $data['file']->open('r'); 
    2746                    if ($f) 
     
    4160</form> 
    4261 
    43 <form class="urlform"
     62<form class="urlform" method="post" action="&(_MIDGARD['uri']:h);delete/"
    4463    <?php 
    4564    $file_url = $_MIDCOM->get_host_prefix() . "midcom-serveattachmentguid-{$data['file']->guid}/{$data['file']->name}"; 
     
    5978            <input class="text" type="text" value="&(file_url);" readonly="readonly" /> 
    6079        </label> 
     80        <br /> 
     81        <input type="submit" class="delete" name="f_delete" value="<?php echo $_MIDCOM->i18n->get_string('delete', 'midcom'); ?>" /> 
    6182    </fieldset> 
    6283</form> 
  • trunk/midcom/midcom.admin.styleeditor/style/midcom-admin-styleeditor-files-header.php

    r5458 r11346  
    1919                } 
    2020                 
    21                 echo "<li{$class}><a href=\"{$prefix}__mfa/styleeditor/files/{$file->name}\"><img src=\"{$mime_icon}\" /> {$file->name}</a></li>\n"; 
     21                echo "<li{$class}><a href=\"{$prefix}__mfa/asgard_midcom.admin.styleeditor/files/{$file->name}/\"><img src=\"{$mime_icon}\" /> {$file->name}</a></li>\n"; 
    2222            } 
    2323            echo "</ul>\n"; 
  • trunk/midcom/midcom.admin.styleeditor/viewer.php

    r11335 r11346  
    9595                'variable_args' => 1, 
    9696            ), 
     97            /** 
     98             * Delete a file 
     99             *  
     100             * Match /files/<filename>/delete/ 
     101             */ 
     102            'file_delete' => array 
     103            ( 
     104                'handler' => array ('midcom_admin_styleeditor_handler_file', 'delete'), 
     105                'fixed_args' => array('files'), 
     106                'variable_args' => 2, 
     107            ), 
    97108        ); 
    98109    }