fmsystem-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Fmsystem-commits] [15365] helpdesk: add image from clipboard


From: sigurdne
Subject: [Fmsystem-commits] [15365] helpdesk: add image from clipboard
Date: Mon, 11 Jul 2016 17:18:09 +0000 (UTC)

Revision: 15365
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=15365
Author:   sigurdne
Date:     2016-07-11 17:18:09 +0000 (Mon, 11 Jul 2016)
Log Message:
-----------
helpdesk: add image from clipboard

Modified Paths:
--------------
    trunk/helpdesk/inc/class.uitts.inc.php
    trunk/helpdesk/js/portico/tts.add.js
    trunk/helpdesk/js/portico/tts.view.js
    trunk/helpdesk/templates/base/tts.xsl

Modified: trunk/helpdesk/inc/class.uitts.inc.php
===================================================================
--- trunk/helpdesk/inc/class.uitts.inc.php      2016-07-02 00:59:48 UTC (rev 
15364)
+++ trunk/helpdesk/inc/class.uitts.inc.php      2016-07-11 17:18:09 UTC (rev 
15365)
@@ -47,7 +47,9 @@
                                'edit_status'           => true,
                                'get_vendor_email'      => true,
                                '_print'                        => true,
-                               'columns'                       => true
+                               'columns'                       => true,
+                               'update_data'           => true,
+                               'upload_clip'           => true
                        );
 
                /**
@@ -861,6 +863,50 @@
                        self::render_template_xsl('datatable_jquery', $data);
                }
 
+               function upload_clip()
+               {
+                       $id = phpgw::get_var('id', 'POST', 'int');
+                       $ret = array(
+                               'status' => 'error',
+                               'message'=> lang('No data')
+                       );
+
+                       if($_POST['pasted_image'])
+                       {
+                               $_ticket = $this->bo->read_single($id);
+                               $bofiles = 
CreateObject('property.bofiles','/helpdesk');
+                               $img = $_POST['pasted_image'];
+                               $img = str_replace('data:image/png;base64,', 
'', $img);
+                               $img = str_replace(' ', '+', $img);
+                               $data = base64_decode($img);
+                               $file = '/tmp/' . uniqid() . '.png';
+                               if (file_put_contents($file, $data))
+                               {
+                                       $to_file = 
"{$bofiles->fakebase}/{$id}/" .  str_replace(' ', '_', $_ticket['subject']) . 
'_' . ( (int)count($_ticket['files']) +1 ) . '.png';
+                                       $bofiles->create_document_dir("{$id}");
+                                       $bofiles->vfs->override_acl = 1;
+
+                                       $ret = array(
+                                               'status' => 'ok',
+                                               'message'=> 'Ok'
+                                       );
+                                       if (!$bofiles->vfs->cp(array(
+                                                       'from' => $file,
+                                                       'to' => $to_file,
+                                                       'relatives' => 
array(RELATIVE_NONE | VFS_REAL, RELATIVE_ALL))))
+                                       {
+                                               $ret = array(
+                                                       'status' => 'error',
+                                                       'message'=> 
lang('Failed to upload file !')
+                                               );
+
+                                       }
+                                       $bofiles->vfs->override_acl = 0;
+                               }
+                       }
+                       return $ret;
+               }
+
                function add()
                {
                        if (!$this->acl_add)
@@ -996,10 +1042,10 @@
                                        //------------ files
                                        $values['file_name'] = @str_replace(' 
', '_', $_FILES['file']['name']);
 
+                                       $bofiles = 
CreateObject('property.bofiles','/helpdesk');
                                        if ($values['file_name'] && 
$receipt['id'])
                                        {
-                                               $bofiles = 
CreateObject('property.bofiles');
-                                               $to_file = $bofiles->fakebase . 
'/helpdesk/' . $receipt['id'] . '/' . $values['file_name'];
+                                               $to_file = 
"{$bofiles->fakebase}/{$receipt['id']}/{$values['file_name']}";
 
                                                if 
($bofiles->vfs->file_exists(array(
                                                                'string' => 
$to_file,
@@ -1010,7 +1056,7 @@
                                                }
                                                else
                                                {
-                                                       
$bofiles->create_document_dir("helpdesk/{$receipt['id']}");
+                                                       
$bofiles->create_document_dir("{$receipt['id']}");
                                                        
$bofiles->vfs->override_acl = 1;
 
                                                        if 
(!$bofiles->vfs->cp(array(
@@ -1023,6 +1069,31 @@
                                                        
$bofiles->vfs->override_acl = 0;
                                                }
                                        }
+
+                                       if($_POST['pasted_image'])
+                                       {
+                                               $img = $_POST['pasted_image'];
+                                               $img = 
str_replace('data:image/png;base64,', '', $img);
+                                               $img = str_replace(' ', '+', 
$img);
+                                               $data = base64_decode($img);
+                                               $file = '/tmp/' . uniqid() . 
'.png';
+                                               if (file_put_contents($file, 
$data))
+                                               {
+                                                       $to_file = 
"{$bofiles->fakebase}/{$receipt['id']}/" .  str_replace(' ', '_', 
$values['subject']) . '.png';
+                                                       
$bofiles->create_document_dir("{$receipt['id']}");
+                                                       
$bofiles->vfs->override_acl = 1;
+
+                                                       if 
(!$bofiles->vfs->cp(array(
+                                                                       'from' 
=> $file,
+                                                                       'to' => 
$to_file,
+                                                                       
'relatives' => array(RELATIVE_NONE | VFS_REAL, RELATIVE_ALL))))
+                                                       {
+                                                               
$receipt['error'][] = array('msg' => lang('Failed to upload file !'));
+                                                       }
+                                                       
$bofiles->vfs->override_acl = 0;
+                                               }
+                                       }
+
                                        //--------------end files
                                        
$GLOBALS['phpgw']->session->appsession('receipt', 'helpdesk', $receipt);
                                        //      
$GLOBALS['phpgw']->session->appsession('session_data','fm_tts','');
@@ -1160,7 +1231,7 @@
                                'cat_select' => 
$this->cats->formatted_xslt_list(array('select_name' => 'values[cat_id]',
                                        'selected' => $this->cat_id, 'use_acl' 
=> $this->_category_acl, 'required' => true)),
                                'pref_send_mail' => 
(isset($GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['tts_user_mailnotification'])
 ? 
$GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['tts_user_mailnotification']
 : ''),
-                               'fileupload' => 
(isset($this->bo->config->config_data['fmttsfileupload']) ? 
$this->bo->config->config_data['fmttsfileupload'] : ''),
+                               'fileupload' => 
true,//(isset($this->bo->config->config_data['fmttsfileupload']) ? 
$this->bo->config->config_data['fmttsfileupload'] : ''),
                                'tabs' => 
phpgwapi_jquery::tabview_generate($tabs, $active_tab)
                        );
 
@@ -1176,6 +1247,67 @@
                        $GLOBALS['phpgw']->xslttpl->set_var('phpgw', 
array('add' => $data));
                }
 
+               function update_data()
+               {
+                       $action = phpgw::get_var('action', 'string', 'GET');
+                       switch ($action)
+                       {
+                               case 'get_vendor':
+                                       return 
$this->bocommon->get_vendor_email();
+                                       break;
+                               case 'get_files':
+                                       return $this->get_files();
+                                       break;
+                               default:
+                       }
+               }
+
+               function get_files()
+               {
+                       $id = phpgw::get_var('id', 'int');
+
+                       if (!$this->acl_read)
+                       {
+                               return;
+                       }
+
+                       $link_file_data = array
+                               (
+                               'menuaction' => 'property.uitts.view_file',
+                       );
+
+
+                       $link_view_file = $GLOBALS['phpgw']->link('/index.php', 
$link_file_data);
+                       $values = $this->bo->read_single($id);
+
+                       $content_files = array();
+
+                       foreach ($values['files'] as $_entry)
+                       {
+                               $content_files[] = array
+                                       (
+                                       'file_name' => '<a href="' . 
$link_view_file . '&amp;file_id=' . $_entry['file_id'] . '" target="_blank" 
title="' . lang('click to view file') . '">' . $_entry['name'] . '</a>',
+                                       'delete_file' => '<input 
type="checkbox" name="values[file_action][]" value="' . $_entry['file_id'] . '" 
title="' . lang('Check to delete file') . '">',
+                                       'attach_file' => '<input 
type="checkbox" name="values[file_attach][]" value="' . $_entry['file_id'] . '" 
title="' . lang('Check to attach file') . '">'
+                               );
+                       }
+
+                       if (phpgw::get_var('phpgw_return_as') == 'json')
+                       {
+
+                               $total_records = count($content_files);
+
+                               return array
+                                       (
+                                       'data' => $content_files,
+                                       'draw' => phpgw::get_var('draw', 'int'),
+                                       'recordsTotal' => $total_records,
+                                       'recordsFiltered' => $total_records
+                               );
+                       }
+                       return $content_files;
+               }
+
                function view()
                {
                        if (!$this->acl_read)
@@ -1310,17 +1442,17 @@
                                }
 
                                //--------- files
-                               $bofiles = CreateObject('property.bofiles');
+                               $bofiles = 
CreateObject('property.bofiles','/helpdesk');
                                if (isset($values['file_action']) && 
is_array($values['file_action']))
                                {
-                                       
$bofiles->delete_file("/helpdesk/{$id}/", $values);
+                                       $bofiles->delete_file("/{$id}", 
$values);
                                }
 
                                $values['file_name'] = str_replace(' ', '_', 
$_FILES['file']['name']);
 
                                if ($values['file_name'])
                                {
-                                       $to_file = $bofiles->fakebase . 
'/helpdesk/' . $id . '/' . $values['file_name'];
+                                       $to_file = 
"{$bofiles->fakebase}/{$id}/{$values['file_name']}";
 
                                        if ($bofiles->vfs->file_exists(array(
                                                        'string' => $to_file,
@@ -1331,7 +1463,7 @@
                                        }
                                        else
                                        {
-                                               
$bofiles->create_document_dir("helpdesk/{$id}");
+                                               
$bofiles->create_document_dir("{$id}");
                                                $bofiles->vfs->override_acl = 1;
 
                                                if (!$bofiles->vfs->cp(array(
@@ -1401,10 +1533,6 @@
                                $this->cat_id = $ticket['cat_id'];
                        }
 
-                       $link_file_data = array(
-                               'menuaction' => 'helpdesk.uitts.view_file',
-                               'id' => $id
-                       );
 
                        if ($this->show_finnish_date)
                        {
@@ -1483,8 +1611,9 @@
                                )
                        );
 
+                       $link_file_data = array('menuaction' => 
'helpdesk.uitts.view_file');
 
-                       $link_view_file = $GLOBALS['phpgw']->link('/index.php', 
$link_file_data);
+                       $link_view_file = $GLOBALS['phpgw']->link('/index.php', 
array('menuaction' => 'helpdesk.uitts.view_file'));
 
                        for ($z = 0; $z < count($ticket['files']); $z++)
                        {
@@ -1564,8 +1693,7 @@
                                $category = 
$this->cats->return_single($ticket['cat_id']);
 //_debug_array($category);
 
-                               array_unshift($cat_select['cat_list'], array
-                                       (
+                               array_unshift($cat_select['cat_list'], array(
                                        'cat_id' => $category[0]['id'],
                                        'name' => $category[0]['name'],
                                        'description' => 
$category[0]['description'],
@@ -1603,6 +1731,7 @@
                                'my_groups' => json_encode($my_groups),
                                'custom_attributes' => array('attributes' => 
$ticket['attributes']),
                                'lookup_functions' => 
isset($ticket['lookup_functions']) ? $ticket['lookup_functions'] : '',
+                               'simple' => $this->simple,
                                'send_response' => 
isset($this->bo->config->config_data['tts_send_response']) ? 
$this->bo->config->config_data['tts_send_response'] : '',
                                'value_sms_phone' => $ticket['contact_phone'],
                                'value_budget' => $ticket['budget'],
@@ -1640,6 +1769,7 @@
                                'done_action' => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'helpdesk.uitts.index')),
                                'value_subject' => $ticket['subject'],
                                'value_id' => '[ #' . $id . ' ] - ',
+                               'id'            => $id,
                                'value_details' => $ticket['details'],
                                'value_opendate' => $ticket['entry_date'],
                                'value_assignedfrom' => $ticket['user_name'],
@@ -1650,10 +1780,9 @@
                                'record_history' => $record_history,
                                'contact_phone' => $ticket['contact_phone'],
                                'pref_send_mail' => 
isset($GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['tts_user_mailnotification'])
 ? 
$GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['tts_user_mailnotification']
 : '',
-                               'fileupload' => 
isset($this->bo->config->config_data['fmttsfileupload']) ? 
$this->bo->config->config_data['fmttsfileupload'] : '',
+                               'fileupload' => 
true,//isset($this->bo->config->config_data['fmttsfileupload']) ? 
$this->bo->config->config_data['fmttsfileupload'] : '',
                                'multiple_uploader' => true,
                                'fileuploader_action' => 
"{menuaction:'property.fileuploader.add',upload_target:'helpdesk.botts.addfiles',id:'{$id}'}",
-                               'link_view_file' => 
$GLOBALS['phpgw']->link('/index.php', $link_file_data),
                                'link_to_files' => 
isset($this->bo->config->config_data['files_url']) ? 
$this->bo->config->config_data['files_url'] : '',
                                'files' => isset($ticket['files']) ? 
$ticket['files'] : '',
                                'lang_filename' => lang('Filename'),
@@ -1698,7 +1827,7 @@
                                phpgw::no_access();
                        }
 
-                       ExecMethod('helpdesk.bofiles.get_file', 
phpgw::get_var('file_id', 'int'));
+                       ExecMethod('property.bofiles.get_file', 
phpgw::get_var('file_id', 'int'));
                }
 
                protected function _generate_tabs( $history = '' )

Modified: trunk/helpdesk/js/portico/tts.add.js
===================================================================
--- trunk/helpdesk/js/portico/tts.add.js        2016-07-02 00:59:48 UTC (rev 
15364)
+++ trunk/helpdesk/js/portico/tts.add.js        2016-07-11 17:18:09 UTC (rev 
15365)
@@ -35,6 +35,10 @@
                                else
                                {
                                        document.getElementById(action).value = 
1;
+                                       var canvas = 
document.getElementById("my_canvas");
+                                       var image_data = 
canvas.toDataURL('image/png');
+                                       $('#pasted_image').val(image_data);
+
                                        try
                                        {
                                                validate_submit();
@@ -77,3 +81,173 @@
        errorMessageKey: ''
 });
 
+
+$(document).ready(function ()
+{
+
+
+       var CLIPBOARD = new CLIPBOARD_CLASS("my_canvas", true);
+
+       /**
+        * image pasting into canvas
+        *
+        * @param string canvas_id canvas id
+        * @param boolean autoresize if canvas will be resized
+        */
+       function CLIPBOARD_CLASS(canvas_id, autoresize)
+       {
+               var canvas = document.getElementById(canvas_id);
+               var _self = this;
+               var ctx = document.getElementById(canvas_id).getContext("2d");
+               var ctrl_pressed = false;
+               var reading_dom = false;
+               var text_top = 15;
+               var pasteCatcher;
+               var paste_mode;
+
+               //handlers
+               document.addEventListener('keydown', function (e)
+               {
+                       _self.on_keyboard_action(e);
+               }, false); //firefox fix
+               document.addEventListener('keyup', function (e)
+               {
+                       _self.on_keyboardup_action(e);
+               }, false); //firefox fix
+               document.addEventListener('paste', function (e)
+               {
+                       _self.paste_auto(e);
+               }, false); //official paste handler
+
+               //constructor - prepare
+               this.init = function ()
+               {
+                       //if using auto
+                       if (window.Clipboard)
+                       {
+                               return true;
+                       }
+
+                       pasteCatcher = document.createElement("div");
+                       pasteCatcher.setAttribute("id", "paste_ff");
+                       pasteCatcher.setAttribute("contenteditable", "");
+                       pasteCatcher.style.cssText = 
'opacity:0;position:fixed;top:0px;left:0px;';
+                       pasteCatcher.style.marginLeft = "-20px";
+                       pasteCatcher.style.width = "10px";
+                       document.body.appendChild(pasteCatcher);
+                       
document.getElementById('paste_ff').addEventListener('DOMSubtreeModified', 
function ()
+                       {
+                               if (paste_mode == 'auto' || ctrl_pressed == 
false)
+                               {
+                                       return true;
+                               }
+                               //if paste handle failed - capture pasted 
object manually
+                               if (pasteCatcher.children.length == 1)
+                               {
+                                       if (pasteCatcher.firstElementChild.src 
!= undefined)
+                                       {
+                                               //image
+                                               
_self.paste_createImage(pasteCatcher.firstElementChild.src);
+                                       }
+                               }
+                               //register cleanup after some time.
+                               setTimeout(function ()
+                               {
+                                       pasteCatcher.innerHTML = '';
+                               }, 20);
+                       }, false);
+               }();
+               //default paste action
+               this.paste_auto = function (e)
+               {
+                       paste_mode = '';
+                       pasteCatcher.innerHTML = '';
+                       var plain_text_used = false;
+                       if (e.clipboardData)
+                       {
+                               var items = e.clipboardData.items;
+                               if (items)
+                               {
+                                       paste_mode = 'auto';
+                                       //access data directly
+                                       for (var i = 0; i < items.length; i++)
+                                       {
+                                               if 
(items[i].type.indexOf("image") !== -1)
+                                               {
+                                                       //image
+                                                       var blob = 
items[i].getAsFile();
+                                                       var URLObj = window.URL 
|| window.webkitURL;
+                                                       var source = 
URLObj.createObjectURL(blob);
+                                                       
this.paste_createImage(source);
+                                               }
+                                       }
+                                       e.preventDefault();
+                               }
+                               else
+                               {
+                                       //wait for DOMSubtreeModified event
+                                       
//https://bugzilla.mozilla.org/show_bug.cgi?id=891247
+                               }
+                       }
+               };
+               //on keyboard press -
+               this.on_keyboard_action = function (event)
+               {
+                       k = event.keyCode;
+                       //ctrl
+                       if (k == 17 || event.metaKey || event.ctrlKey)
+                       {
+                               if (ctrl_pressed == false)
+                               {
+                                       ctrl_pressed = true;
+                               }
+                       }
+                       //c
+                       if (k == 86)
+                       {
+                               if (document.activeElement != undefined && 
document.activeElement.type == 'text')
+                               {
+                                       //let user paste into some input
+                                       return false;
+                               }
+
+                               if (ctrl_pressed == true && !window.Clipboard)
+                               {
+                                       pasteCatcher.focus();
+                               }
+                       }
+               };
+               //on kaybord release
+               this.on_keyboardup_action = function (event)
+               {
+                       k = event.keyCode;
+                       //ctrl
+                       if (k == 17 || event.metaKey || event.ctrlKey || 
event.key == 'Meta')
+                       {
+                               ctrl_pressed = false;
+                       }
+               };
+               //draw image
+               this.paste_createImage = function (source)
+               {
+                       var pastedImage = new Image();
+                       pastedImage.onload = function ()
+                       {
+                               if (autoresize == true)
+                               {
+                                       //resize canvas
+                                       canvas.width = pastedImage.width;
+                                       canvas.height = pastedImage.height;
+                               }
+                               else
+                               {
+                                       //clear canvas
+                                       ctx.clearRect(0, 0, canvas.width, 
canvas.height);
+                               }
+                               ctx.drawImage(pastedImage, 0, 0);
+                       };
+                       pastedImage.src = source;
+               };
+       }
+
+});
\ No newline at end of file

Modified: trunk/helpdesk/js/portico/tts.view.js
===================================================================
--- trunk/helpdesk/js/portico/tts.view.js       2016-07-02 00:59:48 UTC (rev 
15364)
+++ trunk/helpdesk/js/portico/tts.view.js       2016-07-11 17:18:09 UTC (rev 
15365)
@@ -110,3 +110,220 @@
        var strURL = phpGWLink('index.php', oArgs, true);
        JqueryPortico.updateinlineTableHelper(oTable2, strURL);
 };
+
+upload_canvas = function ()
+{
+       var canvas = document.getElementById("my_canvas");
+       var image_data = canvas.toDataURL('image/png');
+//     $('#pasted_image').val(image_data);
+       var oArgs = {
+               menuaction: 'helpdesk.uitts.upload_clip',
+               id: $('#id').val()
+       };
+       var strURL = phpGWLink('index.php', oArgs, true);
+
+       $.ajax({
+               type: 'POST',
+               dataType: 'json',
+               url: strURL,
+               data: {pasted_image: image_data},
+               success: function (data)
+               {
+                       if (data != null)
+                       {
+                               if(data.status == 'ok')
+                               {
+                                       var context = canvas.getContext('2d');
+//                                     context.clearRect(0, 0, canvas.width, 
canvas.height);
+                                       context.clearRect(0, 0, canvas.width, 
canvas.height);
+                                       canvas.height = 100;
+                                       canvas.width = 100;
+                                       refresh_files();
+                               }
+                               else
+                               {
+                                       alert(data.message);
+                               }
+                       }
+               },
+               failure: function (o)
+               {
+               }
+//             ,timeout: 5000
+       });
+
+};
+
+$(document).ready(function ()
+{
+
+
+       var CLIPBOARD = new CLIPBOARD_CLASS("my_canvas", true);
+
+       /**
+        * image pasting into canvas
+        *
+        * @param string canvas_id canvas id
+        * @param boolean autoresize if canvas will be resized
+        */
+       function CLIPBOARD_CLASS(canvas_id, autoresize)
+       {
+               var canvas = document.getElementById(canvas_id);
+               var _self = this;
+               var ctx = document.getElementById(canvas_id).getContext("2d");
+               var ctrl_pressed = false;
+               var reading_dom = false;
+               var text_top = 15;
+               var pasteCatcher;
+               var paste_mode;
+
+               //handlers
+               document.addEventListener('keydown', function (e)
+               {
+                       _self.on_keyboard_action(e);
+               }, false); //firefox fix
+               document.addEventListener('keyup', function (e)
+               {
+                       _self.on_keyboardup_action(e);
+               }, false); //firefox fix
+               document.addEventListener('paste', function (e)
+               {
+                       _self.paste_auto(e);
+               }, false); //official paste handler
+
+               //constructor - prepare
+               this.init = function ()
+               {
+                       //if using auto
+                       if (window.Clipboard)
+                       {
+                               return true;
+                       }
+
+                       pasteCatcher = document.createElement("div");
+                       pasteCatcher.setAttribute("id", "paste_ff");
+                       pasteCatcher.setAttribute("contenteditable", "");
+                       pasteCatcher.style.cssText = 
'opacity:0;position:fixed;top:0px;left:0px;';
+                       pasteCatcher.style.marginLeft = "-20px";
+                       pasteCatcher.style.width = "10px";
+                       document.body.appendChild(pasteCatcher);
+                       
document.getElementById('paste_ff').addEventListener('DOMSubtreeModified', 
function ()
+                       {
+                               if (paste_mode == 'auto' || ctrl_pressed == 
false)
+                               {
+                                       return true;
+                               }
+                               //if paste handle failed - capture pasted 
object manually
+                               if (pasteCatcher.children.length == 1)
+                               {
+                                       if (pasteCatcher.firstElementChild.src 
!= undefined)
+                                       {
+                                               //image
+                                               
_self.paste_createImage(pasteCatcher.firstElementChild.src);
+                                       }
+                               }
+                               //register cleanup after some time.
+                               setTimeout(function ()
+                               {
+                                       pasteCatcher.innerHTML = '';
+                               }, 20);
+                       }, false);
+               }();
+               //default paste action
+               this.paste_auto = function (e)
+               {
+                       paste_mode = '';
+                       pasteCatcher.innerHTML = '';
+                       var plain_text_used = false;
+                       if (e.clipboardData)
+                       {
+                               var items = e.clipboardData.items;
+                               if (items)
+                               {
+                                       paste_mode = 'auto';
+                                       //access data directly
+                                       for (var i = 0; i < items.length; i++)
+                                       {
+                                               if 
(items[i].type.indexOf("image") !== -1)
+                                               {
+                                                       //image
+                                                       var blob = 
items[i].getAsFile();
+                                                       var URLObj = window.URL 
|| window.webkitURL;
+                                                       var source = 
URLObj.createObjectURL(blob);
+                                                       
this.paste_createImage(source);
+                                               }
+                                       }
+                                       e.preventDefault();
+                               }
+                               else
+                               {
+                                       //wait for DOMSubtreeModified event
+                                       
//https://bugzilla.mozilla.org/show_bug.cgi?id=891247
+                               }
+                       }
+               };
+               //on keyboard press -
+               this.on_keyboard_action = function (event)
+               {
+                       k = event.keyCode;
+                       //ctrl
+                       if (k == 17 || event.metaKey || event.ctrlKey)
+                       {
+                               if (ctrl_pressed == false)
+                               {
+                                       ctrl_pressed = true;
+                               }
+                       }
+                       //c
+                       if (k == 86)
+                       {
+                               if (document.activeElement != undefined && 
document.activeElement.type == 'text')
+                               {
+                                       //let user paste into some input
+                                       return false;
+                               }
+
+                               if (ctrl_pressed == true && !window.Clipboard)
+                               {
+                                       pasteCatcher.focus();
+                               }
+                       }
+               };
+               //on kaybord release
+               this.on_keyboardup_action = function (event)
+               {
+                       k = event.keyCode;
+                       //ctrl
+                       if (k == 17 || event.metaKey || event.ctrlKey || 
event.key == 'Meta')
+                       {
+                               ctrl_pressed = false;
+                       }
+               };
+               //draw image
+               this.paste_createImage = function (source)
+               {
+                       var pastedImage = new Image();
+                       pastedImage.onload = function ()
+                       {
+                               if (autoresize == true)
+                               {
+                                       //resize canvas
+                                       canvas.width = pastedImage.width;
+                                       canvas.height = pastedImage.height;
+                               }
+                               else
+                               {
+                                       //clear canvas
+                                       ctx.clearRect(0, 0, canvas.width, 
canvas.height);
+                               }
+                               ctx.drawImage(pastedImage, 0, 0);
+                       };
+                       pastedImage.src = source;
+                       setTimeout(function ()
+                       {
+                               upload_canvas();
+                       }, 500);
+               };
+       }
+
+});

Modified: trunk/helpdesk/templates/base/tts.xsl
===================================================================
--- trunk/helpdesk/templates/base/tts.xsl       2016-07-02 00:59:48 UTC (rev 
15364)
+++ trunk/helpdesk/templates/base/tts.xsl       2016-07-11 17:18:09 UTC (rev 
15365)
@@ -200,6 +200,16 @@
                                                        </div>
                                                </xsl:when>
                                        </xsl:choose>
+
+                                       <div class="pure-control-group">
+                                               <label>
+                                                       <xsl:value-of 
select="php:function('lang', 'paste image data')"/>
+                                               </label>
+                                               <canvas title="Copy image data 
into clipboard and press Ctrl+V" style="border:1px solid grey;" id="my_canvas" 
width="100" height="100">
+                                               </canvas>
+                                               <input type="hidden" 
id="pasted_image" name="pasted_image"></input>
+                                       </div>
+
                                </fieldset>
                        </div>
                </div>
@@ -281,7 +291,7 @@
                var base_java_url = <xsl:value-of select="base_java_url"/>;
                var location_item_id = '<xsl:value-of 
select="location_item_id"/>';
 
-       //      var initialSelection = <xsl:value-of select="resources_json"/>;
+               //      var initialSelection = <xsl:value-of 
select="resources_json"/>;
                var lang = <xsl:value-of select="php:function('js_lang',  
'Name', 'Address')"/>
 
 
@@ -314,6 +324,9 @@
                                                                <xsl:value-of 
select="php:function('lang', 'update subject')"/>
                                                        </xsl:attribute>
                                                </input>
+                                               <input type="text" id="id" 
name="id" value="{id}">
+                                               </input>
+
                                        </div>
                                        <xsl:for-each select="value_origin">
                                                <div class="pure-control-group">
@@ -546,6 +559,17 @@
                                                        <xsl:call-template 
name="file_upload"/>
                                                </xsl:when>
                                        </xsl:choose>
+
+
+                                       <div class="pure-control-group">
+                                               <label>
+                                                       <xsl:value-of 
select="php:function('lang', 'paste image data')"/>
+                                               </label>
+                                               <canvas title="Copy image data 
into clipboard and press Ctrl+V" style="border:1px solid grey;" id="my_canvas" 
width="100" height="100">
+                                               </canvas>
+                                               <input type="hidden" 
id="pasted_image" name="pasted_image"></input>
+                                       </div>
+
                                        <xsl:choose>
                                                <xsl:when test="send_response = 
1">
                                                        <div 
class="pure-control-group">




reply via email to

[Prev in Thread] Current Thread [Next in Thread]