def get_html(self): card_content = TAG[""]( P("Love StopStalk and interested in things to buy online?"), P("Click to know more!")) card_html = BaseCard.get_html( self, **dict(card_title=self.card_title, card_content=card_content, cta_links=self.get_cta_html(), card_color_class="purple lighten-5", card_text_color_class="black-text")) return card_html
def message_widget(field, value, **attr): """ Widget to edit and preview a notification message body @param field: the Field @param value: the current field value @param attr: DOM attributes for the widget """ widget_id = attr.get("_id") if not widget_id: widget_id = "%s_%s" % (field._tablename, field.name) edit = TEXTAREA( _name=attr.get("_name", field.name), _id=widget_id, _class="message %s" % (field.type), _placeholder=attr.get("_placeholder"), _rows=6, _style="display:none", value=value, requires=field.requires, ) preview = P("", _class="preview") return DIV(preview, edit, _class="preview-widget")
def get_html(self): streak_value = self.get_data() if self.kind == "day": card_content = P("You're at a ", B("%d day streak" % streak_value), ". Keep solving a new problem everyday!") elif self.kind == "accepted": card_content = P("You're at a ", B("%d accepted problem streak" % streak_value), ".", BR(), "Let the greens rain!") else: return "FAILURE" card_html = BaseCard.get_html( self, **dict(card_title=self.card_title, card_content=card_content, cta_links=self.get_cta_html(), card_color_class="white", card_text_color_class="black-text")) return card_html
def get_html(self): card_content = P( "I am looking for a job and I want StopStalk to reach out to me for matching opportunities. Let me update my preferences." ) card_html = BaseCard.get_html( self, **dict(card_title=self.card_title, card_content=card_content, cta_links=self.get_cta_html(), card_color_class="white", card_text_color_class="black-text")) return card_html
def get_html(self): streak_value = self.get_data() card_content = P( "Let's find you some problem that you can start solving.") card_html = BaseCard.get_html( self, **dict(card_title=self.card_title, card_content=card_content, cta_links=self.get_cta_html(), card_color_class="white", card_text_color_class="black-text")) return card_html
def _render_tag_div(self, label, controls, help): row = DIV(_class='col s12') label.tag = 'SPAN' row.append(DIV( DIV(label, controls[0], _class='btn'), DIV(INPUT(_class='file-path validate', _type='text'), _class='file-path-wrapper'), _class='file-field input-field' )) row.append(A(controls[3], _href=controls[1][1]['_href'])) row.append(DIV( P(LABEL(controls[1][3], SPAN(controls[1][4][0]))) )) return row
def get_html(self): card_content = P( "AtCoder has come up in our surveys multiple times and here we are. We now support AtCoder profiles :)" ) card_html = BaseCard.get_html( self, **dict(card_title=self.card_title, card_content=card_content, cta_links=self.get_cta_html(), card_color_class="white", card_text_color_class="black-text")) return card_html
def chapter(poem, db, uhdb): """ Return a bootstrap row for a poem row. """ if not poem: raise Exception('No such poem') qry = ((db.verse.book == 1) & (db.verse.chapter == poem.chapter)) verse = db(qry).select().first() title = H3(poem.chapter.title) subtitle = H4('Chapter %i' % poem.chapter.number) published = H5(poem.published.strftime(date_format)) stanzas = verse.en.split('\r\n\r\n') content = [] for stanza in stanzas: content.append(P(XML(stanza.replace('\r\n', '<br />')))) link = P(A(I('Go to the study version'), _href=URL('studies', 'chapter', args=[poem.chapter.number]), _style='color:inherit;', _title='Study version'), _style='font-size:0.9em;padding-top:1em') content.append(P(link)) column = DIV(title, subtitle, published, *content, _class=poem_class) return DIV(column, _class='row', _style='font-size:1.12em;white-space:nowrap;')
def get_html(self): count = self.get_data() card_content = P( "You have ", B(current.T("%s %%{account}") % count), " linked with StopStalk. Update your profile with more handles to track your competitive programming progress." ) card_html = BaseCard.get_html( self, **dict(card_title=self.card_title, card_content=card_content, cta_links=self.get_cta_html(), card_color_class="white", card_text_color_class="black-text")) return card_html
def widget(cls, field, value, **attributes): """ Turn me on. lol! (or off) """ _id = str(field).replace('.', '_') attributes['_type'] = 'checkbox' return DIV(P(LABEL( 'Off', INPUT(_id=_id, _name=field.name, requires=field.requires, value=value, **attributes), SPAN(_class='lever'), 'On', _for=_id, ), _style='padding:20px'), _class='switch')
def get_html(self): data = self.get_data() self.ctas = [ dict(btn_text="Show me", btn_url=URL("default", "search", vars={"institute": data["institute"]}), btn_class="add-more-friends-card-institute-search") ] card_content = P( "You have ", B(current.T("%s %%{friend}") % data["friend_count"]), " on StopStalk. For a better competitive programming learning experience, we recommend you to add more friends." ) card_html = BaseCard.get_html( self, **dict(card_title=self.card_title, card_content=card_content, cta_links=self.get_cta_html(), card_color_class="white", card_text_color_class="black-text")) return card_html
def apparatus(): vbs = False if vbs: print 'starting apparatus controller' filename = request.args[0] info, p = _get_bookinfo(filename) #if no unit has been requested, present the default message if request.vars['called'] == 'no': readings = P('Click on any blue text to display textual variants ' 'for those words. If no links are available that may ' 'mean no variants are attested or it may mean that ' 'this document does not yet have a complete textual ' 'apparatus. See the document introduction for details.', _class='apparatus-message') current_version = '' #if a unit has been requested, assemble that unit's readings else: #get current version current_version = request.vars['version'].replace('_', ' ') unit = request.vars['unit'] readings = p.get_readings(current_version, unit) return {'rlist': readings, 'version': current_version}
def __call__(self): T = current.T db = current.db s3db = current.s3db s3 = current.response.s3 session_s3 = current.session.s3 output = {} # Recent Updates etable = s3db.event_event stable = s3db.event_sitrep query = (stable.deleted == False) fields = [ etable.name, stable.id, stable.date, stable.name, stable.summary, ] left = [etable.on(etable.id == stable.event_id)] language = session_s3.language if language != current.deployment_settings.get_L10n_default_language(): ntable = s3db.event_event_name left.append(ntable.on((ntable.event_id == etable.id) & \ (ntable.language == language))) fields.append(ntable.name_l10n) use_local_event_name = True else: use_local_event_name = False sitreps = db(query).select(left=left, limitby=(0, 3), orderby=~stable.date, *fields) len_sitreps = len(sitreps) if len_sitreps == 0: from s3 import S3CRUD recent_updates = DIV(S3CRUD.crud_string("event_sitrep", "msg_list_empty"), _class="empty") else: recent_updates = DIV() rappend = recent_updates.append count = 0 for s in sitreps: count += 1 if use_local_event_name: event_name = s["event_event_name.name_l10n"] or s[ "event_event.name"] else: event_name = s["event_event.name"] if not event_name: event_name = s["event_sitrep.name"] rappend( H3( A( event_name, _href=URL( c="event", f="sitrep", args=[s["event_sitrep.id"]], ), ))) rappend(P(XML(s["event_sitrep.summary"]))) if count != len_sitreps: rappend(HR()) output["recent_updates"] = recent_updates map_btn = A( T("MAP OF CURRENT NEEDS"), #_href = URL(c="default", # f="index", # args="dashboard", # ), _href=URL( c="req", f="need_line", args="map", ), _class="small primary button", ) create_btn = A( T("CREATE A NEED"), _href=URL( c="req", f="need", args="create", ), _class="small primary button", ) output["needs_btn"] = DIV( SPAN(map_btn), SPAN(create_btn), _class="button-group radius", ) output["about_btn"] = A( "%s >" % T("Read More"), _href=URL( c="default", f="about", ), ) # Resources section if current.deployment_settings.has_module("cms"): system_roles = current.auth.get_system_roles() ADMIN = system_roles.ADMIN in session_s3.roles table = s3db.cms_post ltable = s3db.cms_post_module module = "default" resource = "index" query = (ltable.module == module) & \ ((ltable.resource == None) | \ (ltable.resource == resource)) & \ (ltable.post_id == table.id) & \ (table.deleted != True) item = current.db(query).select(table.body, table.id, limitby=(0, 1)).first() if item: if ADMIN: item = DIV( XML(item.body), BR(), A(T("Edit"), _href=URL(c="cms", f="post", args=[item.id, "update"]), _class="action-btn")) else: item = DIV(XML(item.body)) elif ADMIN: if s3.crud.formstyle == "bootstrap": _class = "btn" else: _class = "action-btn" item = A(T("Edit"), _href=URL(c="cms", f="post", args="create", vars={ "module": module, "resource": resource }), _class="%s cms-edit" % _class) else: item = "" else: item = "" output["item"] = item # Inject D3 scripts from s3 import S3Report S3Report.inject_d3() # Inject charts-script appname = current.request.application scripts = s3.scripts if s3.debug: script = "/%s/static/scripts/S3/s3.ui.charts.js" % appname if script not in scripts: scripts.append(script) else: script = "/%s/static/scripts/S3/s3.ui.charts.min.js" % appname if script not in scripts: scripts.append(script) # Instantiate charts scriptopts = { # Standard SHARE theme color set: "colors": [ '#0C9CD0', # blue '#E03158', # red '#FBA629', # amber '#8ABC3F', # green '#AFB8BF', # grey ], } script = '''$('.homepage-chart').uiChart(%s)''' % json.dumps( scriptopts) s3.jquery_ready.append(script) # Add last update time of chart data last_update = HomepageStatistics.last_update() if last_update: output["last_stats_update"] = T("Updated on %(date)s") % { "date": last_update } else: output["last_stats_update"] = None self._view(THEME, "index.html") return output
def _render_tag_input_boolean(self, label, controls, help): row = DIV(_class='input-field col s12') row.append(P(LABEL(controls, SPAN(label[0])))) return row
def __call__(self): T = current.T db = current.db s3db = current.s3db output = {} # Recent Updates etable = s3db.event_event stable = s3db.event_sitrep query = (stable.deleted == False) fields = [ etable.name, stable.date, stable.name, stable.summary, ] left = [etable.on(etable.id == stable.event_id)] language = current.session.s3.language if language != current.deployment_settings.get_L10n_default_language(): ntable = s3db.event_event_name left.append(ntable.on((ntable.event_id == etable.id) & \ (ntable.language == language))) fields.append(ntable.name_l10n) use_local_event_name = True else: use_local_event_name = False sitreps = db(query).select(left=left, limitby=(0, 3), orderby=~stable.date, *fields) len_sitreps = len(sitreps) if len_sitreps == 0: from s3 import S3CRUD recent_updates = DIV(S3CRUD.crud_string("event_sitrep", "msg_list_empty"), _class="empty") else: recent_updates = DIV() rappend = recent_updates.append count = 0 for s in sitreps: count += 1 if use_local_event_name: event_name = s["event_event_name.name_l10n"] or s[ "event_event.name"] else: event_name = s["event_event.name"] if not event_name: event_name = s["event_sitrep.name"] rappend(H3(event_name)) rappend(P(XML(s["event_sitrep.summary"]))) if count != len_sitreps: rappend(HR()) output["recent_updates"] = recent_updates map_btn = A( T("MAP OF CURRENT NEEDS"), #_href = URL(c="default", # f="index", # args="dashboard", # ), _href=URL( c="req", f="need_line", args="map", ), _class="small primary button", ) create_btn = A( T("CREATE A NEED"), _href=URL( c="req", f="need", args="create", ), _class="small primary button", ) output["needs_btn"] = DIV( SPAN(map_btn), SPAN(create_btn), _class="button-group radius", ) output["about_btn"] = A( "%s >" % T("Read More"), _href=URL( c="default", f="about", ), ) self._view(THEME, "index.html") # Inject D3 scripts from s3 import S3Report S3Report.inject_d3() # Inject charts-script appname = current.request.application s3 = current.response.s3 scripts = s3.scripts if s3.debug: script = "/%s/static/scripts/S3/s3.ui.charts.js" % appname if script not in scripts: scripts.append(script) else: script = "/%s/static/scripts/S3/s3.ui.charts.min.js" % appname if script not in scripts: scripts.append(script) # Instantiate charts scriptopts = { # Standard SHARE theme color set: "colors": [ '#0C9CD0', # blue '#E03158', # red '#FBA629', # amber '#8ABC3F', # green '#AFB8BF', # grey ], } script = '''$('.homepage-chart').uiChart(%s)''' % json.dumps( scriptopts) s3.jquery_ready.append(script) # Add last update time of chart data last_update = HomepageStatistics.last_update() if last_update: output["last_stats_update"] = T("Updated on %(date)s") % { "date": last_update } else: output["last_stats_update"] = None return output
def __call__(self): output = {} T = current.T request = current.request response = current.response s3 = response.s3 # Check logged in and permissions auth = current.auth settings = current.deployment_settings roles = current.session.s3.roles system_roles = auth.get_system_roles() AUTHENTICATED = system_roles.AUTHENTICATED # Login/Registration forms self_registration = current.deployment_settings.get_security_registration_visible( ) registered = False login_form = None login_div = None register_form = None register_div = None if AUTHENTICATED not in roles: login_buttons = DIV(A(T("Login"), _id="show-login", _class="tiny secondary button"), _id="login-buttons") script = ''' $('#show-mailform').click(function(e){ e.preventDefault() $('#intro').slideDown(400, function() { $('#login_box').hide() }); }) $('#show-login').click(function(e){ e.preventDefault() $('#login_form').show() $('#register_form').hide() $('#login_box').show() $('#intro').slideUp() })''' s3.jquery_ready.append(script) # This user isn't yet logged-in if "registered" in request.cookies: # This browser has logged-in before registered = True if self_registration is True: # Provide a Registration box on front page login_buttons.append( A(T("Register"), _id="show-register", _class="tiny secondary button", _style="margin-left:5px")) script = ''' $('#show-register').click(function(e){ e.preventDefault() $('#login_form').hide() $('#register_form').show() $('#login_box').show() $('#intro').slideUp() })''' s3.jquery_ready.append(script) register_form = auth.register() register_div = DIV( H3(T("Register")), P( XML( T("If you would like to help, then please <b>sign up now</b>" )))) register_script = ''' $('#register-btn').click(function(e){ e.preventDefault() $('#register_form').show() $('#login_form').hide() }) $('#login-btn').click(function(e){ e.preventDefault() $('#register_form').hide() $('#login_form').show() })''' s3.jquery_ready.append(register_script) # Provide a login box on front page auth.messages.submit_button = T("Login") login_form = auth.login(inline=True) login_div = DIV( H3(T("Login")), #P(XML(T("Registered users can <b>login</b> to access the system"))), ) else: login_buttons = "" output["login_buttons"] = login_buttons output["self_registration"] = self_registration output["registered"] = registered output["login_div"] = login_div output["login_form"] = login_form output["register_div"] = register_div output["register_form"] = register_form s3.stylesheets.append("../themes/%s/homepage.css" % THEME) self._view(settings.get_theme_layouts(), "index.html") return output
def widget( cls, r, label="Anonymize", ajaxURL=None, _class="action-lnk", ): """ Render an action item (link or button) to anonymize the target record of an S3Request, which can be embedded in the record view @param r: the S3Request @param label: The label for the action item @param ajaxURL: The URL for the AJAX request @param _class: HTML class for the action item @returns: the action item (a HTML helper instance), or an empty string if no anonymize-rules are configured for the target table, no target record was specified or the user is not permitted to anonymize it """ T = current.T default = "" # Determine target table if r.component: resource = r.component if resource.link and not r.actuate_link(): resource = resource.link else: resource = r.resource table = resource.table # Determine target record record_id = S3Anonymize._record_id(r) if not record_id: return default # Check if target is configured for anonymize rules = resource.get_config("anonymize") if not rules: return default if not isinstance(rules, (tuple, list)): # Single rule rules["name"] = "default" rules = [rules] # Check permissions to anonymize if not S3Anonymize.permitted(table, record_id): return default # Determine widget ID widget_id = "%s-%s-anonymize" % (table, record_id) # Inject script if ajaxURL is None: ajaxURL = r.url( method="anonymize", representation="json", ) script_options = { "ajaxURL": ajaxURL, } next_url = resource.get_config("anonymize_next") if next_url: script_options["nextURL"] = next_url cls.inject_script(widget_id, script_options) # Action button translated_label = T(label) action_button = A(translated_label, _class="anonymize-btn") if _class: action_button.add_class(_class) # Dialog and Form INFO = T("The following information will be deleted from the record") CONFIRM = T("Are you sure you want to delete the selected details?") SUCCESS = T("Action successful - please wait...") form = FORM( P("%s:" % INFO), cls.selector(rules), P(CONFIRM), DIV( INPUT( value="anonymize_confirm", _name="anonymize_confirm", _type="checkbox", ), LABEL(T("Yes, delete the selected details")), _class="anonymize-confirm", ), cls.buttons(), _class="anonymize-form", # Store action key in form hidden={"action-key": cls.action_key(widget_id)}, ) dialog = DIV( form, DIV( P(SUCCESS), _class="hide anonymize-success", ), _class="anonymize-dialog hide", _title=translated_label, ) # Assemble widget widget = DIV( action_button, dialog, _class="s3-anonymize", _id=widget_id, ) return widget
def cms_post_list_layout(list_id, item_id, resource, rfields, record): """ dataList item renderer for Posts on the Bulletin Board. @param list_id: the HTML ID of the list @param item_id: the HTML ID of the item @param resource: the S3Resource to render @param rfields: the S3ResourceFields to render @param record: the record as dict """ record_id = record["cms_post.id"] #item_class = "thumbnail" T = current.T db = current.db s3db = current.s3db settings = current.deployment_settings permit = current.auth.s3_has_permission raw = record._row date = record["cms_post.date"] title = record["cms_post.title"] body = record["cms_post.body"] #series_id = raw["cms_post.series_id"] # Allow records to be truncated # (not yet working for HTML) body = DIV( body, _class="s3-truncate", ) #if series_id: # series = record["cms_post.series_id"] # translate = settings.get_L10n_translate_cms_series() # if translate: # series_title = T(series) # else: # series_title = series #else: # series_title = series = "" #status = record["cms_post.status_id"] author_id = raw["cms_post.created_by"] person = record["cms_post.created_by"] # @ToDo: Bulk lookup ltable = s3db.pr_person_user ptable = db.pr_person query = (ltable.user_id == author_id) & \ (ltable.pe_id == ptable.pe_id) row = db(query).select(ptable.id, limitby=(0, 1)).first() if row: person_id = row.id else: person_id = None if person: if person_id: # @ToDo: deployment_setting for controller to use? person_url = URL(c="hrm", f="person", args=[person_id]) else: person_url = "#" person = A( person, _href=person_url, ) table = db.cms_post # Toolbar if permit("update", table, record_id=record_id): edit_btn = A( ICON("edit"), SPAN( "edit", _class="show-for-sr", ), _href=URL(c="cms", f="post", args=[record_id, "update.popup"], vars={ "refresh": list_id, "record": record_id }), _class="s3_modal", #_title=T("Edit %(type)s") % dict(type=series_title), _title=T("Edit"), ) else: edit_btn = "" if permit("delete", table, record_id=record_id): delete_btn = A( ICON("delete"), SPAN( "delete", _class="show-for-sr", ), _class="dl-item-delete", _title=T("Delete"), ) else: delete_btn = "" # Bookmarks auth = current.auth user = auth.user if user: #and settings.get_cms_bookmarks(): # @ToDo: Bulk lookup (via list_fields?) ltable = s3db.cms_post_user query = (ltable.post_id == record_id) & \ (ltable.user_id == user.id) exists = db(query).select(ltable.id, limitby=(0, 1)).first() if exists: bookmark = A( ICON("bookmark"), SPAN( "remove bookmark", _class="show-for-sr", ), _class="bookmark", _title=T("Remove Bookmark"), ) else: bookmark = A( ICON("bookmark-empty"), SPAN( "bookmark", _class="show-for-sr", ), _class="bookmark", _title=T("Add Bookmark"), ) bookmark["_data-c"] = "cms" bookmark["_data-f"] = "post" bookmark["_data-i"] = record_id else: bookmark = "" # Dropdown of available documents documents = raw["doc_document.file"] if documents: if not isinstance(documents, list): documents = (documents, ) doc_list = UL( _class="dropdown-menu", _role="menu", ) retrieve = db.doc_document.file.retrieve for doc in documents: try: doc_name = retrieve(doc)[0] except (IOError, TypeError): doc_name = current.messages["NONE"] doc_url = URL(c="default", f="download", args=[doc]) doc_item = LI( A( ICON("file"), " ", doc_name, _href=doc_url, ), _role="menuitem", ) doc_list.append(doc_item) docs = DIV( A(ICON("paper-clip"), SPAN(_class="caret"), _class="btn dropdown-toggle", _href="#", **{"_data-toggle": "dropdown"}), doc_list, _class="btn-group attachments dropdown pull-right", ) else: docs = "" #divider = LI("|") #divider["_aria-hidden"] = "true" toolbar = UL( #LI(share_btn, # _class="item", # ), #LI(A(ICON("flag"), # @ToDo: Use flag-alt if not flagged & flag if already flagged (like for bookmarks) # SPAN("flag this", # _class = "show-for-sr", # ), # _href="#", # _title=T("Flag"), # ), # _class="item", # ), LI( bookmark, _class="item", ), #LI(A(I(_class="fa fa-users", # ), # SPAN("make public", # _class = "show-for-sr", # ), # _href="#", # _title=T("Make Public"), # ), # _class="item", # ), LI( edit_btn, _class="item", ), LI( delete_btn, _class="item", ), _class="controls", ) # Tags #if settings.get_cms_show_tags(): tag_list = UL(_class="left inline-list s3-tags", ) tag_list["_data-post_id"] = record_id tags = raw["cms_tag.name"] if tags: if not isinstance(tags, list): tags = [tags] for tag in tags: tag_list.append(LI(A( tag, _href="#", ), )) # Comments comment_list = UL(_class="card-post-comments") cappend = comment_list.append #if settings.get_cms_comments(): # Add existing comments (oldest 1st) # - should sort by default by ID which is equivalent to oldest first, # however they seem to come in in a random order (even if orderby set on the component) so need to be sorted manually here comments = raw["cms_comment.json_dump"] ncomments = 0 if comments: if not isinstance(comments, list): comments = [comments] comments = [json.loads(comment) for comment in comments] comments.sort(key=lambda c: c["created_on"]) for comment in comments: author = s3_auth_user_represent(comment["created_by"]) cdate = dateutil.parser.parse(comment["created_on"]) ctime = cdate.time().strftime("%H:%M") cdate = cdate.date().strftime("%b %d, %Y") comment = LI(TAG["ASIDE"](P(T("Updated %(date)s @ %(time)s by %(author)s") % \ dict(date = cdate, time = ctime, author = author, ), _class="meta", ), DIV(comment["body"], _class="desc", ), # @ToDo: Show this if more than x chars? #TAG["FOOTER"](P(A(T("More Info"), # _class="more", # ) # ), # _class="footer", # ), _class="card-post-comment", )) cappend(comment) ncomments += 1 if ncomments == 1: num_comments = "1 Comment" else: num_comments = T("%(num)s Comments") % dict(num=ncomments) if user: add_comment = A( T("Add Comment"), _class="add-comment", ) add_comment["_data-l"] = list_id add_comment["_data-i"] = record_id add_comment = P(add_comment) comment_input = LI( TAG["ASIDE"]( TEXTAREA( _class="desc", _placeholder=T("comment here"), ), TAG["FOOTER"](P(A( "Submit Comment", _class="submit", ), ), ), _class="card-post-comment", ), _class="comment-form hide", ) cappend(comment_input) else: add_comment = "" item = TAG["ASIDE"]( TAG["HEADER"]( UL( # post priority icon LI(_class="item icon", ), # post type title #LI(series_title, # _class="item primary", # ), # post status #LI(status, # _class="item secondary border status", # ), # post visibility # @ToDo: Read the visibility #LI(T("Public"), # _class="item secondary border visibility", # ), _class="status-bar-left"), toolbar, _class="status-bar", ), DIV( DIV( SPAN( "Updated ", # @ToDo: i18n TAG["TIME"](date), " by ", person, _class="meta-update", ), SPAN( num_comments, _class="meta-comments", ), _class="meta", ), H4( title, _class="title", ), DIV( body, _class="desc", ), _class="body", ), docs, TAG["FOOTER"]( DIV( tag_list, _class= "tags clearfix", # @ToDo: remove clearfix and style via CSS ), comment_list, add_comment, _class="footer", ), _class="card-post", _id=item_id, ) return item
def widget( cls, r, record_ids=None, _class="action-lnk", ): """ Render an action item (link or button) to anonymize the provided records @param r: the S3Request @param record_ids: The list of record_ids to act on @param _class: HTML class for the action item @returns: the action item (a HTML helper instance), or an empty string if no anonymize-rules are configured for the target table, no target record was specified or the user is not permitted to anonymize it """ T = current.T default = "" # Determine target table if r.component: resource = r.component if resource.link and not r.actuate_link(): resource = resource.link else: resource = r.resource table = resource.table # Determine target record if not record_ids: return default # Check if target is configured for anonymize rules = resource.get_config("anonymize") if not rules: return default if not isinstance(rules, (tuple, list)): # Single rule rules["name"] = "default" rules = [rules] # Determine widget ID widget_id = "%s-anonymize" % table # Dialog and Form INFO = T( "The following information will be deleted from all the selected records" ) CONFIRM = T("Are you sure you want to delete the selected details?") #SUCCESS = T("Action successful - please wait...") form = FORM( P("%s:" % INFO), cls.selector(rules), P(CONFIRM), DIV( INPUT( value="anonymize_confirm", _name="anonymize_confirm", _type="checkbox", ), LABEL(T("Yes, delete the selected details")), _class="anonymize-confirm", ), DIV( INPUT( _class="small alert button anonymize-submit", _disabled="disabled", _type="submit", _value=T("Anonymize"), ), _class="anonymize-buttons", ), _class="anonymize-form", # Store action key in form hidden={"action-key": cls.action_key(widget_id)}, ) script = '''var submitButton=$('.anonymize-submit'); $('input[name="anonymize_confirm"]').off('.anonymize').on('click.anonymize',function(){if ($(this).prop('checked')){submitButton.prop('disabled',false);}else{submitButton.prop('disabled',true);}});''' current.response.s3.jquery_ready.append(script) return form