diff --git a/api/js/etemplate/et2_widget_image.js b/api/js/etemplate/et2_widget_image.js index a8e523b5b6..86f3dd8db7 100644 --- a/api/js/etemplate/et2_widget_image.js +++ b/api/js/etemplate/et2_widget_image.js @@ -15,6 +15,7 @@ et2_core_interfaces; et2_core_baseWidget; expose; + /vendor/bower-asset/cropper/dist/cropper.min.js; */ /** @@ -328,6 +329,12 @@ var et2_avatar = (function(){ "use strict"; return et2_image.extend( type: "boolean", default: false, description: "Make avatar widget editable to be able to crop profile picture or upload a new photo" + }, + crop: { + name: "Crop avatar", + type: "boolean", + default: false, + description: "Create crop container and cropping feature" } }, @@ -436,7 +443,36 @@ var et2_avatar = (function(){ "use strict"; return et2_image.extend( var edit = jQuery(document.createElement('div')) .addClass('emlEdit') .click(function(){ - // Todo + var buttons = [ + {"button_id": 1,"text": 'save', id: 'save', image: 'check', "default":true}, + {"button_id": 0,"text": 'cancel', id: 'cancel', image: 'cancelled'} + ]; + var dialog = function(_title, _value, _buttons, _egw_or_appname) + { + return et2_createWidget("dialog", + { + callback: function(_buttons, _value) + { + if (_buttons == 'save') + { + var canvas = jQuery('#_cropper_image').cropper('getCroppedCanvas'); + self.image.attr('src', canvas.toDataURL("image/jpeg", 1.0)); + } + }, + title: _title||egw.lang('Input required'), + buttons: _buttons||et2_dialog.BUTTONS_OK_CANCEL, + value: { + content: _value + }, + width: "90%", + height:"90%", + resizable: false, + position:"top+10", + template: egw.webserverUrl+'/api/templates/default/avatar_edit.xet?2' + }, et2_dialog._create_parent(_egw_or_appname)); + }; + + dialog(egw.lang('Edit avatar'),{photo:self.options.contact_id},buttons); }) .appendTo(eml); @@ -474,6 +510,16 @@ var et2_avatar = (function(){ "use strict"; return et2_image.extend( { this._buildEditableLayer(); } + if (this.options.crop) + { + var cropped = jQuery(this.image).cropper({ + aspectRatio: 1/1, + crop: function (e){ + console.log (e); + } + }); + + } } });}).call(this); diff --git a/api/templates/default/avatar_edit.xet b/api/templates/default/avatar_edit.xet new file mode 100644 index 0000000000..7387de1aa0 --- /dev/null +++ b/api/templates/default/avatar_edit.xet @@ -0,0 +1,22 @@ + + + + + + diff --git a/composer.json b/composer.json index f58bfebd23..d93f3cfb50 100644 --- a/composer.json +++ b/composer.json @@ -31,6 +31,7 @@ "bower-asset/fastclick":"1.0.*", "bower-asset/jquery-touchswipe": "1.6.*", "bower-asset/jquery-ui":"=1.11.2", + "bower-asset/cropper":"2.3.*", "npm-asset/as-jqplot" : "1.0.*", "npm-asset/gridster":"0.5.*", "adldap2/adldap2": "=4.0.4" diff --git a/composer.lock b/composer.lock index e7fef8e1f8..7b34aecb32 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "9a74cc9727567f9100d4d1311228aede", - "content-hash": "d6ed8efbe2b9261641cf2d9ca9f1d01b", + "hash": "c53e37027e62153a377bb9adf13d2212", + "content-hash": "5e2d4def7fa91436952c7aef101d4023", "packages": [ { "name": "adldap2/adldap2", @@ -57,6 +57,64 @@ ], "time": "2016-07-14 18:11:24" }, + { + "name": "bower-asset/cropper", + "version": "v2.3.4", + "source": { + "type": "git", + "url": "https://github.com/fengyuanchen/cropper.git", + "reference": "30c58b29ee21010e17e58ebab165fbd84285c685" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/fengyuanchen/cropper/zipball/30c58b29ee21010e17e58ebab165fbd84285c685", + "reference": "30c58b29ee21010e17e58ebab165fbd84285c685", + "shasum": "" + }, + "type": "bower-asset-library", + "extra": { + "bower-asset-main": [ + "dist/cropper.js", + "dist/cropper.css" + ], + "bower-asset-ignore": [ + "**/.*", + "node_modules", + "bower_components", + "tests", + "test", + "examples", + "assets", + "demo", + "docs", + "gulpfile.js", + "CONTRIBUTING.md", + "ISSUE_TEMPLATE.md" + ] + }, + "license": [ + "MIT" + ], + "description": "A simple jQuery image cropping plugin.", + "keywords": [ + "crop", + "cropper", + "cropping", + "css", + "development", + "front-end", + "html", + "image", + "javascript", + "jquery", + "move", + "plugin", + "rotate", + "scale", + "web", + "zoom" + ] + }, { "name": "bower-asset/fastclick", "version": "v1.0.6",