zoukankan      html  css  js  c++  java
  • 如何使用SAP CRM WebClient UI实现一个类似新浪微博的字数统计器

    In the blog we talk about the social media integration into CRM Interaction center agent inbox, which allows end users to directly reply facebook posts & tweets in CRM system. In order to achieve this we implement a very simple character counter which has similar functionality as that in twitter website:

    The counter described in this blog is delivered by SAP in CRM 7.0 EHP3. You can find it in UI component SMCOV, view ReplyMessageView.htm. Its function is slightly different from twitter: it does not display the left number of characters which is allowed to input, but the number of characters which are ALREADY typed by end user.

    The following functionalities are supported by this simple counter:

    (1) Whenever you add, delete or change your input in text area, the number of characters you have typed will be automatically updated below the text area

    (2) The cut & paste event are also captured by the counter
    Any other advanced functionalities like url automatically highlighted as hyperlink is not supported by this simple counter.

    Here below is the implementation of this counter:

    (1) In your UI component view, draw the visual area of the counter which will show the text “The number of characters entered:XXX” via html p tag:

    <p id="COUNTER_TXT"  style="margin-left: 8px; margin-top: 1px; margin-bottom: 4px; margin-right: 8px; color:rgb(102,102,102)"></p>
    

    (2) in line 32, the function handleClick acts as the event handler which will be called automatically whenever the content in the text area is changed.
    In line 34 the final text in the visual area of the counter is populated.

    For translation purpose, the text is not hard-coded but stored and got in Online Text Repository:

    lv_title_prefix = cl_wd_utilities=>get_otr_text_by_alias( 'CRM_UIU_SOC_SMC/COUNTER_TXT' ). "#EC NOTEXT. 
    
    lv_title_prefix = lv_title_prefix && ':'.
    
    

    In line 35 the current number of characters is updated in the visual area of the counter. The variable counter is a DOM variable which represents the html tag p with ID COUNTER_TXT, which is retrieved later.

    The function fillTitle is designed to ensure the counter still displays the correct number of typed characters in text area when the UI is rendered for the first time ( at that time no event for the text area will be fired ).
    Here the biggest challenge is how to get the ID of the text area, so that we can use document.getElementByID to get its DOM node and then get the actual content which has been typed in the text area.

    As this text area is not manually created via native HTML code, it is impossible to get its ID directly in the view.

    However, we could investigate on the naming convention of this ID via development tool ( just click F12 on web page) of IE.
    Click Find->Select element by click, then click on the text area, and development tool will automatically locate the native html textarea element, and then we can observe that the naming convention for it is <component_id>_socialpost_struct.content.

    The current component id is available in the attribute component id of view controller, so finally we can populate the ID of text area via the following code:

    (3) The left code is very easy to understand: retrieve the DOM node for input textarea ( line 47) and visual area of counter( line 48), and register the event handler for three events on text area element.

    要获取更多Jerry的原创文章,请关注公众号"汪子熙":

  • 相关阅读:
    String StringBuffer StringBuilder 三者的区别
    叶正盛:再次写给我们这些浮躁的程序员
    ubuntu中eclipse无法识别android手机问题
    Android 源代码结构
    sqlite3_open_v2(“/data/data/com.android.packagename/databases/dump.sqlite”, &handle, 1, NULL) failed
    新浪天气预报API
    在Android上常用的定时器 AlarmManager
    [转]#ifdef __cplusplus与extern "C"的解释
    [转]char *p="1234567890"以及C/C++的内存
    C语言中,为什么字符串可以赋值给字符指针变量
  • 原文地址:https://www.cnblogs.com/sap-jerry/p/13619043.html
Copyright © 2011-2022 走看看