Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

# -*- coding: UTF-8 -*- 

# Copyright 2015 Luc Saffre 

# License: BSD (see file COPYING for details) 

 

"""Adds usage of the TinyMCE editor instead of Ext.form.HtmlEditor for 

RichTextFields.  See also :attr:`tinymce_root`.  See 

`/blog/2011/0523`.  (formerly `use_tinymce`). 

 

""" 

 

from lino.api import ad 

 

 

#TINYMCE_VERSION = '3.4.8' 

TINYMCE_VERSION = '3.5.11' 

#TINYMCE_VERSION = '4.1.10' 

 

"""Which version of TinyMCE to use. 

 

With 4.1.10, windows containing a TextField don't open, and the JS 

console says "TypeError: sp is undefined". That's because we did not 

yet get Andrew Mayorov's 

:srcref:`lino/modlib/tinymce/static/byteforce/Ext.ux.TinyMCE.js` to 

work with TinyMCE 4.  It seems that either ControlManager or 

WindowManager no longer are functions in tinymce4. 

 

""" 

 

 

def javascript(url): 

    return '<script type="text/javascript" src="{0}"></script>'.format(url) 

 

 

class Plugin(ad.Plugin): 

    "See :doc:`/dev/plugins`." 

 

    needs_plugins = ['lino.modlib.office']  # because of TextFieldTemplate 

 

    site_js_snippets = ['tinymce/tinymce.js'] 

 

    url_prefix = 'tinymce' 

 

    # window_width = 600 

    # window_height = 500 

 

    document_domain = None 

    """When serving static files from a different subdomain, TinyMCE needs 

    to know about this. Typical usage is to specify this in your 

    :file:`djangosite_local.py` file (:ref:`lino.djangosite_local`):: 

 

        def setup_site(self): 

            ... 

            from lino.api.ad import configure_plugin 

            configure_plugin('tinymce', document_domain="mydomain.com") 

 

    Currently when using this, **you must also manually change** your 

    static `tiny_mce_popup.js` file after each `collectstatic`. 

 

    """ 

 

    window_width = 500 

    """The initial width of the window to use when editing in own 

    window. 

 

    """ 

 

    window_height = 400 

    """The initial height of the window to use when editing in own 

    window. 

 

    """ 

 

    field_buttons = ( 

        "bold,italic,underline,|,justifyleft,justifycenter,justifyright,|," 

        "bullist,numlist,|,outdent,indent,|,undo,redo,|,removeformat,template") 

    """The toolbar buttons when editing a field inside a detail form.""" 

 

    window_buttons1 = ( 

        "save,cancel,|,bold,italic,underline,|,justifyleft,justifycenter," 

        "justifyright,fontselect,fontsizeselect,formatselect,|," 

        "search,replace") 

    """The first row of toolbar buttons when editing in own window.""" 

    window_buttons2 = ( 

        "cut,copy,paste,template,|,bullist,numlist,|,outdent,indent,|," 

        "undo,redo,|,link,unlink,anchor,image,|,code,preview,|,forecolor," 

        "backcolor") 

    """The second row of toolbar buttons when editing in own window.""" 

 

    window_buttons3 = ( 

        "insertdate,inserttime,|,spellchecker,advhr,,removeformat,|," 

        "sub,sup,|,charmap,emotions,|,tablecontrols") 

    """The third row of toolbar buttons when editing in own window.""" 

 

    media_name = 'tinymce-' + TINYMCE_VERSION 

    """Lino currently includes three versions of TinyMCE, but for 

    production sites we still use the eldest version 3.4.8. 

 

    """ 

 

    media_root = None 

    # media_base_url = "http://www.tinymce.com/js/tinymce/jscripts/tiny_mce/" 

    # media_base_url = "http:////tinymce.cachefly.net/4.1/tinymce.min.js" 

 

    def get_used_libs(self, html=False): 

        if html is not None: 

            yield ("TinyMCE", TINYMCE_VERSION, "http://www.tinymce.com/") 

            yield ("Ext.ux.TinyMCE", '0.8.4', "http://www.byte-force.com") 

 

    def get_js_includes(self, settings, language): 

        if TINYMCE_VERSION.startswith('3'): 

            yield self.build_lib_url('tiny_mce.js') 

        else: 

            yield self.build_lib_url('tinymce.min.js') 

        yield settings.SITE.build_static_url("byteforce", "Ext.ux.TinyMCE.js") 

 

    def get_patterns(self): 

        from django.conf.urls import url 

        from . import views 

 

        rx = '^' 

 

        urlpatterns = [ 

            url(rx + r'templates/(?P<app_label>\w+)/' 

                + r'(?P<actor>\w+)/(?P<pk>\w+)/(?P<fldname>\w+)$', 

                views.Templates.as_view()), 

            url(rx + r'templates/(?P<app_label>\w+)/' 

                + r'(?P<actor>\w+)/(?P<pk>\w+)/(?P<fldname>\w+)/' 

                + r'(?P<tplname>\w+)$', 

                views.Templates.as_view())] 

 

        return urlpatterns 

 

    def get_row_edit_lines(self, e, panel): 

        from lino.modlib.extjs.elems import TextFieldElement 

        if isinstance(e, TextFieldElement): 

            if e.format == 'html': 

                yield "%s.refresh();" % e.as_ext() 

 

    def setup_config_menu(self, site, profile, m): 

        if site.user_model is not None: 

            mg = site.plugins.office 

            m = m.add_menu(mg.app_label, mg.verbose_name) 

            m.add_action('tinymce.MyTextFieldTemplates') 

 

    def setup_explorer_menu(self, site, profile, m): 

        if site.user_model is not None: 

            mg = site.plugins.office 

            m = m.add_menu(mg.app_label, mg.verbose_name) 

            m.add_action('tinymce.TextFieldTemplates')