View | Details | Raw Unified | Return to bug 27643
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/lib/codemirror/overlay.js (+90 lines)
Line 0 Link Here
1
// CodeMirror, copyright (c) by Marijn Haverbeke and others
2
// Distributed under an MIT license: https://codemirror.net/LICENSE
3
4
// Utility function that allows modes to be combined. The mode given
5
// as the base argument takes care of most of the normal mode
6
// functionality, but a second (typically simple) mode is used, which
7
// can override the style of text. Both modes get to parse all of the
8
// text, but when both assign a non-null style to a piece of code, the
9
// overlay wins, unless the combine argument was true and not overridden,
10
// or state.overlay.combineTokens was true, in which case the styles are
11
// combined.
12
13
(function(mod) {
14
  if (typeof exports == "object" && typeof module == "object") // CommonJS
15
    mod(require("../../lib/codemirror"));
16
  else if (typeof define == "function" && define.amd) // AMD
17
    define(["../../lib/codemirror"], mod);
18
  else // Plain browser env
19
    mod(CodeMirror);
20
})(function(CodeMirror) {
21
"use strict";
22
23
CodeMirror.overlayMode = function(base, overlay, combine) {
24
  return {
25
    startState: function() {
26
      return {
27
        base: CodeMirror.startState(base),
28
        overlay: CodeMirror.startState(overlay),
29
        basePos: 0, baseCur: null,
30
        overlayPos: 0, overlayCur: null,
31
        streamSeen: null
32
      };
33
    },
34
    copyState: function(state) {
35
      return {
36
        base: CodeMirror.copyState(base, state.base),
37
        overlay: CodeMirror.copyState(overlay, state.overlay),
38
        basePos: state.basePos, baseCur: null,
39
        overlayPos: state.overlayPos, overlayCur: null
40
      };
41
    },
42
43
    token: function(stream, state) {
44
      if (stream != state.streamSeen ||
45
          Math.min(state.basePos, state.overlayPos) < stream.start) {
46
        state.streamSeen = stream;
47
        state.basePos = state.overlayPos = stream.start;
48
      }
49
50
      if (stream.start == state.basePos) {
51
        state.baseCur = base.token(stream, state.base);
52
        state.basePos = stream.pos;
53
      }
54
      if (stream.start == state.overlayPos) {
55
        stream.pos = stream.start;
56
        state.overlayCur = overlay.token(stream, state.overlay);
57
        state.overlayPos = stream.pos;
58
      }
59
      stream.pos = Math.min(state.basePos, state.overlayPos);
60
61
      // state.overlay.combineTokens always takes precedence over combine,
62
      // unless set to null
63
      if (state.overlayCur == null) return state.baseCur;
64
      else if (state.baseCur != null &&
65
               state.overlay.combineTokens ||
66
               combine && state.overlay.combineTokens == null)
67
        return state.baseCur + " " + state.overlayCur;
68
      else return state.overlayCur;
69
    },
70
71
    indent: base.indent && function(state, textAfter) {
72
      return base.indent(state.base, textAfter);
73
    },
74
    electricChars: base.electricChars,
75
76
    innerMode: function(state) { return {state: state.base, mode: base}; },
77
78
    blankLine: function(state) {
79
      var baseToken, overlayToken;
80
      if (base.blankLine) baseToken = base.blankLine(state.base);
81
      if (overlay.blankLine) overlayToken = overlay.blankLine(state.overlay);
82
83
      return overlayToken == null ?
84
        baseToken :
85
        (combine && baseToken != null ? baseToken + " " + overlayToken : overlayToken);
86
    }
87
  };
88
};
89
90
});
(-)a/koha-tmpl/intranet-tmpl/lib/codemirror/overlay.min.js (+1 lines)
Line 0 Link Here
1
!function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],e):e(CodeMirror)}(function(e){"use strict";e.overlayMode=function(o,r,a){return{startState:function(){return{base:e.startState(o),overlay:e.startState(r),basePos:0,baseCur:null,overlayPos:0,overlayCur:null,streamSeen:null}},copyState:function(a){return{base:e.copyState(o,a.base),overlay:e.copyState(r,a.overlay),basePos:a.basePos,baseCur:null,overlayPos:a.overlayPos,overlayCur:null}},token:function(e,n){return(e!=n.streamSeen||Math.min(n.basePos,n.overlayPos)<e.start)&&(n.streamSeen=e,n.basePos=n.overlayPos=e.start),e.start==n.basePos&&(n.baseCur=o.token(e,n.base),n.basePos=e.pos),e.start==n.overlayPos&&(e.pos=e.start,n.overlayCur=r.token(e,n.overlay),n.overlayPos=e.pos),e.pos=Math.min(n.basePos,n.overlayPos),null==n.overlayCur?n.baseCur:null!=n.baseCur&&n.overlay.combineTokens||a&&null==n.overlay.combineTokens?n.baseCur+" "+n.overlayCur:n.overlayCur},indent:o.indent&&function(e,r){return o.indent(e.base,r)},electricChars:o.electricChars,innerMode:function(e){return{state:e.base,mode:o}},blankLine:function(e){var n,t;return o.blankLine&&(n=o.blankLine(e.base)),r.blankLine&&(t=r.blankLine(e.overlay)),null==t?n:a&&null!=n?n+" "+t:t}}}});
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt (-4 / +27 lines)
Lines 53-58 Link Here
53
    .CodeMirror {
53
    .CodeMirror {
54
        resize:  vertical;
54
        resize:  vertical;
55
    }
55
    }
56
    .cm-sqlParams {
57
        color: #11917B;
58
    }
56
    #mana_search_errortext { font-family: monospace; font-weight: bold; }
59
    #mana_search_errortext { font-family: monospace; font-weight: bold; }
57
</style>
60
</style>
58
[% Asset.css("css/reports.css") | $raw %]
61
[% Asset.css("css/reports.css") | $raw %]
Lines 1287-1293 Link Here
1287
                [% INCLUDE 'guided-reports-view.inc' %]
1290
                [% INCLUDE 'guided-reports-view.inc' %]
1288
            </aside>
1291
            </aside>
1289
        </div> <!-- /.col-sm-2.col-sm-pull-10 -->
1292
        </div> <!-- /.col-sm-2.col-sm-pull-10 -->
1290
     </div> <!-- /.row -->
1293
    </div> <!-- /.row -->
1291
1294
1292
[% MACRO jsinclude BLOCK %]
1295
[% MACRO jsinclude BLOCK %]
1293
    [% Asset.js("js/charts.js") | $raw %]
1296
    [% Asset.js("js/charts.js") | $raw %]
Lines 1299-1304 Link Here
1299
        [% INCLUDE 'columns_settings.inc' %]
1302
        [% INCLUDE 'columns_settings.inc' %]
1300
    [% END %]
1303
    [% END %]
1301
    [% Asset.js( "lib/codemirror/codemirror.min.js" ) | $raw %]
1304
    [% Asset.js( "lib/codemirror/codemirror.min.js" ) | $raw %]
1305
    [% Asset.js( "lib/codemirror/overlay.min.js" ) | $raw %]
1302
    [% Asset.js( "lib/codemirror/sql.min.js" ) | $raw %]
1306
    [% Asset.js( "lib/codemirror/sql.min.js" ) | $raw %]
1303
    [% Asset.js( "js/mana.js" ) | $raw %]
1307
    [% Asset.js( "js/mana.js" ) | $raw %]
1304
    <script>
1308
    <script>
Lines 1331-1336 Link Here
1331
            }
1335
            }
1332
        }
1336
        }
1333
1337
1338
        /* overlay a syntax-highlighting definition on top of the existing sql one */
1339
        CodeMirror.defineMode("sqlParams", function(config, parserConfig) {
1340
            var sqlParamsOverlay = {
1341
                token: function(stream, state) {
1342
                var ch;
1343
                if (stream.match("<<")) {
1344
                    while ((ch = stream.next()) != null)
1345
                    if (ch == ">" && stream.next() == ">") {
1346
                        stream.eat(">");
1347
                        return "sqlParams";
1348
                    }
1349
                }
1350
                while (stream.next() != null && !stream.match("<<", false)) {}
1351
                return null;
1352
                }
1353
            };
1354
            return CodeMirror.overlayMode(CodeMirror.getMode(config, parserConfig.backdrop || "text/x-sql"), sqlParamsOverlay);
1355
        });
1356
1334
        var MSG_CONFIRM_DELETE = _("Are you sure you want to delete this report? This cannot be undone.");
1357
        var MSG_CONFIRM_DELETE = _("Are you sure you want to delete this report? This cannot be undone.");
1335
        var group_subgroups = {};
1358
        var group_subgroups = {};
1336
        [% FOREACH group IN groups_with_subgroups %]
1359
        [% FOREACH group IN groups_with_subgroups %]
Lines 1344-1352 Link Here
1344
        [% END %]
1367
        [% END %]
1345
1368
1346
        [% IF ( create || editsql || save ) %]
1369
        [% IF ( create || editsql || save ) %]
1370
1347
            var editor = CodeMirror.fromTextArea(sql, {
1371
            var editor = CodeMirror.fromTextArea(sql, {
1348
                lineNumbers: true,
1372
                lineNumbers: true,
1349
                mode: "text/x-sql",
1373
                mode: "sqlParams", /* text/x-sql plus custom sqlParams configuration */
1350
                lineWrapping: true,
1374
                lineWrapping: true,
1351
                smartIndent: false
1375
                smartIndent: false
1352
            });
1376
            });
Lines 1368-1374 Link Here
1368
        [% IF ( showsql ) %]
1392
        [% IF ( showsql ) %]
1369
            var editor = CodeMirror.fromTextArea(sql, {
1393
            var editor = CodeMirror.fromTextArea(sql, {
1370
                lineNumbers: false,
1394
                lineNumbers: false,
1371
                mode: "text/x-sql",
1395
                mode: "sqlParams", /* text/x-sql plus custom sqlParams configuration */
1372
                lineWrapping: true,
1396
                lineWrapping: true,
1373
                readOnly: true
1397
                readOnly: true
1374
            });
1398
            });
1375
- 

Return to bug 27643