From 01438f60ebad3d2382d478add4058ddb8090aae5 Mon Sep 17 00:00:00 2001 From: nathangray Date: Thu, 21 Sep 2017 14:56:40 -0600 Subject: [PATCH] Add timestamp button widget, use it in infolog --- api/js/etemplate/et2_widget_timestamper.js | 168 +++++++++++++++++++++ api/js/etemplate/etemplate2.js | 1 + api/templates/default/images/timestamp.png | Bin 0 -> 1238 bytes infolog/js/app.js | 89 +---------- infolog/templates/default/edit.xet | 2 +- pixelegg/images/timestamp.png | Bin 0 -> 3057 bytes 6 files changed, 173 insertions(+), 87 deletions(-) create mode 100644 api/js/etemplate/et2_widget_timestamper.js create mode 100644 api/templates/default/images/timestamp.png create mode 100644 pixelegg/images/timestamp.png diff --git a/api/js/etemplate/et2_widget_timestamper.js b/api/js/etemplate/et2_widget_timestamper.js new file mode 100644 index 0000000000..5016a7c87a --- /dev/null +++ b/api/js/etemplate/et2_widget_timestamper.js @@ -0,0 +1,168 @@ +/** + * EGroupware eTemplate2 - JS Timestamp button object + * + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @package etemplate + * @subpackage api + * @link http://www.egroupware.org + * @author Nathan Gray + * @copyright Nathan Gray 2017 + */ + +/*egw:uses + et2_button; +*/ + +/** + * Class which implements the "button-timestamper" XET-Tag + * + * Clicking the button puts the current time and current user at the end of + * the provided field. + * + * @augments et2_button + */ +var et2_timestamper = (function(){ "use strict"; return et2_button.extend([], +{ + attributes: { + target: { + name: "Target field", + type: "string", + default: et2_no_init, + description: "Which field to place the timestamp in" + }, + image: { + default: "timestamp" + }, + background_image: { + default: true + } + }, + + /** + * Constructor + * + * @memberOf et2_button + */ + init: function() { + this._super.apply(this, arguments); + }, + + /** + * Overwritten to maintain an internal clicked attribute + * + * @param _ev + * @returns {Boolean} + */ + click: function(_ev) { + // ignore click on readonly button + if (this.options.readonly) return false; + + this._insert_text(); + + if (!this._super.apply(this, arguments)) + { + return false; + } + + return true; + }, + + _insert_text: function() { + var text = ""; + var now = new Date(); + text += date(egw.preference('dateformat') + ' ' + (egw.preference("timeformat") === "12" ? "h:ia" : "H:i")+' ',now); + + // Get properly formatted user name + var user = parseInt(egw.user('account_id')); + var accounts = egw.accounts('accounts'); + for(var j = 0; j < accounts.length; j++) + { + if(accounts[j].value === user) + { + text += accounts[j].label; + break; + } + } + text += ': '; + + var input = this._get_input(this.target); + var scrollPos = input.scrollTop; + var browser = ((input.selectionStart || input.selectionStart == "0") ? + "standards" : (document.selection ? "ie" : false ) ); + + var pos = 0; + + // Find cursor or selection + if (browser == "ie") + { + input.focus(); + var range = document.selection.createRange(); + range.moveStart ("character", -input.value.length); + pos = range.text.length; + } + else if (browser == "standards") + { + pos = input.selectionStart; + }; + + // Insert the text + var front = (input.value).substring(0, pos); + var back = (input.value).substring(pos, input.value.length); + input.value = front+text+back; + + // If CKEDitor, update it + if(CKEDITOR && CKEDITOR.instances[input.id]) + { + window.setTimeout(function() { + CKEDITOR.instances[input.id].focus(); + }, 10); + } + else + { + // Clean up a little + pos = pos + text.length; + if (browser == "ie") { + input.focus(); + var range = document.selection.createRange(); + range.moveStart ("character", -input.value.length); + range.moveStart ("character", pos); + range.moveEnd ("character", 0); + range.select(); + } + else if (browser == "standards") { + input.selectionStart = pos; + input.selectionEnd = pos; + input.focus(); + } + input.scrollTop = scrollPos; + } + }, + + _get_input: function _get_input(target) + { + var input = null; + var widget = null; + if(jQuery('#'+this.target).is('input')) + { + input = this.target; + } + else if (typeof target == 'string') + { + var widget = this.getRoot().getWidgetById(target); + } + else if (target.instanceOf && target.instanceOf(et2_IInput)) + { + widget = target; + } + if(widget) + { + input = widget.input ? widget.input : widget.getDOMNode(); + } + if(input.context) + { + input = input.get(0); + } + return input; + } +});}).call(this); +et2_register_widget(et2_timestamper, ["button-timestamp", "timestamper"]); \ No newline at end of file diff --git a/api/js/etemplate/etemplate2.js b/api/js/etemplate/etemplate2.js index 232cf7c741..25c415d4ca 100644 --- a/api/js/etemplate/etemplate2.js +++ b/api/js/etemplate/etemplate2.js @@ -38,6 +38,7 @@ et2_widget_htmlarea; et2_widget_tabs; et2_widget_taglist; + et2_widget_timestamper; et2_widget_toolbar; et2_widget_tree; et2_widget_historylog; diff --git a/api/templates/default/images/timestamp.png b/api/templates/default/images/timestamp.png new file mode 100644 index 0000000000000000000000000000000000000000..864811b6bea480004110d45237e84f396b4bf9ce GIT binary patch literal 1238 zcmV;{1S$K8P)u1)CyP6D@&AF+p1&g-90>s*9}ZuIQrR%8fg5 zC!*jJA6*r+A}N##sgESIQqbBOA)!%I+K@EEBsZ_lE0cRZ7x&KNW@a)|Y3a8)ch1~% zzyJAv|L^%{53jfa4fz~DXhH4J<(G~fs=}(NVRd4L=;glv4iC*ZqqhIf$(r^y zTKjsLJ^$Udf$V>87;W2ux%z!wwD%2g`{H>fzj&v>Ia(ve#Uv8c?cc-d^i4LLwUfZ8 z_TL+9>ggusIAxWz)p@?P_rFvymsp69n7>VYcFqfpajEOvO-AH8i?qF!^r~}zQ%)%m zA=FTt+fYtT;tTFRnzlSwt|!hqnSDxi6J@^{u|CRv&OGrLkmh+G~a zzHqAy0PXvCi!fj+kN@)ZYcxFaB>C()lfRYMpdSK{?X3XrLVzpRuOfLu5-~)tjF(SC zZG%$9vq19VQqIC2W-m=bEz!IG?ubdhQfh{s+6t_fVN6!fk@>cXzD(g z6%>FSj#ma;+kU&ui7;2##Z;690O5valF@lDt^D5Ke4vlTYnRG~02O4w&iM~Au(Pv^ zeaB7|YC{Aa3X@u0@@l)!-kyOWI$nIWpqRPII1?Yfl?wqnkZ}P9@@egT`}3l^5E0x| zg4vO8dFZ*9F&il^y*bF?FUQeV@lM(K%Io}l=3_4lvSoiO10sP$G@EI(9V+;kNpCQA z;spR^zR!Uie`A0{pI#^-K9wgzRjL$MmWJ96(f@woiRqb-eyF$`Qi_4Cj!HF@aD5Zc ze)cn)@pY`KYV7LTtR70HAD}H8g(@yWL_C%HHucrJG(6gaNvBIU$xIe(tNajiqi6kg zY_l1QA#M=>$*9AQmO852c9B?!Fh72d`SEl2_C%y@Qp*l*JXHW-cx~#&U_;klbXB-u z;q#|{{a+4$I{tLvcQP7bV`-7pN-T3x2_DN^`ktWv@rN;q1d=(!X$xg(?=YbhD2>({ zrERaaYYUzCthDXLTw7kuEgPk6lF%^u4OE+#DpyQ$m12aKDIuOPu@ z>7nz`i@y(*msFxMU4qS6jMTEj#?m6m=$(x7;KgJsh;ZXh>N - + diff --git a/pixelegg/images/timestamp.png b/pixelegg/images/timestamp.png new file mode 100644 index 0000000000000000000000000000000000000000..da67e09ae972fceaec44beaacf5d31ad55e5f057 GIT binary patch literal 3057 zcmaJ@3sh3s8b*{<(nLkG)Dchel2Vv-dqZ)y!S%cF$U8|L5Q9`@a9*|NhtBr!Y1q z${aZ#34_7R8PPx-WOdNnZ88fQeS(8eL1vzezCyN4lq$>ONI)2kCrSY^3;`z%i~~8m zoDEmNU>M90$B$njTftgF;fe&_oN0`Awm=NAVX)xPY%zzs4wPY1z%;&)iu>d2c^rn% zqv8_$SVWdM0!-&e=Ssk3xiRtF+;!X_9xgNl6P!(f1O%XrgUJ@G7fLDFRNRa%1^S+z zCg3nL5ZO8^?$4xFuwpS0A_<7`^Co(6iT*^4KgpX!_6-OK@Wl8KNkjtChd}c2A_Y*$ zJ`^Gm^Xb7s(ImW7N*oaRDHh~Wap^Ldm_i_AWo3D1k-bHdGy*9oC}>*4$Hxmocu8}F zGETOaQ0n|y0RW|3312MZi-eeIMNWz+Lq^3xnf|#1f%uE8Q2MD%P{9b<95I39O`KlR zXCRC9|DgiG7qnCs2mY1s{}h(S=ZHZ<94HlKNVw3(r8-ZC5>p~1AV(&W#EV4hKUXm} zT_h7p(?w!T#4tK8{U5Qw4304U*Sg1ktHNPwAH zGKK&3T*AMq_le8zV6b)LdJOl`r4PyoT0n3jw@pRP!||RA5>QW8<**?Xx`5 z6#%Oa1!!h(p#Q_G24!=wBf7+K+c0I)SQJrf_T(5PNenU)WAWM$VX}F_nXm5LN zy|PCqdAVxCA=&;W{gPglLVujI=k@TtI_`z`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