示例#1
0
def main(j, args, params, tags, tasklet):

    params.result = page = args.page
    userguid = args.getTag('guid')
    if not userguid:
        raise exceptions.BadRequest("BadRequest", "text/plain")
    scl = j.clients.osis.getNamespace('system')
    user = scl.user.get(userguid)

    popup = Popup(id='user_edit',
                  header='Update User',
                  submit_url='/restmachine/system/usermanager/editUser',
                  clearForm=False)

    options = list()
    popup.addText(
        'Enter Email Address',
        'emails',
        value=', '.join(user.emails),
        placeholder='If left empty, email address will not be changed')
    popup.addHiddenField('domain', user.domain)
    popup.addText('Enter Password',
                  'password',
                  type='password',
                  placeholder='If left empty, password will not be changed')
    for group in scl.group.search({})[1:]:
        available = group['id'] in user.groups
        options.append((group['id'], group['id'], available))

    popup.addCheckboxes('Select Groups', 'groups', options)
    popup.addHiddenField('username', user.id)
    popup.write_html(page)

    return params
示例#2
0
def main(j, args, params, tags, tasklet):
    #import ipdb; ipdb.set_trace()
    params.result = page = args.page
    reload = 'noreload' not in args.tags.labels
    scl = j.clients.osis.getNamespace('system')

    popup = Popup(id='createuser',
                  header='Create User',
                  submit_url='/restmachine/cloudbroker/user/create',
                  reload_on_success=reload)

    options = list()
    popup.addText('Enter Username', 'username')
    popup.addText('Enter Email Address', 'emailaddress')
    popup.addHiddenField('domain', '')
    popup.addText(
        'Enter Password',
        'password',
        type='password',
        placeholder='If left empty, a random password will be generated')
    for group in scl.group.search({})[1:]:
        options.append((group['id'], group['id'], False))

    popup.addCheckboxes('Select Groups', 'groups', options)
    popup.write_html(page)

    return params
示例#3
0
def main(j, args, params, tags, tasklet):

    params.result = page = args.page
    groupguid = args.getTag('guid')
    if groupguid is None:
        raise exceptions.BadRequest("BadRequest", "text/plain")
    scl = j.clients.osis.getNamespace('system')
    group = None
    guidExists = scl.group.search({'id': groupguid})[1:]
    if guidExists:
        group = scl.group.get(groupguid)
    if not group:
        return params
    popup = Popup(id='group_edit', header='Change Group', clearForm=False, submit_url='/restmachine/system/usermanager/editGroup')

    options = list()
    popup.addText('Enter domain', 'domain', value=group.domain)
    popup.addText('Enter description', 'description', value=group.description)
    for user in scl.user.search({})[1:]:
        available = user['id'] in group.users
        options.append((user['id'], user['id'], available))
    popup.addCheckboxes('Select Users', 'users', options)
    popup.addHiddenField('name', group.id)
    popup.write_html(page)

    return params
示例#4
0
def main(j, args, params, tags, tasklet):
    # import ipdb; ipdb.set_trace()
    params.result = page = args.page
    reload = "noreload" not in args.tags.labels
    scl = j.clients.osis.getNamespace("system")

    popup = Popup(
        id="createuser",
        header="Create User",
        submit_url="/restmachine/cloudbroker/user/create",
        reload_on_success=reload,
    )

    options = list()
    popup.addText("Enter Username", "username")
    popup.addText("Enter Email Address", "emailaddress")
    popup.addHiddenField("domain", "")
    popup.addText(
        "Enter Password",
        "password",
        type="password",
        placeholder="If left empty, a random password will be generated",
    )
    for group in scl.group.search({})[1:]:
        options.append((group["id"], group["id"], False))

    popup.addCheckboxes("Select Groups", "groups", options)
    popup.write_html(page)

    return params
示例#5
0
def main(j, args, params, tags, tasklet):

    params.result = page = args.page
    userguid = args.getTag('guid')
    if not userguid:
        raise exceptions.BadRequest("BadRequest", "text/plain")
    scl = j.clients.osis.getNamespace('system')
    user = scl.user.get(userguid)

    popup = Popup(id='user_edit', header='Update User',
                  submit_url='/restmachine/system/usermanager/editUser', clearForm=False)

    options = list()
    popup.addText('Enter Email Address', 'emails', value=', '.join(user.emails),
                  placeholder='If left empty, email address will not be changed')
    popup.addHiddenField('domain', user.domain)
    popup.addText('Enter Password', 'password', type='password',
                  placeholder='If left empty, password will not be changed')
    for group in scl.group.search({})[1:]:
        available = group['id'] in user.groups
        options.append((group['id'], group['id'], available))

    popup.addCheckboxes('Select Groups', 'groups', options)
    popup.addHiddenField('username', user.id)
    popup.write_html(page)

    return params
def main(j, args, params, tags, tasklet):
    params.result = page = args.page
    imageId = args.getTag("imageId")
    try:
        imageId = int(imageId)
    except ValueError:
        return params
    ccl = j.clients.osis.getNamespace("cloudbroker")
    image = {"id": imageId}

    popup = Popup(
        id="image_update_cpu_nodes",
        header="Image Availability",
        submit_url="/restmachine/cloudbroker/image/updateNodes",
    )

    options = list()
    for stack in ccl.stack.search({})[1:]:
        available = image["id"] in stack.get("images", [])
        options.append((stack["name"], stack["id"], available))

    popup.addCheckboxes(
        "Select the Stacks you want to make this Image available on",
        "enabledStacks",
        options,
    )
    popup.addHiddenField("imageId", imageId)
    popup.write_html(page)

    return params
示例#7
0
def main(j, args, params, tags, tasklet):
    params.result = page = args.page
    imageId = args.getTag('imageId')
    try:
        imageId = int(imageId)
    except ValueError:
        return params
    ccl = j.clients.osis.getNamespace('cloudbroker')
    image = {'id': imageId}

    popup = Popup(id='image_update_cpu_nodes',
                  header='Image Availability',
                  submit_url='/restmachine/cloudbroker/image/updateNodes')

    options = list()
    for stack in ccl.stack.search({})[1:]:
        available = image['id'] in stack.get('images', [])
        options.append((stack['name'], stack['id'], available))

    popup.addCheckboxes(
        'Select the Stacks you want to make this Image available on',
        'enabledStacks', options)
    popup.addHiddenField('imageId', imageId)
    popup.write_html(page)

    return params
def main(j, args, params, tags, tasklet):
    params.result = page = args.page

    pars = args.expandParamsAsDict()

    page.addMessage('<a href="#{0}" role="button" class="btn" data-toggle="modal">Launch demo modal {0}</a>'.format(pars['id']))

    popup = Popup(id=pars['id'], header='Text popup', submit_url=pars['submit_url'])
    popup.addHiddenField('hidden_field', 'hidden_value')
    popup.addText('First name', 'firstname', required=True)
    popup.addNumber('Age', 'age')
    popup.addDropdown('Choose licence', 'license', [('MIT', 'mit'), ('BSD', 'bsd'), ('GPL version 3', 'gpl3')])
    popup.addRadio('Choose licence', 'license2', [('MIT', 'mit'), ('BSD', 'bsd'), ('GPL version 3', 'gpl3')])
    popup.addCheckboxes('Choose the software', 'software', [('MS Office', 'msoffice'), ('Photoshop', 'photoshop')])
    popup.write_html(page)

    return params
def main(j, args, params, tags, tasklet):

    params.result = page = args.page
    reload = 'noreload' not in args.tags.labels
    scl = j.clients.osis.getNamespace('system')

    popup = Popup(id='user_create', header='Create User', submit_url='/restmachine/system/usermanager/create', reload_on_success=reload)

    options = list()
    popup.addText('Enter Username', 'username')
    popup.addText('Enter Email Address', 'emails')
    popup.addHiddenField('domain', '')
    popup.addText('Enter Password', 'password', type='password',
                  placeholder='If left empty, a random password will be generated')
    for group in scl.group.search({})[1:]:
        options.append((group['id'], group['id'], False))

    popup.addCheckboxes('Select Groups', 'groups', options)
    popup.write_html(page)

    return params
示例#10
0
def main(j, args, params, tags, tasklet):

    params.result = page = args.page
    reload = 'noreload' not in args.tags.labels

    popup = Popup(
        id='user_create',
        header='Create User',
        submit_url='/restmachine/system/usermanager/create',
        reload_on_success=reload)

    options = list()
    popup.addText('Enter Username', 'username')
    popup.addText('Enter Emails (comma seperated)', 'emails')
    popup.addHiddenField('domain', '')
    popup.addText('Enter Password', 'password', type='password')
    for group in j.data.models.system.Group.find({}):
        options.append((group['name'], group['name'], False))

    popup.addCheckboxes('Select Groups', 'groups', options)
    popup.write_html(page)

    return params
示例#11
0
def main(j, args, params, tags, tasklet):

    params.result = page = args.page
    groupid = args.getTag('id')
    group = j.data.models.system.Group.get(groupid)
    if not group:
        params.result = ('group with id %s not found' % groupid, args.doc)
        return params

    popup = Popup(id='group_edit', header='Change Group', clearForm=False,
                  submit_url='/restmachine/system/usermanager/editGroup')

    options = list()
    popup.addText('Enter domain', 'domain', value=group.domain)
    popup.addText('Enter description', 'description', value=group.description)
    for user in j.data.models.system.User.find({}):
        available = user['id'] in [u['id'] for u in j.data.models.system.User.find({'groups': group['name']})]
        options.append((user['name'], user['name'], available))

    popup.addCheckboxes('Select Users', 'users', options)
    popup.addHiddenField('name', group.name)
    popup.write_html(page)

    return params
示例#12
0
def main(j, args, params, tags, tasklet):

    params.result = page = args.page
    userid = args.getTag('id')
    user = j.data.models.system.User.get(userid)
    if not user:
        params.result = ('User with id %s not found' % userid, args.doc)
        return params

    popup = Popup(id='user_edit', header='Change User', submit_url='/restmachine/system/usermanager/editUser')

    options = list()
    popup.addText('Enter emails (comma seperated)', 'emails', value=', '.join(user.emails))
    popup.addHiddenField('domain', user.domain)
    popup.addText('Enter Password (leave empty to unchange)', 'password', type='password')
    for group in j.data.models.system.Group.find({}):
        available = group['name'] in user.groups
        options.append((group['name'], group['name'], available))

    popup.addCheckboxes('Select Groups', 'groups', options)
    popup.addHiddenField('username', user.name)
    popup.write_html(page)

    return params
示例#13
0
def main(j, args, params, tags, tasklet):
    page = args.page
    from JumpScale.portal.docgenerator.popup import Popup
    import yaml

    def _showexample():
        page.addMessage("""Actions must be in yaml form.
eg:
- display: Start
  action: /restmachine/cloudbroker/machine/start
  input:
  - reason
  - spacename
  - name: accesstype
    type: dropdown
    label: ACL
    values:
     - label: Admin
       value: ARCXDU
     - label: Write
       value: RCX
     - label: Read
       value: R

  data:
   machineId: $$id
   accountName: $$accountname

- display: Stop
  action: /restmachine/cloudbroker/machine/stop?machineId=$$id&reason=ops&accountName=$$accountname&spaceName=$$spacename
}}
""")
        params.result = page
        return params

    macrostr = args.macrostr.strip()
    title = args.getTag('title', 'Action')
    gridbinding = args.getTag('gridbinding', '').split()
    content = "\n".join(macrostr.split("\n")[1:-1])

    if not content:
        return _showexample()

    actionoptions = []
    actions = yaml.load(content)
    if actions == content:
        return _showexample()

    if not isinstance(actions, list):
        actions = [actions]

    for actiondata in actions:
        actionurl = actiondata['action']
        display = actiondata['display']
        inputs = actiondata.get('input', '')
        navigateback = actiondata.get('navigateback', False)
        reload = actiondata.get('reload', True)
        clearForm = actiondata.get('clearform', True)
        hide = actiondata.get('hide', False)
        data = actiondata.get('data', {})
        showresponse = actiondata.get('showresponse', False)
        hideon = actiondata.get('hideon', [])
        if hideon:
            hideon_input = actiondata.get('hideonInput', '')
            if hideon_input in hideon:
                continue

        action = "$('%s').modal('show');"

        if actionurl.startswith("#"):
            actionoptions.append((display, action % actionurl))
            continue
        else:
            actionid = "action-%s" % display.replace(' ', '')
            if not hide:
                actionoptions.append((display, action % ('#' + actionid)))

        popup = Popup(id=actionid,
                      header="Confirm Action %s" % display,
                      submit_url=actionurl,
                      navigateback=navigateback,
                      reload_on_success=reload,
                      showresponse=showresponse,
                      clearForm=clearForm,
                      gridbinding=gridbinding)
        if inputs:
            for var in inputs:
                if isinstance(var, basestring):
                    popup.addText(var, var)
                else:
                    if var['type'] in ('dropdown', 'radio'):
                        label = var['label']
                        name = var['name']
                        options = list()
                        for value in var['values']:
                            options.append((value['label'], value['value']))
                        if var['type'] == 'dropdown':
                            popup.addDropdown(label, name, options)
                        elif var['type'] == 'checkboxes':
                            popup.addCheckboxes(label, name, options)
                        elif var['type'] == 'radio':
                            popup.addRadio(label, name, options)
                    elif var['type'] in ('text', 'password', 'number',
                                         'float'):
                        label = var['label']
                        name = var['name']
                        default = var.get('default', '')
                        placeholder = var.get('placeholder', '')
                        if var['type'] == 'float':
                            popup.addText(label,
                                          name,
                                          type='number',
                                          value=default,
                                          placeholder=placeholder,
                                          step="0.1")
                        else:
                            popup.addText(label,
                                          name,
                                          type=var['type'],
                                          value=default,
                                          placeholder=placeholder)
                    elif var['type'] == 'hidden':
                        popup.addHiddenField(var['name'], var['value'])
                    elif var['type'] == 'message':
                        popup.addMessage(var['message'], var['messagetype'])

        for name, value in data.items():
            popup.addHiddenField(name, value)

        popup.write_html(page)

    if len(actionoptions) >= 1:
        actionsid = None
        if gridbinding:
            actionsid = "actions_%s" % gridbinding[0]
            jscontent = """
    $(document).on('init.dt', function(e, settings) {
        var actionid = '#actions_' + settings.sTableId;
        var action = $(actionid);
        if (action) {
            action.css('margin', '10px');
            var container = '#' + settings.sTableId + '_length';
            $(container).append(action);
            var tableid = '#' + settings.sTableId;
            var table = $(tableid);
            if (table.dataTable().fnSettings().oInit.select) {
                var link = $('<a href="#">Select All</a>');
                var selected = false;
                link.click(function (e) {
                    e.preventDefault();
                    var rows = table.DataTable().rows();
                    if (!selected) {
                        rows.select();
                        $(this).text('Clear Selection');
                    } else {
                        rows.deselect();
                        $(this).text('Select All');
                    }
                    selected = !selected;
                });
                $(container).append(link);
            }
        }
    });
"""
            page.addDocumentReadyJSfunction(jscontent)
        page.addBootstrapCombo(title, actionoptions, actionsid)
    params.result = page

    return params
示例#14
0
def main(j, args, params, tags, tasklet):
    page = args.page
    from JumpScale.portal.docgenerator.popup import Popup
    import yaml

    def _showexample():
        page.addMessage("""Actions must be in yaml form.
eg:
- display: Start
  action: /restmachine/cloudbroker/machine/start
  input:
  - reason
  - spacename
  - name: accesstype
    type: dropdown
    label: ACL
    values:
     - label: Admin
       value: ARCXDU
     - label: Write
       value: RCX
     - label: Read
       value: R

  data:
   machineId: $$id
   accountName: $$accountname

- display: Stop
  action: /restmachine/cloudbroker/machine/stop?machineId=$$id&reason=ops&accountName=$$accountname&spaceName=$$spacename
}}
""")
        params.result = page
        return params

    macrostr = args.macrostr.strip()
    title = args.getTag('title', 'Action')
    gridbinding = args.getTag('gridbinding', '').split()
    content = "\n".join(macrostr.split("\n")[1:-1])

    if not content:
        return _showexample()

    actionoptions = []
    actions = yaml.load(content)
    if actions == content:
        return _showexample()

    if not isinstance(actions, list):
      actions = [actions]

    for actiondata in actions:
        actionurl = actiondata['action']
        display = actiondata['display']
        inputs = actiondata.get('input', '')
        navigateback = actiondata.get('navigateback', False)
        reload = actiondata.get('reload', True)
        clearForm = actiondata.get('clearform', True)
        hide = actiondata.get('hide', False)
        data = actiondata.get('data', {})
        showresponse = actiondata.get('showresponse', False)
        hideon = actiondata.get('hideon', [])
        if hideon:
            hideon_input = actiondata.get('hideonInput', '')
            if hideon_input in hideon:
                continue

        action = "$('%s').modal('show');"

        if actionurl.startswith("#"):
            actionoptions.append((display, action % actionurl))
            continue
        else:
            actionid = "action-%s" % display.replace(' ', '')
            if not hide:
                actionoptions.append((display, action % ('#' + actionid)))

        popup = Popup(id=actionid, header="Confirm Action %s" % display, submit_url=actionurl,
                      navigateback=navigateback, reload_on_success=reload,
                      showresponse=showresponse, clearForm=clearForm, gridbinding=gridbinding)
        if inputs:
            for var in inputs:
                if isinstance(var, basestring):
                    popup.addText(var, var)
                else:
                    if var['type'] in ('dropdown', 'radio'):
                        label = var['label']
                        name = var['name']
                        options = list()
                        for value in var['values']:
                            options.append((value['label'], value['value']))
                        if var['type'] == 'dropdown':
                            popup.addDropdown(label, name, options)
                        elif var['type'] == 'checkboxes':
                            popup.addCheckboxes(label, name, options)
                        elif var['type'] == 'radio':
                            popup.addRadio(label, name, options)
                    elif var['type'] in ('text', 'password', 'number', 'float'):
                        label = var['label']
                        name = var['name']
                        default = var.get('default', '')
                        required = var.get('required', False)
                        placeholder = var.get('placeholder', '')
                        if var['type'] == 'float':
                            popup.addText(label, name, required, type='number', value=default, placeholder=placeholder, step="0.1")
                        else:
                            popup.addText(label, name, required, type=var['type'], value=default, placeholder=placeholder)
                    elif var['type'] == 'hidden':
                        popup.addHiddenField(var['name'], var['value'])
                    elif var['type'] == 'message':
                        popup.addMessage(var['message'], var['messagetype'])

        for name, value in data.items():
            popup.addHiddenField(name, value)

        popup.write_html(page)

    if len(actionoptions) >= 1:
        actionsid = None
        if gridbinding:
            actionsid = "actions_%s" % gridbinding[0]
            jscontent = """
    $(document).on('init.dt', function(e, settings) {
        var actionid = '#actions_' + settings.sTableId;
        var action = $(actionid);
        if (action) {
            var button = action.find('button');
            action.css('margin', '10px');
            var container = '#' + settings.sTableId + '_length';
            $(container).append(action);
            var tableid = '#' + settings.sTableId;
            var table = $(tableid);
            if (table.dataTable().fnSettings().oInit.select) {
                button.prop('disabled', true);
                var linka = $('<a href="#">Select All</a>');
                var linkn = $('<a href="#">Clear Selection</a>');
                linkn.hide();
                linka.click(function (e) {
                    e.preventDefault();
                    var rows = table.DataTable().rows();
                    rows.select();
                });
                linkn.click(function (e) {
                    e.preventDefault();
                    var rows = table.DataTable().rows();
                    rows.deselect();
                });
                $(container).append(linka);
                $(container).append('&nbsp;');
                $(container).append(linkn);
                var onselect = function (e, dt, type, indexes) {
                    var count = dt.rows({'selected': true}).count()
                    var totalcount = dt.rows().count()
                    if (count == 0){
                        linkn.hide();
                        button.prop('disabled', true);
                    } else {
                        linkn.show();
                        button.prop('disabled', false);
                    }
                    if (totalcount == count) {
                        linka.hide();
                    } else {
                        linka.show();
                    }
                };
                table.DataTable().on('select', onselect);
                table.DataTable().on('deselect', onselect);
            }
        }
    });
"""
            page.addDocumentReadyJSfunction(jscontent)
        page.addBootstrapCombo(title, actionoptions, actionsid)
    params.result = page

    return params