aboutsummaryrefslogtreecommitdiffstats
path: root/templates/layerindex/editlayer.html
blob: e2350808f27c5818918917795f6c9468ad466079 (plain)
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
{% extends "base.html" %}
{% load i18n %}

{% comment %}

  layerindex-web - layer editing form page template

  Copyright (C) 2013 Intel Corporation
  Licensed under the MIT license, see COPYING.MIT for details

{% endcomment %}

<!--
{% block title_append %} - edit layer{% endblock %}
-->

{% block topfunctions %}
<!-- Remove submit link/tools drop-down added by base.html, otherwise clicking it may lose changes -->
{% endblock %}


{% block content %}
{% autoescape on %}

<div class="container-fluid">
    <div class="row-fluid">
        {% block heading %}
        <div class="page-header">
            <h1>Edit layer</h1>
        </div>
        {% endblock %}

{% block formtop %}
{% endblock %}
<form id="edit_layer_form" method="post">
{% csrf_token %}
    {% for hidden in form.hidden_fields %}
        {{ hidden }}
    {% endfor %}

    <div class="formfields">
        {% for field in form.visible_fields %}
            {% if field.name != 'captcha' %}
            {% if field.errors %}
            <div class="control-group alert alert-error">
            {{ field.errors }}
            {% else %}
            <div class="control-group">
            {% endif %}
                <div class="control-label">
                    {{ field.label_tag }}
                </div>
                <div class="controls">
                    {% if field.name == 'deps' %}
                        <div class="scrolling">
                            <table><tbody>
                                {% for deplayer in deplistlayers %}
                                    {% if deplayer.id in form.checked_deps %}
                                        <tr>
                                            <td class="checkboxtd"><input type="checkbox" name="deps" value="{{ deplayer.id }}" id="id_deps_{{forloop.counter}}" checked="checked" /></td>
                                            {% if deplayer.status == 'N' %}
                                            <td><label class="muted" for="id_deps_{{forloop.counter}}">{{ deplayer.name }} (unpublished)</label></td>
                                            {% else %}
                                            <td><label for="id_deps_{{forloop.counter}}">{{ deplayer.name }}</label></td>
                                            {% endif %}
                                        </tr>
                                    {% endif %}
                                {% endfor %}
                                {% for deplayer in deplistlayers %}
                                    {% if not deplayer.id in form.checked_deps %}
                                        <tr>
                                            <td class="checkboxtd"><input type="checkbox" name="deps" value="{{ deplayer.id }}" id="id_deps_{{forloop.counter}}" /></td>
                                            {% if deplayer.status == 'N' %}
                                            <td><label class="muted" for="id_deps_{{forloop.counter}}">{{ deplayer.name }} (unpublished)</label></td>
                                            {% else %}
                                            <td><label for="id_deps_{{forloop.counter}}">{{ deplayer.name }}</label></td>
                                            {% endif %}
                                        </tr>
                                    {% endif %}
                                {% endfor %}
                            </tbody></table>
                        </div>
                    {% else %}
                        {{ field }}
                    {% endif %}
                    <span class="help-inline custom-help">
                        {{ field.help_text }}
                    </span>
                </div>
            </div>
            {% endif %}
            {% if field.name == 'vcs_web_url' %}
                <div class="control-label">
                    Web interface type
                </div>
                <div class="controls">
                    <div class="formfield-div">
                        <select id="idx_vcs_web_type">
                        <option>(custom)</option>
                        <option>cgit</option>
                        <option>gitweb</option>
                        <option>gitlab</option>
                        </select>
                    </div>
                    <span class="help-inline custom-help">
                        Type of web interface (helps to auto-determine other URL fields)
                    </span>
                </div>
            {% endif %}
        {% endfor %}
    </div>
    <h3 id="maintainers">Maintainers</h3>
    {{ maintainerformset.non_form_errors }}
    {{ maintainerformset.management_form }}
    {% for maintainerform in maintainerformset %}
        <div class="maintainerform" id="maintainerform-{{forloop.counter0}}">
            <h4>Maintainer {{forloop.counter}}</h4>
            <div class="maintainerformfields">
                {% for hidden in maintainerform.hidden_fields %}
                    {{ hidden }}
                {% endfor %}

                {% for field in maintainerform.visible_fields %}
                    {% if field.errors %}
                    <div class="control-group alert alert-error">
                    {{ field.errors }}
                    {% else %}
                    <div class="control-group">
                    {% endif %}
                        <div class="control-label">
                            {{ field.label_tag }}
                        </div>
                        <div class="controls">
                            {{ field }}
                            <span class="help-inline custom-help">
                                {{ field.help_text }}
                            </span>
                        </div>
                    </div>
                {% endfor %}
            </div>
        </div>
    {% endfor %}
    <p><a href="#" class="btn btn-small" id="addanothermaintainer"><i class="icon-plus"></i>Add maintainer</a><p>


    {% if form.captcha %}
        <div class="captchafield">
            <h3>Verification</h3>
            {% if form.captcha.errors %}
            <div class="control-group alert alert-error">
            {{ form.captcha.errors }}
            {% else %}
            <div class="control-group">
            {% endif %}
                <div class="controls">
                    {{ form.captcha }}
                    <span class="help-inline custom-help">
                        {{ form.captcha.help_text }}
                    </span>
                </div>
            </div>
        </div>
    {% endif %}

<div class="submitbuttons">
{% block submitbuttons %}
<input type="submit" value="Save layer" class="btn btn-primary btn-large submitbutton" />
<a href="{{ return_url }}" class="btn btn-large">Cancel</a>
{% endblock %}
</div>
</form>

    </div>
</div>

{% endautoescape %}

{% endblock %}

{% block scripts %}
<script>
    if (typeof String.prototype.startsWith != 'function') {
        String.prototype.startsWith = function (str){
            return this.slice(0, str.length) == str;
        };
    }

    function AutoWebFields(repoval) {
        // Auto-determine web interface URLs from repo URL
        if( repoval[repoval.length-1] == '/' )
            repoval = repoval.slice(0, repoval.length-1)

        if( repoval.startsWith('git://git.openembedded.org/') ) {
            reponame = repoval.replace(/^.*\//, '')
            this.vcs_web_url = 'http://cgit.openembedded.org/' + reponame
            this.vcs_web_tree_base_url = 'http://cgit.openembedded.org/' + reponame + '/tree/%path%?h=%branch%'
            this.vcs_web_file_base_url = 'http://cgit.openembedded.org/' + reponame + '/tree/%path%?h=%branch%'
            this.vcs_web_type = 'cgit'
        }
        else if( repoval.indexOf('git.yoctoproject.org/') > -1 ) {
            reponame = repoval.replace(/^.*\//, '')
            this.vcs_web_url = 'http://git.yoctoproject.org/cgit/cgit.cgi/' + reponame
            this.vcs_web_tree_base_url = 'http://git.yoctoproject.org/cgit/cgit.cgi/' + reponame + '/tree/%path%?h=%branch%'
            this.vcs_web_file_base_url = 'http://git.yoctoproject.org/cgit/cgit.cgi/' + reponame + '/tree/%path%?h=%branch%'
            this.vcs_web_type = 'cgit'
        }
        else if( repoval.indexOf('github.com/') > -1 ) {
            reponame = repoval.replace(/^.*github.com\//, '')
            reponame = reponame.replace(/.git$/, '')
            this.vcs_web_url = 'http://github.com/' + reponame
            this.vcs_web_tree_base_url = 'http://github.com/' + reponame + '/tree/%branch%/'
            this.vcs_web_file_base_url = 'http://github.com/' + reponame + '/blob/%branch%/'
            this.vcs_web_type = '(custom)'
        }
        else if( repoval.indexOf('bitbucket.org/') > -1 ) {
            reponame = repoval.replace(/^.*bitbucket.org\//, '')
            reponame = reponame.replace(/.git$/, '')
            this.vcs_web_url = 'http://bitbucket.org/' + reponame
            this.vcs_web_tree_base_url = 'http://bitbucket.org/' + reponame + '/src/%branch%/%path%?at=%branch%'
            this.vcs_web_file_base_url = 'http://bitbucket.org/' + reponame + '/src/%branch%/%path%?at=%branch%'
            this.vcs_web_type = '(custom)'
        }
        else {
            this.vcs_web_url = ''
            this.vcs_web_tree_base_url = ''
            this.vcs_web_file_base_url = ''
            this.vcs_web_type = '(custom)'
        }
    };

    auto_web_url_field = function (e) {
        // Auto-determine web interface type from URL
        vcs_web_url = $('#id_vcs_web_url').val()
        if ( vcs_web_url.indexOf('/cgit.cgi/') > -1 || vcs_web_url.indexOf('/cgit/') > -1 ) {
            $('#idx_vcs_web_type').val('cgit')
            auto_web_type_field(e)
        }
        else if ( vcs_web_url.indexOf('a=summary') > -1 ) {
            $('#idx_vcs_web_type').val('gitweb')
            auto_web_type_field(e)
        }
    }

    auto_web_type_field = function (e) {
        // Auto-determine web interface tree/file URLs based on type
        type = $('#idx_vcs_web_type').val()
        if (type == '(custom)') {
            readonly = $('#idx_vcs_web_type').prop('disabled')
            $('#id_vcs_web_tree_base_url').prop('readonly', readonly)
            $('#id_vcs_web_file_base_url').prop('readonly', readonly)
        }
        else {
            $('#id_vcs_web_tree_base_url').prop('readonly', true)
            $('#id_vcs_web_file_base_url').prop('readonly', true)
            vcs_web_url = $('#id_vcs_web_url').val()
            if (vcs_web_url) {
                if (vcs_web_url.endsWith('/')) {
                    vcs_web_url = vcs_web_url.slice(0, -1)
                }
                if (type == 'cgit') {
                    $('#id_vcs_web_tree_base_url').val('readonly', true)
                    $('#id_vcs_web_file_base_url').prop('readonly', true)
                    if (e) {
                        $('#id_vcs_web_tree_base_url').val(vcs_web_url + '/tree/%path%?h=%branch%')
                        $('#id_vcs_web_file_base_url').val(vcs_web_url + '/tree/%path%?h=%branch%')
                    }
                }
                else if (type == 'gitweb') {
                    $('#id_vcs_web_tree_base_url').val('readonly', true)
                    $('#id_vcs_web_file_base_url').prop('readonly', true)
                    if (e) {
                        spliturl = vcs_web_url.split('?')
                        if (spliturl.length > 1) {
                            params = spliturl[1].split(';')
                            newparams = []
                            for (i = 0; i < params.length; i++) {
                                if (!params[i].startsWith('a=')) {
                                    newparams.push(params[i])
                                }
                            }
                            newparamsstr = newparams.join(';')
                            if( newparamsstr ) {
                                newparamsstr += ';'
                            }
                            vcs_web_url = spliturl[0] + '?' + newparamsstr
                        }
                        else {
                            vcs_web_url = spliturl[0] + '?'
                        }
                        $('#id_vcs_web_tree_base_url').val(vcs_web_url + 'a=tree;f=%path%;hb=refs/heads/%branch%')
                        $('#id_vcs_web_file_base_url').val(vcs_web_url + 'a=blob;f=%path%;hb=refs/heads/%branch%')
                    }
                }
                else if (type == 'gitlab') {
                    $('#id_vcs_web_tree_base_url').val('readonly', true)
                    $('#id_vcs_web_file_base_url').prop('readonly', true)
                    if (e) {
                        $('#id_vcs_web_tree_base_url').val(vcs_web_url + '/tree/%branch%/%path%')
                        $('#id_vcs_web_file_base_url').val(vcs_web_url + '/blob/%branch%/%path%')
                    }
                }
            }
        }
    };

    auto_web_fields = function (e) {
        repoval = $('#id_vcs_url').val()
        awf = new AutoWebFields(repoval)
        if (awf.vcs_web_url) {
            if (e) {
                $('#id_vcs_web_url').val(awf.vcs_web_url)
                $('#id_vcs_web_tree_base_url').val(awf.vcs_web_tree_base_url)
                $('#id_vcs_web_file_base_url').val(awf.vcs_web_file_base_url)
                $('#idx_vcs_web_type').val(awf.vcs_web_type)
            }
            $('#id_vcs_web_url').prop('readonly', true);
            $('#idx_vcs_web_type').prop('disabled', true);
        }
        else {
            $('#id_vcs_web_url').prop('readonly', false);
            $('#idx_vcs_web_type').prop('disabled', false);
        }

        auto_web_type_field(e)
    };

    split_email = function() {
        // Split email name/email address pairs
        name_input = $(this)
        split_regex = /^"?([^"@$<>]+)"? *<([^<> ]+)>[ -]*(.*)?$/
        matches = split_regex.exec(name_input.val())
        if( matches ){
            name_input.val($.trim(matches[1]))
            email_id = name_input.attr('id').replace('-name', '-email')
            $('#' + email_id).val($.trim(matches[2]))
            resp_id = email_id.replace('-email', '-responsibility')
            currval = $('#' + resp_id).val()
            // Set the responsibility with the remainder of the value unless the user has entered a value for
            // responsibility already
            if( currval == window['last_' + resp_id] || currval == "" ) {
                newval = $.trim(matches[3])
                $('#' + resp_id).val(newval)
                window['last_' + resp_id] = newval
            }
        }
    }

    expand_maintainer = function() {
        for(i=0;i<{{ maintainerformset.total_form_count }};i++) {
            maintbox = $('#maintainerform-' + i)
            if( maintbox.is(':hidden') ) {
                maintbox.slideToggle();
                if( i == {{maintainerformset.total_form_count}} - 1 )
                    $('#addanothermaintainer').hide()
                break
            }
        }
        return false;
    }

    $(document).ready(function() {
        $('.maintainerform').hide()

        for(i=0;i<{{ maintainerformset.total_form_count }};i++) {
            name_input = $('#id_layermaintainer_set-' + i + '-name')
            name_input.change(split_email)
            resp_id = 'id_layermaintainer_set-' + i + '-responsibility'
            window['last_' + resp_id] = ""
            if( i==0 || name_input.val() )
                $('#maintainerform-' + i).show()
        }
        $('#addanothermaintainer').click(expand_maintainer)

        $('#id_vcs_url').change(auto_web_fields)
        $('#id_vcs_web_url').change(auto_web_url_field)
        $('#idx_vcs_web_type').change(auto_web_type_field)
        auto_web_fields(null)

        firstfield = $("#edit_layer_form input:text, #edit_layer_form textarea").first();
        if( ! firstfield.val() )
            firstfield.focus()
    });
</script>
{% endblock %}